Laravel Courier Api Integration Using Multicourier for Bangladeshi Courier Companies

Ariful Islam
2 min readJun 14, 2022

--

We are developers and we have to work on several projects. For several projects we have to integrate different company’s api for courier parcel booking, shipping and also tracking. I aslo faced that. After faching that awkward problem for a long time I motivated my mind to make a common library/package that will solve this issues like my previously released package Xenon/Laravelbdsms

Here I developed Xenon/MultiCourier for solving this hassel that will fixed coding structure for all providers though their api are different. Your duty is to change api credentials provided by your courier company such E-courier, Pathao, Steadfast, Paperfly, Redx; Follow the below steps for integrating this package in your project easily

Step 1:

composer require xenon/multicourier

Step 2:

Then, publish the package

php artisan vendor:publish --provider=Xenon\MultiCourier\MultiCourierServiceProvider

Step 3:

Set .env configuration for individual couriers . Here E-courier and Pathao for example

PATHAO_CLIENT_SECRET="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
PATHAO_USERNAME="xxxx@example.com"
PATHAO_PASSWORD="xxxxxx"
PATHAO_GRANT_TYPE="password"
ECOURIER_API_KEY='xxx'
ECOURIER_API_SECRET='xxx'
ECOURIER_USER_ID='xxxx'
ECOURIER_ENVIRONMENT='xxxx'

Otherwise, if you want more control, you can use the underlying sender object. This will not touch any laravel facade or service provider.

Here below are sample code for interacting with provider’s api

Get Location

use Xenon\MultiCourier\Provider\ECourier;
use Xenon\MultiCourier\Courier;


$courier = Courier::getInstance();
$courier->setProvider(ECourier::class, 'local'); /* local/production */
$courier->setConfig([
'API-KEY' => 'xxx',
'API-SECRET' => 'xxxx',
'USER-ID' => 'xxxx',
]);
$courier->setParams(['city'=>'Dhaka']);
$thanas = $courier->getThanas(); //get thana
$cities = $courier->getCities(); //get city

Place Order

//place order
use Xenon\MultiCourier\Provider\ECourier;
use Xenon\MultiCourier\Courier;


$courier = Courier::getInstance();
$courier->setProvider(ECourier::class, 'local'); /* local/production */
$courier->setConfig([
'API-KEY' => 'xxx',
'API-SECRET' => 'xxx',
'USER-ID' => 'xxx',
]);
$orderData = array(
'recipient_name' => 'XXXXX',
'recipient_mobile' => '017XXXXX',
'recipient_city' => 'Dhaka',
'recipient_area' => 'Badda',
'recipient_thana' => 'Badda',
'recipient_address' => 'Full Address',
'package_code' => '#XXXX',
'product_price' => '1500',
'payment_method' => 'COD',
'recipient_landmark' => 'DBBL ATM',
'parcel_type' => 'BOX',
'requested_delivery_time' => '2019-07-05',
'delivery_hour' => 'any',
'recipient_zip' => '1212',
'pick_hub' => '18490',
'product_id' => 'DAFS',
'pick_address' => 'Gudaraghat new mobile',
'comments' => 'Please handle carefully',
'number_of_item' => '3',
'actual_product_price' => '1200',
'pgwid' => 'XXX',
'pgwtxn_id' => 'XXXXXX'
);

$courier->setParams($orderData);
$response = $courier->placeOrder();

For accesing to repo and all method list visit github link from here https://github.com/arif98741/multicourier

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Ariful Islam
Ariful Islam

Written by Ariful Islam

Working on PHP, Laravel, CI, CakePHP, API. Open Source contributor, Cloud Expert, Project Consultant, Technical Writer. Owner at https://programmingmindset.com

No responses yet

Write a response