softrang / parcel-helper
A small helper to place orders using API keys from env/config.
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/softrang/parcel-helper
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.0
README
A simple, developer-friendly Parcel Helper for Laravel 12+ to easily create and manage consignments with SteadFast and other supported services. created by Softrang.
Features
- Simple API for creating parcels/orders.
- Supports SteadFast and other courier services.
- Automatically stores consignment details in your database.
- Clean, professional, and Laravel-native.
Requirements
- PHP 8.1+
- Laravel 12+
- Composer
Installation
Install via Composer
composer require softrang/parcel-helper
Publish the config:
php artisan vendor:publish --tag= parcel-helpar
Environment Configuration
Add your API keys to your .env file:
PACKZY_API_KEY=your_api_key PACKZY_SECRET_KEY=your_secret_key
Usage
Sample Controller
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Softrang\ParcelHelper\Facades\ParcelHelper; use App\Models\Consignment; public function sendSteadFast(Request $request) { // Validate request $validated = $request->validate([ 'invoice' => 'required|string|max:50', 'name' => 'required|string|max:255', 'phone' => 'required|string|max:20', 'address' => 'required|string|max:500', 'amount' => 'required|numeric|min:0', ]); try { // Create order via ParcelHelper $response = ParcelHelper::steadfastCreateOrder([ 'invoice' => $validated['invoice'], 'recipient_name' => $validated['name'], 'recipient_phone' => $validated['phone'], 'recipient_address' => $validated['address'], 'cod_amount' => $validated['amount'], ]); if ($response['status'] === 200 && isset($response['consignment'])) { $c = $response['consignment']; // Save consignment in DB $consignment = Consignment::create([ 'consignment_id' => $c['consignment_id'], 'invoice' => $c['invoice'], 'tracking_code' => $c['tracking_code'], 'recipient_name' => $c['recipient_name'], 'recipient_phone' => $c['recipient_phone'], 'recipient_address' => $c['recipient_address'], 'cod_amount' => $c['cod_amount'], 'status' => $c['status'], ]); return response()->json([ 'success' => true, 'message' => 'Consignment created and saved successfully.', 'data' => $consignment, ], 201); } return response()->json([ 'success' => false, 'message' => 'Failed to create consignment from API.', 'api_response' => $response, ], 400); } catch (\Exception $e) { return response()->json([ 'success' => false, 'message' => 'An error occurred while processing your request.', 'error' => $e->getMessage(), ], 500); } }
Database Setup
Ensure you have a consignments table:
Schema::create('consignments', function (Blueprint $table) { $table->id(); $table->string('consignment_id')->unique(); $table->string('invoice'); $table->string('tracking_code')->nullable(); $table->string('recipient_name'); $table->string('recipient_phone'); $table->text('recipient_address'); $table->decimal('cod_amount', 10, 2)->default(0); $table->string('status')->nullable(); $table->timestamps(); });