Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. // Get Cost from RajaOngkir
  2. protected function getCostData(Request $request)
  3. {
  4. // $origin = "153"; // Jakarta Selatan
  5. // $destination = $request->district;
  6. // $weight = $request->weightData;
  7. // $courier = "jnt";
  8.  
  9. $curl = curl_init();
  10.  
  11. curl_setopt_array($curl, array(
  12. CURLOPT_URL => "https://pro.rajaongkir.com/api/cost",
  13. CURLOPT_RETURNTRANSFER => true,
  14. CURLOPT_ENCODING => "",
  15. CURLOPT_MAXREDIRS => 10,
  16. CURLOPT_TIMEOUT => 30,
  17. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  18. CURLOPT_CUSTOMREQUEST => "POST",
  19. CURLOPT_POSTFIELDS => "origin=501&originType=city&destination=574&destinationType=subdistrict&weight=1700&courier=jne",
  20. CURLOPT_HTTPHEADER => array(
  21. "content-type: application/x-www-form-urlencoded",
  22. "key: $this->rajaOngkirAPIKey"
  23. ),
  24. ));
  25.  
  26. $response = curl_exec($curl);
  27. $err = curl_error($curl);
  28.  
  29. curl_close($curl);
  30.  
  31. if ($err) {
  32. return "cURL Error #:" . $err;
  33. } else {
  34. return response()->json($response);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement