ci = &get_instance(); } public function get_all_product_list() { $path = "/product-list.json/list?lang=EN"; $product_list = $this->call_bokun($path, 'get'); return ($product_list); } public function get_product_list_detail($list_id) { $path = "/product-list.json/$list_id?currency=USD&lang=EN"; $product_list = $this->call_bokun($path, 'get'); return ($product_list); } public function get_activity_price($bokun_id) { $path = "/activity.json/$bokun_id/price-list?currency=USD"; $price_list = $this->call_bokun($path, 'get'); return ($price_list); } public function search_by_text($text) { $path = "/activity.json/search?currency=USD&lang=EN"; $request_body = array( "textFilter" => array( "operator" => "and", "searchExternalId" => true, "searchFullText" => false, "searchKeywords" => true, "searchTitle" => true, "text" => $text, "wildcard" => false ) ); $result = $this->call_bokun($path, 'post', json_encode($request_body, JSON_UNESCAPED_UNICODE)); return json_decode($result)->items; } private function make_bokun_signature($date, $method, $path) { $raw_str = $date . $this->access_key . strtoupper($method) . $path; return base64_encode(hash_hmac("sha1", $raw_str, $this->secret_key, TRUE)); } private function call_bokun($path, $method, $body = null) { $url = $this->bokun_url . $path; $create_date = gmdate("Y-m-d H:i:s"); $bokun_signature = $this->make_bokun_signature($create_date, $method, $path); $curl = curl_init(); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 20); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_URL, $url); $http_header = array( "X-Bokun-Date:" . $create_date, "X-Bokun-AccessKey :" . $this->access_key, "X-Bokun-Signature :" . $bokun_signature ); $set_post = strtoupper($method) === 'GET' ? false : true; curl_setopt($curl, CURLOPT_POST, $set_post); if ($body !== null) { curl_setopt($curl, CURLOPT_POSTFIELDS, $body); $http_header[] = 'Content-Type: application/json'; } curl_setopt($curl, CURLOPT_HTTPHEADER, $http_header); log_message('debug', 'call_bokun ' . $method . PHP_EOL . var_export($url, 1)); $output = curl_exec($curl); if (curl_errno($curl)) { log_message('error', "curl error code: " . curl_error($curl) . "; curl call: " . $path); } else { $httpStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if (200 !== $httpStatusCode) { log_message('error', "Request html Status Code: " . $httpStatusCode . "; curl call: " . $path); } } curl_close($curl); return $output; } } /* End of file Bokun_lib.php */