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
Top comments (3)
Hi, how to integrate Pathao API in Wordpress woocommerce?
If you have documentation then it is possible to integrate
so i have the documentation can i make it work with shopify??