Exemplo n.º 1
0
 /**
  * Constructor
  * @param string $api_key API Key Anda sebagaimana yang tercantum di akun panel RajaOngkir
  * @param array $additional_headers Header tambahan seperti android-key, ios-key, dll
  */
 public function __construct($api_key, $additional_headers = array())
 {
     RajaOngkir::$api_key = $api_key;
     \Unirest::defaultHeader("Content-Type", "application/x-www-form-urlencoded");
     \Unirest::defaultHeader("key", RajaOngkir::$api_key);
     foreach ($additional_headers as $key => $value) {
         \Unirest::defaultHeader($key, $value);
     }
 }
Exemplo n.º 2
0
 /**
  * Construct
  * @param string $apiKey API Key Anda sebagaimana yang tercantum di akun panel RajaOngkir
  * @param string[] $additionalHeaders Header tambahan seperti android-key, ios-key, dll
  */
 public function __construct($apiKey, $additionalHeaders = [])
 {
     self::$apiKey = $apiKey;
     $this->rest = new RESTClient();
     $this->rest->initialize(array('server' => self::$host));
     $this->rest->set_header('Content-Type', 'application/x-www-form-urlencoded');
     $this->rest->set_header('key', self::$apiKey);
     foreach ($additionalHeaders as $key => $value) {
         $this->restrest->set_header($key, $value);
     }
 }
Exemplo n.º 3
0
    public function updateEkspedisi($id)
    {
        $id = Kabupaten::find($id)->nama;
        if (\Cache::has('rajaongkir')) {
            $rs = \Cache::get('rajaongkir');
        } else {
            $rs = \RajaOngkir::getCity();
            \Cache::put('rajaongkir', $rs, 60);
        }
        $cart = Shpcart::cart()->contents();
        $berat = 0;
        foreach ($cart as $value) {
            $beratnew = \Produk::find($value['produkId'])->berat;
            $berat = $berat + $value['qty'] * $beratnew;
        }
        //$berat = ceil($berat/1000);
        $html = '';
        if ($berat != 0) {
            $statusApi = $this->setting->statusApi;
            $alresult = null;
            $asal = $this->setting->kotaAsal;
            $results = $rs['rajaongkir']['results'];
            //cari tujuan pengirim
            $destination = array_filter($results, function ($obj) use($id) {
                if (strtolower($obj['city_name']) == strtolower($id)) {
                    return true;
                }
                return false;
            });
            $destination = array_values($destination)[0];
            //cari kota asal pengirim
            $origin = array_filter($results, function ($obj) use($asal) {
                if (strtolower($obj['city_name']) == strtolower($asal)) {
                    return true;
                }
                return false;
            });
            $origin = array_values($origin)[0];
            if ($statusApi == 1) {
                $alresult = \RajaOngkir::getCost($origin['city_id'], $destination['city_id'], $berat, 'jne');
            }
            if ($statusApi == 2) {
                $alresult = \RajaOngkir::getCost($origin['city_id'], $destination['city_id'], $berat, 'tiki');
            }
            if ($statusApi == 3) {
                $alresult = \RajaOngkir::getCost($origin['city_id'], $destination['city_id'], $berat, 'pos');
            }
            if ($alresult != null) {
                foreach ($alresult['rajaongkir']['results'] as $key => $item) {
                    if (count($item['costs']) > 0) {
                        foreach ($item['costs'] as $service) {
                            $html = $html . '<label class="radio span12" style="margin-left:0;margin-right:10px">
                              <input style="margin-left:0;margin-right:10px" type="radio" name="ekspedisilist" id="optionsRadios1" value="' . $item['code'] . ' : ' . $service['service'] . ' ' . $service['description'] . ';' . $service['cost'][0]['value'] . '"><small>' . $item['name'] . '|' . $service['service'] . ':
                              ' . $service['description'] . ' harga : ' . price($service['cost'][0]['value']) . '</small>
                            </label>';
                        }
                    }
                }
            }
            $tarif = \Tarif::join('paket', 'tarif.paketId', '=', 'paket.id')->whereRaw('(tarif.tujuan ="' . $id . '" or tarif.tujuan LIKE "%' . strtolower($id) . '%" or tarif.tujuan LIKE "%' . strtoupper($id) . '%" or tarif.tujuan LIKE "%' . ucfirst($id) . '%") and paket.akunId=' . $this->akunId)->get();
            $beratLokal = ceil($berat / 1000);
            foreach ($tarif as $key => $value) {
                $html = $html . '<label class="radio">
                                    <input type="radio" style="margin-left:0;margin-right:10px" name="ekspedisilist" value="' . $value->paket->ekspedisi->nama . ' ' . $value->nama . ';' . $value->harga * $beratLokal . '">
                                    ' . $value->paket->ekspedisi->nama . ' ' . $value->paket->nama . ' - ' . price($value->harga * $beratLokal) . '
                                </label><br>';
            }
            if ($html == '') {
                $html = $html . '<p>Tidak ditemukan ekpedisi dari <strong>' . $this->setting->kotaAsal . '</strong> ke tujuan : <strong>' . $id . '</strong> <br>
                    <small><i>untuk informasi pengiriman silakan hubungi kami <a href="' . URL::to('kontak') . '" target="_blank">disini</a></i></small> <a type="button" class="btn btn-link close" data-dismiss="modal" aria-hidden="true">[tutup]</a>
                </p>

                ';
                $html = '<div id="result_ekspedisi">' . $html . '<hr></div>';
                return \Response::json(['not_found' => true, 'html' => $html]);
            } else {
                $html = '<p>Ekspedisi list dari <strong>' . $this->setting->kotaAsal . '</strong> ke tujuan: <strong>' . $id . '</strong> (' . ceil($berat / 1000) . ' Kg)</p>' . $html;
                $html = '<div id="result_ekspedisi">' . $html . '<hr></div>';
                return \Response::json(['not_found' => false, 'html' => $html]);
            }
        }
    }