PHP code example of nayemuf / pathao-courier

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

    

nayemuf / pathao-courier example snippets


$stores = PathaoCourier::store()->list();

use Nayemuf\PathaoCourier\Facades\PathaoCourier;

$orderData = [
    'store_id' => 149043, // Your store ID
    'merchant_order_id' => 'ORD-12345', // Your internal order ID
    'recipient_name' => 'John Doe',
    'recipient_phone' => '01712345678', // 11 digits, starts with 01
    'recipient_address' => 'House 123, Road 4, Sector 10, Uttara, Dhaka-1230',
    'delivery_type' => 48, // 48 for normal, 12 for on-demand
    'item_type' => 2, // 1 for document, 2 for parcel
    'item_quantity' => 1,
    'item_weight' => '0.5', // in kg (0.5 to 10)
    'amount_to_collect' => 1000, // 0 for non-COD orders
    'item_description' => 'Product description', // Optional
];

try {
    $response = PathaoCourier::order()->create($orderData);
    // Response contains: consignment_id, invoice_id, etc.
} catch (\Nayemuf\PathaoCourier\Exceptions\PathaoException $e) {
    // Handle error
    logger()->error('Pathao order creation failed', [
        'message' => $e->getMessage(),
        'errors' => $e->getErrors(),
    ]);
}

$orders = [
    [
        'store_id' => 149043,
        'merchant_order_id' => 'ORD-001',
        'recipient_name' => 'John Doe',
        'recipient_phone' => '01712345678',
        'recipient_address' => 'Address 1',
        'delivery_type' => 48,
        'item_type' => 2,
        'item_quantity' => 1,
        'item_weight' => '0.5',
        'amount_to_collect' => 1000,
    ],
    [
        'store_id' => 149043,
        'merchant_order_id' => 'ORD-002',
        'recipient_name' => 'Jane Doe',
        'recipient_phone' => '01712345679',
        'recipient_address' => 'Address 2',
        'delivery_type' => 48,
        'item_type' => 2,
        'item_quantity' => 1,
        'item_weight' => '1.0',
        'amount_to_collect' => 0,
    ],
];

$response = PathaoCourier::order()->createBulk($orders);

// Get order short info
$orderInfo = PathaoCourier::order()->getInfo($consignmentId);

// Get full order details
$orderDetails = PathaoCourier::order()->getDetails($consignmentId);

// Get all cities
$cities = PathaoCourier::area()->getCities();

// Get zones for a city
$zones = PathaoCourier::area()->getZones($cityId);

// Get areas for a zone
$areas = PathaoCourier::area()->getAreas($zoneId);

$priceData = [
    'store_id' => 149043,
    'item_type' => 2, // 1 for document, 2 for parcel
    'delivery_type' => 48, // 48 for normal, 12 for on-demand
    'item_weight' => 0.5, // in kg
    'recipient_city' => 1, // City ID
    'recipient_zone' => 298, // Zone ID
];

$price = PathaoCourier::price()->calculate($priceData);
// Returns: price, distance, etc.

// Get list of all stores
$stores = PathaoCourier::store()->list();

// Get single store info
$storeInfo = PathaoCourier::store()->getInfo($storeId);

// Create a new store
$storeData = [
    'name' => 'My Store',
    'contact_name' => 'John Doe',
    'contact_number' => '01712345678',
    'address' => 'Store Address',
    'city_id' => 1,
    'zone_id' => 298,
    'area_id' => 1234,
];
$newStore = PathaoCourier::store()->create($storeData);

// Refresh access token using refresh token
$response = PathaoCourier::refreshToken($refreshToken);
// Returns: ['access_token' => '...', 'refresh_token' => '...', 'expires_in' => 432000]

use Nayemuf\PathaoCourier\Exceptions\PathaoException;

try {
    $response = PathaoCourier::order()->create($orderData);
} catch (PathaoException $e) {
    // Get error message
    $message = $e->getMessage();
    
    // Get field-level validation errors (if any)
    $errors = $e->getErrors(); // Array of validation errors
    
    // Get HTTP status code
    $code = $e->getCode();
    
    // Log or handle error
    logger()->error('Pathao API Error', [
        'message' => $message,
        'errors' => $errors,
        'code' => $code,
    ]);
}

'rate_limit' => [
    'enabled' => true,
    'requests_per_minute' => 60,
],
bash
php artisan vendor:publish --tag=pathao-config