PHP code example of nicxonsolutions / rajaongkir

1. Go to this page and download the library: Download nicxonsolutions/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/ */

    

nicxonsolutions / rajaongkir example snippets


return [
    'api_key' => env('RAJAONGKIR_API_KEY'),
    'base_url' => env('RAJAONGKIR_BASE_URL', 'https://rajaongkir.komerce.id/api'),
    'account_type' => env('RAJAONGKIR_ACCOUNT_TYPE', 'starter'),
    'origin' => env('RAJAONGKIR_ORIGIN'),
    'base_weight' => (int) env('RAJAONGKIR_BASE_WEIGHT', 0),
    'sort_shipping' => env('RAJAONGKIR_SORT_SHIPPING', 'no'),
];

use Nicxonsolutions\Rajaongkir\Facades\Rajaongkir;

$destinations = Rajaongkir::searchDomesticDestination('Jakarta');

use Nicxonsolutions\Rajaongkir\Rajaongkir;

class CheckoutController
{
    public function shipping(Rajaongkir $rajaongkir)
    {
        return $rajaongkir->searchDomesticDestination('Bandung');
    }
}

$destinations = Rajaongkir::searchDomesticDestination('Jakarta');

[
    'id' => 31711,
    'text' => 'Gambir, Jakarta Pusat, DKI Jakarta 10110',
    'label' => 'Gambir, Jakarta Pusat, DKI Jakarta 10110',
    'subdistrict_name' => 'Gambir',
    'district_name' => 'Gambir',
    'city_name' => 'Jakarta Pusat',
    'province_name' => 'DKI Jakarta',
    'zip_code' => '10110',
]

$countries = Rajaongkir::searchInternationalDestination('Singapore');

$provinces = Rajaongkir::provinces();

$province = Rajaongkir::province($provinceId);

$cities = Rajaongkir::cities($provinceId);

$city = Rajaongkir::city($provinceId, $cityId);

$city = Rajaongkir::findCity($cityId);

$districts = Rajaongkir::districts($cityId);

$district = Rajaongkir::district($cityId, $districtId);

$subDistricts = Rajaongkir::subDistricts($districtId);

$subDistrict = Rajaongkir::subDistrict($districtId, $subDistrictId);

[
    'id' => 1,
    'text' => 'Bali',
    'name' => 'Bali',
    // Original API fields are preserved as well.
]

$rates = Rajaongkir::calculateDomestic([
    'origin' => '31555',
    'destination' => '31711',
    'weight' => 1200,
    'courier' => ['jne', 'jnt', 'pos'],
]);

$rates = Rajaongkir::calculateInternational([
    'origin' => '31555',
    'destination' => '702',
    'weight' => 1200,
    'courier' => ['jne', 'pos'],
]);

$rates = Rajaongkir::calculateDistrictDomestic([
    'origin' => '4570',
    'destination' => '4571',
    'weight' => 1200,
    'courier' => ['jne', 'jnt', 'pos'],
]);

[
    'courier' => 'jne',
    'courier_label' => 'JNE',
    'service' => 'REG',
    'description' => 'Layanan Reguler',
    'cost' => 18000,
    'currency' => 'IDR',
    'etd' => '2-3',
    'note' => '',
    'cost_conversion' => false,
]

[
    'parsed' => [...],
    'raw' => [...],
]

$tracking = Rajaongkir::trackWaybill(
    awb: 'YOUR_AWB_NUMBER',
    courier: 'jne',
);

$tracking = Rajaongkir::trackWaybill(
    awb: 'YOUR_AWB_NUMBER',
    courier: 'jne',
    lastPhoneNumber: '12345',
);

[
    'delivered' => true,
    'summary' => [...],
    'details' => [...],
    'delivery_status' => [...],
    'manifest' => [...],
]

$quote = Rajaongkir::quote(
    cart: ['weight' => 1200],
    destination: [
        'country' => 'ID',
        'id' => '31711',
    ],
);

$quote = Rajaongkir::quote(
    cart: ['weight' => 1200],
    destination: ['country' => 'ID', 'id' => '31711'],
    options: [
        'origin' => '31555',
        'params' => [
            'courier' => ['jne', 'sicepat'],
        ],
    ],
);

$valid = Rajaongkir::validateApiKey();

use Nicxonsolutions\Rajaongkir\Exceptions\RajaongkirException;
use Nicxonsolutions\Rajaongkir\Facades\Rajaongkir;

try {
    $rates = Rajaongkir::calculateDomestic([...]);
} catch (RajaongkirException $e) {
    report($e);

    return back()->withErrors([
        'shipping' => $e->getMessage(),
    ]);
}

$all = Rajaongkir::couriers();
$domestic = Rajaongkir::couriers('domestic');
$international = Rajaongkir::couriers('international');

$all = Rajaongkir::courier('all');
$jne = Rajaongkir::courier('jne');
$regularServices = Rajaongkir::courier('REG');
bash
php artisan vendor:publish --tag=rajaongkir-config
bash
php artisan config:clear