OneShopAPI.php
From Developer's API
(Difference between revisions)
Chrisn (Talk | contribs)
(New page: <pre> <?php # OneShopAPI: PHP wrapper class for 1ShoppingCart.com API # Author: 1ShoppingCart.com class OneShopAPI { var $_merchantId = ""; var $_merchantKey = ""; var $_apiUri = "";...)
Newer edit →
(New page: <pre> <?php # OneShopAPI: PHP wrapper class for 1ShoppingCart.com API # Author: 1ShoppingCart.com class OneShopAPI { var $_merchantId = ""; var $_merchantKey = ""; var $_apiUri = "";...)
Newer edit →
Revision as of 19:36, 26 May 2008
<?php # OneShopAPI: PHP wrapper class for 1ShoppingCart.com API # Author: 1ShoppingCart.com class OneShopAPI { var $_merchantId = ""; var $_merchantKey = ""; var $_apiUri = ""; var $_apiParameters; function OneShopAPI($merchantId, $merchantKey, $apiUri) { $this->_merchantId = $merchantId; $this->_merchantKey = $merchantKey; $this->_apiUri = $apiUri; } # BuildApiParameters Method Here # AddApiParameter Method Here # ClearApiParameters Method Here function SendHttpRequest($uri, $request_body) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_POSTFIELDS, $request_body); curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-POST_DATA_FORMAT: xml')); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); # TODO - SET THIS TO true FOR PRODUCTION curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_exec($ch); $err = curl_error($ch); if ($err) return $err; return $data; } function ApiRequest($path, $parameters = "") { $uri = $this->_apiUri."/API/".$this->_merchantId.$path; $request_body = $this->CreateRequestString(); $result = $this->SendHttpRequest($uri, $request_body); return($result); } function XLinkApiRequest($xlink, $parameters = "") { $request_body = $this->CreateRequestString(); $result = $this->SendHttpRequest($xlink, $request_body); return($result); } function CreateRequestString() { $request_body = "<Request><Key>".$this->_merchantKey."</Key>".$this->ParseApiParameters($this->_parameters)."</Request>"; return $request_body; } function ParseApiParameters($parameters) { $request_payload = ""; if ((!empty($parameters)) && (is_array($parameters))) { foreach($parameters as $key => $value) { if (!is_array($value)) { $request_payload .= ("<".$key.">".$value."</".$key.">\r\n"); } else { $request_payload .= "<".$key.">\r\n"; $request_payload .= $this->create_request($value); $request_payload .= "</".$key.">\r\n"; } } } return $request_payload; } #orders function GetOrdersList() { return($this->ApiRequest("/ORDERS/LIST")); } function GetOrderById($orderId) { return($this->ApiRequest("/ORDERS/" . $orderId . "/READ")); } #products function GetProductsList() { return($this->ApiRequest("/PRODUCTS/LIST")); } function GetProductById($productId) { return($this->ApiRequest("/PRODUCTS/" . $productId . "/READ")); } #CLIENTS function GetClientsList() { return($this->ApiRequest("/CLIENTS/LIST")); } function GetClientById($clientId) { return($this->ApiRequest("/CLIENTS/". $clientId ."/READ")); } function GetErrorsList() { return($this->ApiRequest("/ERRORS/LIST")); } function GetAvailableApiMethods() { return($this->ApiRequest("")); } } ?>