Bangladeshi Courier Company Api Integration in Laravel Using Xenon Multicourier Package
Tags: ecourier, laravel, multicourier, laravelbdsms
Published: 2022-06-14 20:44:13

---
title: Bangladeshi Courier Company Api Integration in Laravel Using  Xenon Multicourier Package 
published: true
description: This is a courier api endpoints library for interacting such as e-courier, dhl, pathao etc

tags: ecourier, laravel, multicourier, laravelbdsms
# cover_image: https://raw.githubusercontent.com/arif98741/multicourier/master/img/Project-home-page-screenshot.png
# Use a ratio of 100:42 for best results.
---
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:
<pre>composer require xenon/multicourier</pre>
Step 2:
Then, publish the package

<pre>php artisan vendor:publish --provider=Xenon\MultiCourier\MultiCourierServiceProvider</pre>
Step 3:
Set .env configuration for individual couriers . Here E-courier and Pathao for example
<pre>
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'
</pre>
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
<pre>
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
</pre>
<pre> 
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();
</pre>
For accesing to repo and all method list visit github link from here https://github.com/arif98741/multicourier