PHP code example of amdadulhaq / bd-courier-laravel
1. Go to this page and download the library: Download amdadulhaq/bd-courier-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amdadulhaq / bd-courier-laravel example snippets
use AmdadulHaq\BdCourier\Facades\Courier;
use AmdadulHaq\BdCourier\DataTransferObjects\ShipmentRequest;
$response = Courier::createShipment(new ShipmentRequest(
invoiceNumber: 'INV-1001',
recipientName: 'John Doe',
recipientPhone: '01700000000',
recipientAddress: 'House 1, Road 2, Gulshan',
recipientCity: 'Dhaka',
recipientZone: 'Gulshan',
codAmount: 1200.00,
itemWeight: 0.5,
itemDescription: 'T-Shirt',
));
$response->consignmentId; // the courier's own tracking/consignment ID — save this
$response->status; // AmdadulHaq\BdCourier\Enums\ShipmentStatus
$status = Courier::track($response->consignmentId);
if ($status->status->isSuccessful()) {
// mark the order delivered
}
use AmdadulHaq\BdCourier\Facades\Courier;
Route::post('/webhooks/redx', function (Request $request) {
$result = Courier::driver('redx')->handleWebhook($request->all());
if ($result->status->isSuccessful()) {
// mark the order delivered
}
return response()->noContent();
})->withoutMiddleware([\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class]);
use AmdadulHaq\BdCourier\Facades\Courier;
Courier::extend('my-courier', function ($app) {
return new MyCourierDriver(/* ... */);
});
interface CourierDriver
{
public function createShipment(ShipmentRequest $request): ShipmentResponse;
public function track(string $consignmentId): ShipmentResponse;
public function cancel(string $consignmentId): ShipmentResponse;
public function calculatePrice(ShipmentRequest $request): float;
public function handleWebhook(array $payload): ShipmentResponse;
}
use AmdadulHaq\BdCourier\CourierManager;
use AmdadulHaq\BdCourier\Facades\Courier;
$fake = CourierManager::fake();
// ... code under test that calls Courier::createShipment() ...
$fake->assertShipmentCreated('INV-1001');
$fake->assertNothingCreated();