Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_kurir($pjg){
- $destination = explode('-', $pjg)[1];
- $data = array('jne', 'pos', 'tiki');
- $out .= '<option value="" disabled selected>Pilih Kurir</option>';
- $post = curl_init();
- foreach($data as $ini){
- curl_setopt($post, CURLOPT_URL, "https://api.rajaongkir.com/starter/cost");
- curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($post, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($post, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($post, CURLOPT_POSTFIELDS, 'origin=22&destination='.$destination.'&weight=1000&courier='.$ini);
- curl_setopt($post, CURLOPT_HTTPHEADER , array(
- "content-type: application/x-www-form-urlencoded",
- "key: 412b1ec150824a89e0d8792b62adaa90"
- ));
- $response = json_decode(curl_exec($post), true);
- $base = $response['rajaongkir']['results'][0]['costs'];
- foreach($base as $bis){
- $kurir = strtoupper($ini);
- $service = $bis['service'];
- $price = $bis['cost'][0]['value'];
- $hum_price = number_format($price,0,",",".");
- $std = str_replace(' hari', '', strtolower($bis['cost'][0]['etd']));
- $out .= '<option value="'.$price.'" est-d="'.$std.' Hari">Rp. '.$hum_price.' ( '.$kurir.' '.$service.' )</option>';
- }
- }
- curl_close($post);
- return $out;
- }
Add Comment
Please, Sign In to add comment