Skip to content

Unofficial Laravel package for Biteship API

License

Notifications You must be signed in to change notification settings

cloudenum/laravel-biteship

Repository files navigation

Unofficial Laravel package for Biteship API

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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

API Doc

Example:

\Cloudenum\Biteship\Area::search("Lebak Bulus");

Retrieve Area With Double Search

API Doc

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 with Area::doubleSearchSecondRequest() method.

Rates

Retrieve Courier Rates

API Doc

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

API Doc

Example:

$data = [
    'shipper_contact_name' => 'Amir',
    'shipper_contact_phone' => '088888888888',
    'shipper_contact_email' => '[email protected]',
    '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

API Doc

Example:

$biteshipOrder = \Cloudenum\Biteship\Order::find("ID");

Cancel a Shipping Order

API Doc

Example:

// The reason could be a message why it is cancelled.
$biteshipOrder->cancel($reason);

Shipment Tracking

Get Shipment Tracking By ID

API Doc

Note
Tracking ID is not Waybill ID issued by couriers

Example:

$tracking = \Cloudenum\Biteship\Tracking::find("TrackingId");

Get Shipment Tracking By Waybill ID

API Doc

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.

About

Unofficial Laravel package for Biteship API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages