ncaneldiee / rajaongkir

A PHP library which implement the complete functionality of Raja Ongkir API
MIT License
5 stars 2 forks source link

courier in pro account #4

Closed robertnicjoo closed 6 years ago

robertnicjoo commented 6 years ago

Hi,

How can I get all couriers in pro account?

this is my function now but only able to get one courier at the moment:

public function indexajax(Request $request, $cityID) {
      $rajaongkir = new Rajaongkir\Domestic('xxxxxxxxx');
      $province = $rajaongkir->province();

      $origin = 152; //Jakarta
      $destination = $request->cityID;
      $weight = 1;
      $courier = 'jne'; // jne, tiki, pos
      $cost = $rajaongkir->cost($origin, $destination, $weight, $courier);
      return response()->json($cost);
    }

PS:

please help me to get account type in my code

$rajaongkir = new Rajaongkir\Domestic('xxxxxxxxx');

for this i had to change Domestic.php file. couldn't add my type base on documents of this package

Thanks.

robertnicjoo commented 6 years ago

no support hah?

robertnicjoo commented 6 years ago

anyone?

ncaneldiee commented 6 years ago

@robertnicjoo really sorry, didn't read this issue

You can use $rajaongkir->account(); to check your account type and if you want to add multiple courier, just separated courier code with :. Ex : $courier = 'jne:tiki:post:jnt'; (jnt need pro account), hope this help

PS : Don't forget to read the wiki to more information about this packagemention me if you need help

robertnicjoo commented 6 years ago

@ncaneldiee thanks for respond anyway, but I made a better way rather that typing all the courier names (i guess),

Since we have couriers in our app config file separated by api types I've made array of my couriers and listed them in function,

Here is sample function for those might some day end up here:

public function indexajax(Request $request, $weight, $cityID) {
      $rajaongkir = new Rajaongkir\Domestic('xxxxxxxxxxxxxxxxxxxxxxx');
      $province = $rajaongkir->province();
      $cori = $rajaongkir->courier('all'); //get all couriers (base on your domestic code it will retrieve it automatically)
      $cori = []; // put them in array
      $origin = 152; //Jakarta
      $destination = $request->cityID;
      $weight = $request->weight;
      $courier = $cori; // get couriers array in your function loop
      $cost = $rajaongkir->cost($origin, $destination, $weight, $courier);
      return response()->json($cost);
    }

the rest of it is huge JavaScript coding, you can figure it out...

Demo

This demo is made by Pro API,

rajaongkir api by tjd-studio com