juhara / rajaongkir
Advanced RajaOngkir API PHP Class
Fund package maintenance!
Patreon
Open Collective
Installs: 15
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 39
Open Issues: 0
Type:php-class
Requires
- php: ^7.4|^8.0.2
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^9.6
This package is not auto-updated.
Last update: 2024-11-01 14:47:21 UTC
README
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.
Requirements
Installation
$ composer require juhara/rajaongkir
Usage
Initialization
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);
Get list of provinces
$provinces = $rajaongkir->getProvinces();
Get detail of a province
// province ID = 1 $province = $rajaongkir->getProvince(1);
Get list of all cities
$cities = $rajaongkir->getCities();
Get list of cities in a province
// province id = 1 $cities = $rajaongkir->getCities(1);
Get city detail
// city id = 1 $city = $rajaongkir->getCity(1);
Get list of subdistricts in a city
// city id = 39 $subdistricts = $rajaongkir->getSubdistricts(39);
Get subdistrict detail
// subdistrict id = 537 $subdistrict = $rajaongkir->getSubdistrict(537);
Get list all cities with international shipping support
// not available for starter $internationalOrigins = $rajaongkir->getInternationalOrigins();
Get list all cities in a province with international shipping support
// not available for starter // province id = 6 $internationalOrigins = $rajaongkir->getInternationalOrigins(6);
Get international origin detail
// not available for starter // city id = 152 // province id = 6 $internationalOrigin = $rajaongkir->getInternationalOrigin(152, 6);
Get international country list
// not available for starter $internationalDestinations = $rajaongkir->getInternationalDestinations();
Get international destination detail
// not available for starter // country id = 108 $internationalDestination = $rajaongkir->getInternationalDestination(108);
Get shipping cost based on weight (in gram)
// origin city id = 501 // destination subdistrict id = 574 // weight 1000 gram // courier = 'jne' $cost = $rajaongkir->getCost(['city' => 501], ['subdistrict' => 574], 1000, 'jne');
Get shipping cost based on volume
// 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' );
Get shipping cost based on weight or volume
// 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' );
Get international shipping cost based on weight
// 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' );
Track shipping
// receipt id (no resi pengiriman) = 'SOCAG00183235715' // courier = 'jne' $waybill = $rajaongkir->getWaybill('SOCAG00183235715', 'jne');
Get IDR currency exchange to USD
$currency = $rajaongkir->getCurrency();
Get latest error
// get latest error if(false === ($waybill = $rajaongkir->getWaybill('SOCAG00183235715', 'jne'))) { var_dump($rajaongkir->getErrors()); }
Get courier list based on account type
$supportedCouriers = $rajaongkir->getSupportedCouriers();
Get waybill tracking list based on account type
$supportedWayBills = $rajaongkir->getSupportedWayBills();