meowmoriaoi

Ongkiiir

May 15th, 2020
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. function get_kurir($pjg){
  2. $destination = explode('-', $pjg)[1];
  3. $data = array('jne', 'pos', 'tiki');
  4. $out .= '<option value="" disabled selected>Pilih Kurir</option>';
  5. $post = curl_init();
  6. foreach($data as $ini){
  7. curl_setopt($post, CURLOPT_URL, "https://api.rajaongkir.com/starter/cost");
  8. curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
  9. curl_setopt($post, CURLOPT_FOLLOWLOCATION, 1);
  10. curl_setopt($post, CURLOPT_CUSTOMREQUEST, "POST");
  11. curl_setopt($post, CURLOPT_POSTFIELDS, 'origin=22&destination='.$destination.'&weight=1000&courier='.$ini);
  12. curl_setopt($post, CURLOPT_HTTPHEADER , array(
  13. "content-type: application/x-www-form-urlencoded",
  14. "key: 412b1ec150824a89e0d8792b62adaa90"
  15. ));
  16. $response = json_decode(curl_exec($post), true);
  17. $base = $response['rajaongkir']['results'][0]['costs'];
  18. foreach($base as $bis){
  19. $kurir = strtoupper($ini);
  20. $service = $bis['service'];
  21. $price = $bis['cost'][0]['value'];
  22. $hum_price = number_format($price,0,",",".");
  23. $std = str_replace(' hari', '', strtolower($bis['cost'][0]['etd']));
  24. $out .= '<option value="'.$price.'" est-d="'.$std.' Hari">Rp. '.$hum_price.' ( '.$kurir.' '.$service.' )</option>';
  25. }
  26. }
  27. curl_close($post);
  28. return $out;
  29. }
Add Comment
Please, Sign In to add comment