-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcek_ongkir.php
39 lines (34 loc) · 1.13 KB
/
cek_ongkir.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
$asal = $_POST['asal'];
$id_kabupaten = $_POST['kab_id'];
$kurir = $_POST['kurir'];
$berat = $_POST['berat'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://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 => "originType=city&origin=501&destinationType=city&destination={$id_kabupaten}&weight=1000&courier=jne",
CURLOPT_HTTPHEADER => array(
"content-type: application/x-www-form-urlencoded",
"key: Your-API-Key"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
/*echo $response;*/
$json = json_decode($response);
/* $diskon = $json->rajaongkir->results[0]->costs[0]->cost[0]->value - ($json->rajaongkir->results[0]->costs[0]->cost[0]->value * 0.3);
echo $diskon;*/
echo $json->rajaongkir->results[0]->costs[0]->cost[0]->value;
/*echo $json->rajaongkir->results[0]->name;*/
}
?>