Example #1
0
 /**
  * Actually perform API Call and return result
  * @param string $endpoint
  * @param array $post_array
  * @throws CRError
  * @return mixed "response" portion Response as array or TRUE if successful but no "response" portion.
  */
 protected static function make_api_call($api_user, $api_key, $endpoint, $post_array = null, $get_array = array())
 {
     $url = APIObject::$api_base . APIObject::$api_version . $endpoint . '?' . http_build_query(array_merge(array('api_user' => $api_user, 'api_key' => $api_key), $get_array));
     $header = array('User-Agent: CartRover PhpClient/' . APIObject::$api_version, 'Content-type: application/json');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     if ($post_array) {
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_array));
     }
     $responseBody = curl_exec($ch);
     $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($responseBody === false) {
         $errno = curl_errno($ch);
         $error = curl_error($ch);
         curl_close($ch);
         APIObject::curlError($errno, $error);
     }
     curl_close($ch);
     $jsonPayload = json_decode($responseBody, true);
     // Catch error or invalid response
     if (empty($jsonPayload) || empty($jsonPayload['success_code']) || $http_status > 400) {
         throw new CRError($jsonPayload['message'], $http_status, $responseBody);
     }
     return !empty($jsonPayload['response']) ? $jsonPayload['response'] : true;
 }
 /**
  * [__construct description]
  * @param [type] $http [description]
  */
 public function __construct($http)
 {
     parent::__construct($http);
 }
Example #3
0
 /**
  * Return a specific product
  * @param string $api_user
  * @param string $api_key
  * @param string $sku Product to lookup
  * @return array
  */
 public static function GetProdInventory($api_user, $api_key, $sku)
 {
     $endpoint = '/merchant/inventory/' . $sku;
     return APIObject::make_api_call($api_user, $api_key, $endpoint);
 }
Example #4
0
 /**
  * Return a list of all ship methods setup for this WMS
  * @param string $api_user
  * @param string $api_key
  * @return array
  */
 public static function ListShipMethods($api_user, $api_key)
 {
     $endpoint = '/wms/shipmethod/list';
     return APIObject::make_api_call($api_user, $api_key, $endpoint);
 }
Example #5
0
 /**
  * Add or update the given list of ship methods.
  * @param string $api_user
  * @param string $api_key
  * @param string $order_source
  * @param array $cart_codes_array
  * @return array
  */
 public static function UpdateShipMethods($api_user, $api_key, $order_source, $cart_codes_array)
 {
     $endpoint = '/cart/shipmethod/' . $order_source;
     return APIObject::make_api_call($api_user, $api_key, $endpoint, $cart_codes_array);
 }
Example #6
0
 /**
  * View an order in CartRover.
  * @param string $api_user
  * @param string $api_key
  * @param array $cust_ref cust_ref of order to view
  * @return array
  */
 public static function ViewOrder($api_user, $api_key, $cust_ref)
 {
     $endpoint = '/merchant/orders/' . $cust_ref;
     return APIObject::make_api_call($api_user, $api_key, $endpoint);
 }