PHP code example of rdj / rajaongkir

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

    

rdj / rajaongkir example snippets

code
$ php artisan vendor:publish
code
$id = 12;
$getData = Rajaongkir::setEndpoint('province')
                    ->setBase(env("RAJAONGKIR_TYPE"))
                    ->setQuery(['id' => $id])
                    ->get();
        
return response()->json( $getData['rajaongkir'] );
code
$id = 12;
$getData = Rajaongkir::setEndpoint('city')
                    ->setBase(env("RAJAONGKIR_TYPE"))
                    ->setQuery(['id' => $id])
                    ->get();
        
return response()->json( $getData['rajaongkir'] );
code
$id = 12;
$getData = Rajaongkir::setEndpoint('subdistrict')
                    ->setBase(env("RAJAONGKIR_TYPE"))
                    ->setQuery(['id' => $id])
                    ->get();
        
return response()->json( $getData['rajaongkir'] );
code
$request = [
   "origin" => "501",
   "originType"  => "city",
   "destination" => "574",
   "destinationType" => "subdistrict",
   "weight" => 1700,
   "courier" => "jne"
];
        
$getData = Rajaongkir::setEndpoint('cost')
                    ->setBase(env("RAJAONGKIR_TYPE"))
                    ->setBody($request)
                    ->post();
        
return response()->json( $getData['rajaongkir'] );