Laravel Shipper is a wrapper around the Shipper API.
You can install the package via composer:
composer require meteor/shipper
If you are not going to use Shipper's default migrations, you should call the Shipper::ignoreMigrations
method in the register
method of your App\Providers\AppServiceProvider
class. You may export the default migrations using the vendor:publish
Artisan command:
php artisan vendor:publish --tag=meteor.shipper.migrations
You can publish the config file with:
php artisan vendor:publish --provider="Meteor\Shipper\ShipperServiceProvider" --tag="meteor.shipper.config"
Before you can use the Shipper API, you need to set your API key. You can do this by setting the SHIPPER_API_KEY
environment variable in your .env
file. if you don't have an API key, you can get one from here.
SHIPPER_API_KEY=your-api-key
To initialize the Shipper API, you can use the Shipper
facade.
use Meteor\Shipper\Facades\Shipper;
$shipper = Shipper::make();
make()
accepts two optional parameters: baseUrl
and apiKey
. If you don't pass any parameters, it will use the SHIPPER_API_KEY
environment variable.
$shipper = Shipper::make('your-api-key', 'https://api.shipper.id');
Create an instance of logistic:
$logistic = $shipper->logistic();
$logistic->list()->json();
Create an instance of location:
$location = $shipper->location();
$response = $location->search(
keyword: '15510',
admLevel: 5, // optional
options: ['limit' => 5] // optional
)->json();
$location->getCountries()->json();
$location->getCountry()->json();
$location->getProvinces()->json();
$location->getProvince()->json();
$location->getProvincesByCountryId()->json();
$location->getCitiesByProvinceId()->json();
$location->getCities()->json();
$location->getCity()->json();
$location->getSuburbs()->json();
$location->getSuburbsByCityId()->json();
$location->getSuburb()->json();
$location->getAreasBySuburbId()->json();
$location->getAreas()->json();
$location->getArea()->json();
Create an instance of pricing:
$pricing = $shipper->pricing();
Note:
lat
andlng
must be in string format
$domesticBody = [
'cod' => false,
'destination' => [
'area_id' => 12284,
'lat' => '-6.9189281',
'lng' => '107.617093',
],
'origin' => [
'area_id' => 12441,
'lat' => '-6.3179073',
'lng' => '106.9506175'
],
'for_order' => true,
'height' => 6.54,
'length' => 6.54,
'width' => 6.54,
'weight' => 0.18,
'item_value' => 134950,
'sort_by' => ['final_price']
];
$internationalBody = [];
$pricing->domestic(body: $domesticBody)->json();
Available rates:
instant
regular
express
trucking
same-day
$pricing->domesticByRate(rateType: 'instant', body: $domesticBody)->json();
$pricing->international(body: $internationalBody)->json();
Create an instance of order:
$location = $shipper->order();
Note:
phone_number
cannot contain+
or0
prefix. so if your phone number is+6288112233443
or08111223344
you should remove the+
or0
prefix. you can useshipper_phone_format
helper function to format your phone number.
$response = $order->create([
'consignee' => [
'name' => 'Mr. Jonson H',
'phone_number' => '6288112233443'
],
'consigner' => [
'name' => 'Aslam H',
'phone_number' => '6281901560666'
],
'courier' => [
'cod' => false,
'rate_id' => 15,
'use_insurance' => false
],
'coverage' => 'domestic',
'destination' => [
'address' => 'Jl. Joni Afternoon, gg. Jonwik no 100A RT 08 RW 07 Kec. Sumur Bawah, Kota Melati, Jawa Jonggol, 50112',
'area_id' => 12284,
'lat' => '-6.9189281',
'lng' => '107.617093',
'email_address' => '[email protected]',
'company_name' => 'Marvel'
],
'origin' => [
'address' => 'Jl monyet kp rangga rt 11 rw 12 no 55 kode pos 17445 kel. jatimakmur kec. jatisolo',
'area_id' => 12441,
'lat' => '-6.3179073',
'lng' => '106.9506175',
'email_address' => '[email protected]',
'company_name' => 'Foo'
],
'package' => [
'items' => [
[
'name' => 'Daging Ikan 1kg',
'price' => 10000,
'qty' => 1
]
],
'package_type' => 2,
'height' => 4.1,
'length' => 4.1,
'width' => 4.1,
'weight' => 0.03,
'price' => 2000
],
'payment_type' => 'postpay'
])->json();
$order->detail('order-id')->json();
$order->trackingStatus('status-id')->json();
$order->availableOrders()->json();
$order->update('order-id', [])->json();
$order->cancel('order-id', [])->json();
$pickup = $shipper->pickup();
$pickup->create([])->json();
$pickup->cancel([])->json();
$pickup->createWithTimeslot([])->json();
$pickup->getTimeSlots()->json();
shipper_phone_format('08111223344'); // 628111223344
shipper_phone_format('+628111223344'); // 628111223344
shipper_categories(); // ['domestic', 'international']
shipper_rates(); // ['instant', 'regular', 'express', 'trucking', 'same-day']