PHP code example of juhara / rajaongkir

1. Go to this page and download the library: Download juhara/rajaongkir library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

juhara / rajaongkir example snippets


$rajaongkir = new Juhara\Rajaongkir('YOUR_API_KEY', Rajaongkir::ACCOUNT_STARTER);

$rajaongkir = new Juhara\Rajaongkir('YOUR_API_KEY');

use Juhara\Rajaongkir;

$rajaongkir = new Rajaongkir('YOUR_API_KEY', Rajaongkir::ACCOUNT_BASIC);

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();