RajaOngkir API PHP client
- Support all kind of RajaOngkir account (Starter, Basic, Pro).
- Get shipping cost based on weight (gram) and/or volume (width x heigth x length).
This is original RajaOngkir library fork with goal to add PHP 8.0 support also replace HTTP Client with Guzzle.
$ composer require juhara/rajaongkir
Create instance for Starter account
$rajaongkir = new Juhara\Rajaongkir('YOUR_API_KEY', Rajaongkir::ACCOUNT_STARTER);
When account type is not set, it is assumed starter, so code below is same as above.
$rajaongkir = new Juhara\Rajaongkir('YOUR_API_KEY');
Create instance for Basic account
use Juhara\Rajaongkir;
$rajaongkir = new Rajaongkir('YOUR_API_KEY', Rajaongkir::ACCOUNT_BASIC);
Create instance for Pro account
use Juhara\Rajaongkir;
$rajaongkir = new Rajaongkir('YOUR_API_KEY', Rajaongkir::ACCOUNT_PRO);
$provinces = $rajaongkir->getProvinces();
// province ID = 1
$province = $rajaongkir->getProvince(1);
$cities = $rajaongkir->getCities();
// province id = 1
$cities = $rajaongkir->getCities(1);
// city id = 1
$city = $rajaongkir->getCity(1);
// city id = 39
$subdistricts = $rajaongkir->getSubdistricts(39);
// subdistrict id = 537
$subdistrict = $rajaongkir->getSubdistrict(537);
// not available for starter
$internationalOrigins = $rajaongkir->getInternationalOrigins();
// not available for starter
// province id = 6
$internationalOrigins = $rajaongkir->getInternationalOrigins(6);
// not available for starter
// city id = 152
// province id = 6
$internationalOrigin = $rajaongkir->getInternationalOrigin(152, 6);
// not available for starter
$internationalDestinations = $rajaongkir->getInternationalDestinations();
// not available for starter
// country id = 108
$internationalDestination = $rajaongkir->getInternationalDestination(108);
// origin city id = 501
// destination subdistrict id = 574
// weight 1000 gram
// courier = 'jne'
$cost = $rajaongkir->getCost(['city' => 501], ['subdistrict' => 574], 1000, 'jne');
// origin city id = 501
// destination subdistrict id = 574
// volume 50x60x70
// courier = 'jne'
$cost = $rajaongkir->getCost(
['city' => 501],
['subdistrict' => 574],
[
'width' => 50,
'height' => 60,
'length' => 70,
],
'jne'
);
// origin city id = 501
// destination subdistrict id = 574
// weight 1000 gram
// volume 50x60x70
// courier = 'jne'
$cost = $rajaongkir->getCost(
['city' => 501],
['subdistrict' => 574],
[
'weight' => 1000,
'length' => 50,
'width' => 50,
'height' => 50,
],
'jne'
);
// not available for starter
// origin city id = 152
// destination country id = 108
// weight 1400 gram
// courier = 'pos'
$cost = $rajaongkir->getCost(
['city' => 152],
['country' => 108],
1400,
'pos'
);
// receipt id (no resi pengiriman) = 'SOCAG00183235715'
// courier = 'jne'
$waybill = $rajaongkir->getWaybill('SOCAG00183235715', 'jne');
$currency = $rajaongkir->getCurrency();
// get latest error
if(false === ($waybill = $rajaongkir->getWaybill('SOCAG00183235715', 'jne'))) {
var_dump($rajaongkir->getErrors());
}
$supportedCouriers = $rajaongkir->getSupportedCouriers();
$supportedWayBills = $rajaongkir->getSupportedWayBills();