$origin_latitude, "origin_longitude" => $origin_longitude, "destination_latitude" => $destination_latitude, "destination_longitude" => $destination_longitude, "couriers" => env("BITESHIP_COURIER","grab,gojek,tiki,jnt,anteraja"), "items" => $items ]; $res = Http::withHeaders([ "authorization" => $key ]) ->withBody(json_encode($body), 'application/json') ->post($url."/v1/rates/couriers"); if ($res->status() != 200 && $res->json()['error'] != null) { Log::info(json_encode($res->json())); Log::info($body); throw ValidationException::withMessages([ "message" => $res->json()['error'] ]); } if ($res->status() == 200) return $res->json(); return null; }); } public function byPostal($params) { $destination_postal_code = $params["destination_postal_code"]; $origin_postal_code = $params["origin_postal_code"]; $items = $params["items"]; $sha1 = sha1(json_encode($items)); $key = $origin_postal_code."_".$destination_postal_code."_".$sha1; return Cache::remember("rates_".$key, 60 * 60 * 24, function() use ( $origin_postal_code, $destination_postal_code, $items) { $url = env("BITESHIP_URL"); $key = env("BITESHIP_KEY"); $res = Http::withHeaders([ "authorization" => $key ]) ->withBody(json_encode([ "origin_postal_code" => $origin_postal_code, "destination_postal_code" => $destination_postal_code, "couriers" => env("BITESHIP_COURIER","tiki,jnt,anteraja"), "items" => $items ]), 'application/json') ->post($url."/v1/rates/couriers"); if ($res->status() != 200 && $res->json()['error'] != null) { throw ValidationException::withMessages([ "message" => $res->json()['error'] ]); } if ($res->status() == 200) return $res->json(); return null; }); } }