PHP code example of risan / jne

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

    

risan / jne example snippets



// Include autoloder file.
e.
$jne = new Jne\Jne();

// Search for origin city and get the first mathced item.
$bandung = $jne->searchOrigin('Bandung')->first();

// Search for destination city ang get the first matched item.
$depok = $jne->searchDestination('Depok')->first();

// Create a package instance.
// From bandung to depok 10 Kilograms package.
$myPackage = new Jne\Package($origin, $destination, Jne\Weight::fromKilograms(10));

// Get delivery options for $myPackage.
// @return Jne\Collections\DeliveryOptionCollection
$deliveryOptions = $jne->deliveryOptions($myPackage);

$jne->searchOrigin(string $query);

$jne = new Jne\Jne();

$origins = $jne->searchOrigin('bandar');

print_r($origins->toArray());

Array
(
  [0] => Jne\Location Object
    (
      [name:protected] => BANDAR SRI BENTAN, KAB.BINTAN
      [code:protected] => VE5KMTAxMDA=
    )

  [1] => Jne\Location Object
    (
      [name:protected] => BANDAR,SIMALUNGUN
      [code:protected] => TUVTMjA2MDE=
    )

  [2] => Jne\Location Object
    (
      [name:protected] => BANDARLAMPUNG
      [code:protected] => VEtHMTAwMDA=
    )
)

$jne->searchDestination(string $query);

$jne = new Jne\Jne();

$destinations = $jne->searchDestination('purwodadi');

Array
(
  [0] => Jne\Location Object
    (
        [name:protected] => PURWODADI,KAB.GROBOGAN
        [code:protected] => U1JHMjExMDA=
    )

  [1] => Jne\Location Object
    (
        [name:protected] => PURWODADI,MUARA BELITI BARU
        [code:protected] => UExNMTAzMTI=
    )

  [2] => Jne\Location Object
    (
        [name:protected] => PURWODADI,PASURUAN
        [code:protected] => UEROMTAwMTU=
    )

  [3] => Jne\Location Object
    (
        [name:protected] => PURWODADI,PURWOREJO
        [code:protected] => TUdMMTAzMDg=
    )
)

// Create an instance of Jne\Jne class.
$jne = new Jne\Jne();

// Find origin locations that match `Bandung`.
$origins = $jne->searchOrigin('Bandung');

// Get the first matched location.
$bandung = $origin->first();

Jne\Location Object
  (
    [name:protected] => BANDUNG
    [code:protected] => QkRPMTAwMDA=
  )

$origin = new Jne\Location(string $name, string $code);

$bandung = new Jne\Location('BANDUNG', 'QkRPMTAwMDA=');

// Create an instance of Jne\Jne class.
$jne = new Jne\Jne();

// Find destination locations that match `Depok`.
$destinations = $jne->searchOrigin('Depok');

// Get the first matched location.
$depok = $destinations->first();

Jne\Location Object
  (
    [name:protected] => DEPOK
    [code:protected] => RFBLMTAwMDA=
  )

$destination = new Jne\Location(string $name, string $code);

$depok = new Jne\Location('DEPOK', 'RFBLMTAwMDA=');

// Create from grams unit.
Jne\Weight::fromGrams(float $grams);

// Create from kilograms unit.
Jne\Weight::fromKilograms(float $kilograms);

// Create from pounds unit.
Jne\Weight::fromPounds(float $pounds);

$weight = Jne\Weight::fromKilograms(10);

$package = new Jne\Package($origin, $destination, $weight);

$jne = new Jne\Jne();

// Create a origin location.
$bandung = new Jne\Location('BANDUNG', 'QkRPMTAwMDA=');

// Find a destination location.
$depok = $jne->searchDestination('DEPOK')->first();

// Create weight.
$weight = Jne\Weight::fromKilograms(10);

$package = new Jne\Package($bandung, $depok, $weight);

$jne = new Jne\Jne();

$jne->deliveryOptions(Jne\Package $package);

$jne = new Jne\Jne();

// Create a origin location.
$bandung = new Jne\Location('BANDUNG', 'QkRPMTAwMDA=');

// Create a destination location.
$depok = new Jne\Location('DEPOK', 'RFBLMTAwMDA=');

// Create weight.
$weight = Jne\Weight::fromKilograms(10);

// Create package.
$package = new Jne\Package($bandung, $depok, $weight);

$deliveryOptions = $jne->deliveryOptions($package);

Array
(
  [0] => Jne\DeliveryOption Object
    (
      [service:protected] => OKE
      [type:protected] => Dokumen / Paket
      [tariff:protected] => 100000
      [estimatedDays:protected] => 2-3 Days
    )

  [1] => Jne\DeliveryOption Object
    (
      [service:protected] => REG
      [type:protected] => Dokumen / Paket
      [tariff:protected] => 110000
      [estimatedDays:protected] => 1-2 Days
    )
  ...