cloudenum / laravel-biteship
Unofficial Laravel package for Biteship API.
Fund package maintenance!
cloudenum
Buy Me A Coffee
Requires
- php: ^8.1
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- guzzlehttp/guzzle: ^7.5
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
README
With this package you can easily interact with Biteship API
Here is a simple example to retrieve shipping costs
// First you must define the items to ship $items = [ [ 'name' => 'Black L', 'description' => 'White Shirt', 'category' => 'fashion', 'value' => 165000, 'quantity' => 1, 'height' => 10, 'length' => 10, 'weight' => 200, 'width' => 10, ] ]; // Then specify the destination and the origin // You could use Postal Code but Biteship recommends you to use // their's Area ID, because it is more accurate. $destination = 12950; $origin = 12440; $availableCouriers = \Cloudenum\Biteship\Courier::all(); $rates = \Cloudenum\Biteship\CourierPricing::Rates([ 'origin_postal_code' => $origin, 'destination_postal_code' => $destination, 'couriers' => implode(',', $availableCouriers->pluck('courier_code')->unique()->toArray()), 'items' => $items, ]);
Installation
You can install the package via composer:
composer require cloudenum/laravel-biteship
You can publish the config file with:
php artisan vendor:publish --tag="biteship-config"
This is the contents of the published config file:
return [ 'base_url' => env('BITESHIP_BASE_URL', 'https://api.biteship.com'), 'api_key' => env('BITESHIP_API_KEY'), ];
Usage
The usage of this package will largely follows Biteship API Usage Flow.
Authentication
You must obtain an API key to use this package. Biteship has documentation on how you could get an API key.
After you get your API key add below environments to your .env
file
BITESHIP_API_KEY=<YourApiKey>
Area
Retrieve Area With Single Search
Example:
\Cloudenum\Biteship\Area::search("Lebak Bulus");
Retrieve Area With Double Search
For the first request you could use the Area::search()
method and set the double
paramater to true
.
Then for the second request you could use Area::doubleSearchSecondRequest()
method.
Example:
$area = \Cloudenum\Biteship\Area::search("Lebak Bulus")->first(); \Cloudenum\Biteship\Area::doubleSearchSecondRequest($area->id);
Tip:
You could get Area by their's ID withArea::doubleSearchSecondRequest()
method.
Rates
Retrieve Courier Rates
Example:
$items = [ [ 'name' => 'Black L', 'description' => 'White Shirt', 'category' => 'fashion', 'value' => 165000, 'quantity' => 1, 'height' => 10, 'length' => 10, 'weight' => 200, 'width' => 10, ] ]; $destination = 55510; $origin = 12440; $availableCouriers = \Cloudenum\Biteship\Courier::all(); $rates = \Cloudenum\Biteship\CourierPricing::Rates([ 'origin_postal_code' => $origin, 'destination_postal_code' => $destination, 'couriers' => implode(',', $availableCouriers->pluck('courier_code')->unique()->toArray()), 'items' => $items, ]);
Shipping Order
Create a Shipping Order
Example:
$data = [ 'shipper_contact_name' => 'Amir', 'shipper_contact_phone' => '088888888888', 'shipper_contact_email' => 'biteship@test.com', 'shipper_organization' => 'Biteship Org Test', 'origin_contact_name' => 'Amir', 'origin_contact_phone' => '088888888888', 'origin_address' => 'Plaza Senayan, Jalan Asia Afrika', 'origin_note' => 'Deket pintu masuk STC', 'origin_postal_code' => 12440, 'destination_contact_name' => 'John Doe', 'destination_contact_phone' => '088888888888', 'destination_address' => 'Lebak Bulus MRT', 'destination_postal_code' => 12950, 'destination_note' => 'Near the gas station', 'courier_company' => 'jne', 'courier_type' => 'reg', 'courier_insurance' => 500000, 'delivery_type' => 'now', 'order_note' => 'Please be careful', 'metadata' => [], 'items' => [ [ 'name' => 'Black L', 'description' => 'White Shirt', 'category' => 'fashion', 'value' => 165000, 'quantity' => 1, 'height' => 10, 'length' => 10, 'weight' => 200, 'width' => 10, ] ] ]; $biteshipOrder = \Cloudenum\Biteship\Order::create($data);
Get Shipping Order By ID
Example:
$biteshipOrder = \Cloudenum\Biteship\Order::find("ID");
Cancel a Shipping Order
Example:
// The reason could be a message why it is cancelled. $biteshipOrder->cancel($reason);
Shipment Tracking
Get Shipment Tracking By ID
Note
Tracking ID is not Waybill ID issued by couriers
Example:
$tracking = \Cloudenum\Biteship\Tracking::find("TrackingId");
Get Shipment Tracking By Waybill ID
Example:
$tracking = \Cloudenum\Biteship\Tracking::findPublicTracking("WaybillId");
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.