manoar / laravel-steadfast
A Laravel package for interacting with the Steadfast Courier API.
dev-main
2025-04-07 01:24 UTC
Requires
- php: ^8.1
- illuminate/http: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
- laravel/framework: ^11.0|^12.0
This package is auto-updated.
Last update: 2025-05-07 01:43:42 UTC
README
A Laravel package that provides seamless integration with Steadfast Courier API services.
Installation
Install the package via Composer:
composer require manoar/laravel-steadfast
Configuration
- Publish the configuration file:
php artisan vendor:publish --provider="Manoar\Steadfast\SteadfastServiceProvider"
- Configure your credentials in your
.env
file:
STEADFAST_API_KEY=your_api_key STEADFAST_API_SECRET=your_api_secret STEADFAST_API_URL=https://api.steadfast.com
Usage
Facade Usage
<?php use Manoar\Steadfast\Facades\Steadfast; use Manoar\Steadfast\Exceptions\SteadfastApiException; try { // Create an order $response = Steadfast::createOrder([ 'invoice' => 'INV-123', 'recipient_name' => 'John Doe', 'recipient_phone' => '01700000000', 'recipient_address' => '123 Main St, Dhaka', 'cod_amount' => 1500, 'note' => 'Please handle with care' ]); $consignmentId = $response['consignment']['consignment_id']; $trackingCode = $response['consignment']['tracking_code']; // Get order status $status = Steadfast::getStatusByConsignmentId($consignmentId); // Check balance $balance = Steadfast::getBalance(); } catch (SteadfastApiException $e) { // Handle errors $message = $e->getMessage(); $responseData = $e->getApiErrorData(); $statusCode = $e->getCode(); }
Dependency Injection
<?php use Manoar\Steadfast\SteadfastClient; class OrderController extends Controller { protected SteadfastClient $steadfast; public function __construct(SteadfastClient $steadfast) { $this->steadfast = $steadfast; } public function placeOrder(Request $request) { try { $response = $this->steadfast->createOrder([ 'invoice' => $request->invoice_id, 'recipient_name' => $request->name, 'recipient_phone' => $request->phone, 'recipient_address' => $request->address, 'cod_amount' => $request->amount, 'note' => $request->note ]); return response()->json(['success' => true, 'data' => $response]); } catch (SteadfastApiException $e) { return response()->json(['success' => false, 'message' => $e->getMessage()], 500); } } }
Available Methods
Method | Description |
---|---|
createOrder(array $data) |
Create a new order/consignment |
placeBulkOrders(array $orders) |
Place multiple orders in bulk (max 500) |
getStatusByConsignmentId(string|int $consignmentId) |
Get status by Consignment ID |
getStatusByInvoice(string $invoiceId) |
Get status by Invoice ID |
getStatusByTrackingCode(string $trackingCode) |
Get status by Tracking Code |
getBalance() |
Get merchant account balance |
Error Handling
The package throws SteadfastApiException
on API failures, providing:
- Error message via
getMessage()
- HTTP status code via
getCode()
- API error data via
getApiErrorData()
- Full HTTP response via
getResponse()
Local Development
To develop this package locally:
-
Create a directory structure:
packages/manoar/laravel-steadfast/
-
Add to your Laravel project's
composer.json
:"repositories": [ { "type": "path", "url": "packages/manoar/laravel-steadfast" } ], "require": { "manoar/laravel-steadfast": "@dev" }
-
Run
composer update manoar/laravel-steadfast
License
The MIT License (MIT). Please see License File for more information.
Contributing
Contributions are welcome! Please follow the coding standards and include tests for new features or bug fixes.