PHP code example of centrex / laravel-courier

1. Go to this page and download the library: Download centrex/laravel-courier 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/ */

    

centrex / laravel-courier example snippets


return [
    'api_prefix' => 'api',
    'route_prefix' => '',

    'pathao' => [
        'tracking_url' => 'https://merchant.pathao.com/api/v1/user/tracking',
        'sandbox' => env('PATHAO_SANDBOX', true),
        'base_urls' => [
            'sandbox' => env('PATHAO_SANDBOX_BASE_URL', 'https://courier-api-sandbox.pathao.com/'),
            'live' => env('PATHAO_LIVE_BASE_URL', 'https://courier-api.pathao.com/'),
        ],
        'client_id' => env('PATHAO_CLIENT_ID', ''),
        'client_secret' => env('PATHAO_CLIENT_SECRET', ''),
        'username' => env('PATHAO_USERNAME', ''),
        'password' => env('PATHAO_PASSWORD', ''),
        'token_cache_ttl' => (int) env('PATHAO_TOKEN_CACHE_TTL', 7200),
        'auth' => [
            'endpoint' => 'aladdin/api/v1/issue-token',
            'method' => 'post',
            'body_type' => 'json',
            'response_token_key' => 'access_token',
            'header' => 'Authorization',
            'prefix' => 'Bearer',
        ],
    ],

    'redx' => [
        'sandbox' => env('REDX_SANDBOX', false),
        'base_urls' => [
            'sandbox' => env('REDX_SANDBOX_BASE_URL', 'https://sandbox.redx.com.bd/v1.0.0-beta'),
            'live' => env('REDX_LIVE_BASE_URL', 'https://openapi.redx.com.bd/v1.0.0-beta'),
        ],
        'api_access_token' => env('REDX_API_ACCESS_TOKEN', ''),
    ],

    'rokomari' => [
        'tracking_url' => 'https://www.rokomari.com/ordertrack',
    ],

    'steadfast' => [
        'tracking_url' => 'https://steadfast.com.bd/track/consignment',
    ],

    'sundarban' => [
        'tracking_url' => 'https://tracking.sundarbancourierltd.com/Home/getDatabyCN',
    ],
];

return [
    'api_prefix' => 'api',
    'route_prefix' => 'courier',
];

use Centrex\Courier\Courier;

$courier = app(Courier::class);

$redx = $courier->redx('RX123456789');
$steadfast = $courier->steadfast('ST123456789');
$pathao = $courier->pathao('PTH123456', '01700000000');
$rokomari = $courier->rokomari('ORDER123', '01700000000');
$sundarban = $courier->sundarban('CN123456');

use Centrex\Courier\Facades\Courier;

$tracking = Courier::redx('RX123456789');

use Centrex\Courier\Services\PathaoService;

$pathao = app(PathaoService::class);

$cities = $pathao->cities();
$zones = $pathao->zones(1);
$areas = $pathao->areas(10);
$stores = $pathao->storeInfo();
$order = $pathao->orderInfo('CONSIGNMENT_ID');

use Centrex\Courier\Services\PathaoService;

$pathao = app(PathaoService::class);

$store = $pathao->createStore([
    'name' => 'Main Store',
    'contact_name' => 'John Doe',
    'contact_number' => '01700000000',
    'address' => 'Dhaka, Bangladesh',
    'city_id' => 1,
    'zone_id' => 10,
    'area_id' => 100,
]);

use Centrex\Courier\Services\PathaoService;

$pathao = app(PathaoService::class);

$order = $pathao->createOrder([
    'store_id' => 1,
    'recipient_name' => 'Customer Name',
    'recipient_phone' => '01700000000',
    'recipient_address' => 'Customer Address',
    'delivery_type' => 48,
    'item_type' => 2,
    'item_quantity' => 1,
    'item_weight' => 0.5,
    'amount_to_collect' => 1200,
]);

use Centrex\Courier\Services\PathaoService;

$pathao = app(PathaoService::class);

$price = $pathao->priceCalculator([
    'store_id' => 1,
    'item_type' => 2,
    'delivery_type' => 48,
    'item_weight' => 0.5,
    'recipient_city' => 1,
    'recipient_zone' => 10,
]);

use Centrex\Courier\Services\RedxService;

$redx = app(RedxService::class);

$tracking = $redx->track('RX123456789');
$parcelInfo = $redx->parcelInfo('RX123456789');

use Centrex\Courier\Services\RokomariService;

$rokomari = app(RokomariService::class);

$html = $rokomari->track('ORDER123', '01700000000');

use Centrex\Courier\Services\SteadfastService;

$steadfast = app(SteadfastService::class);

$tracking = $steadfast->track('ST123456789');

use Centrex\Courier\Services\SundarbanService;

$sundarban = app(SundarbanService::class);

$tracking = $sundarban->track('CN123456');



namespace App\Http\Controllers;

use Centrex\Courier\Services\PathaoService;
use Illuminate\Http\JsonResponse;

class CourierController extends Controller
{
    public function pathaoCities(PathaoService $pathao): JsonResponse
    {
        return response()->json($pathao->cities());
    }
}

use Centrex\Courier\Exceptions\CourierException;
use Centrex\Courier\Services\PathaoService;

try {
    $response = app(PathaoService::class)->createBulkOrder([
        [
            'store_id' => 1,
            'recipient_name' => 'Customer',
            'recipient_phone' => '01700000000',
            'recipient_address' => 'Dhaka',
            'delivery_type' => 48,
            'item_type' => 2,
            'item_quantity' => 1,
            'item_weight' => 1,
            'amount_to_collect' => 500,
        ],
    ]);
} catch (CourierException $exception) {
    report($exception);
}
bash
php artisan vendor:publish --tag="courier-config"