Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get Cost from RajaOngkir
- protected function getCostData(Request $request)
- {
- // $origin = "153"; // Jakarta Selatan
- // $destination = $request->district;
- // $weight = $request->weightData;
- // $courier = "jnt";
- $curl = curl_init();
- curl_setopt_array($curl, array(
- CURLOPT_URL => "https://pro.rajaongkir.com/api/cost",
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_ENCODING => "",
- CURLOPT_MAXREDIRS => 10,
- CURLOPT_TIMEOUT => 30,
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
- CURLOPT_CUSTOMREQUEST => "POST",
- CURLOPT_POSTFIELDS => "origin=501&originType=city&destination=574&destinationType=subdistrict&weight=1700&courier=jne",
- CURLOPT_HTTPHEADER => array(
- "content-type: application/x-www-form-urlencoded",
- "key: $this->rajaOngkirAPIKey"
- ),
- ));
- $response = curl_exec($curl);
- $err = curl_error($curl);
- curl_close($curl);
- if ($err) {
- return "cURL Error #:" . $err;
- } else {
- return response()->json($response);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement