WCB_API

The WooCommerce Billogram Integration WCB API class.

Defined (1)

The class is defined in the following location(s).

/class-billogram2-api.php  
  1. class WCB_API{ 
  2.  
  3. /** @public String base URL */ 
  4. public $api_url; 
  5.  
  6. /** @public String base URL */ 
  7. public $billogram_mode; 
  8.  
  9. /** @public Client Secret token */ 
  10. public $client_secret = 'AQV9TbDU1k'; 
  11.  
  12. /** @public String Authorization code */ 
  13. public $authorization_code; 
  14.  
  15. /** @public String Access token */ 
  16. public $access_token; 
  17.  
  18. /** @public String api key */ 
  19. public $api_key; 
  20.  
  21. /** @public String license key */ 
  22. public $license_key; 
  23.  
  24. /** @public String local key data */ 
  25. public $localkeydata; 
  26.  
  27. /** 
  28. */ 
  29. function __construct() { 
  30.  
  31. $options = get_option('woocommerce_billogram_general_settings'); 
  32. $localkeydata = get_option('local_key_billogram_plugin'); 
  33. //$this->api_url = "https://api.billogram.se/3/"; 
  34. if($options['billogram-mode']=='Sandbox') 
  35. $this->api_url = "https://sandbox.billogram.com/api/v2"; 
  36. else 
  37. $this->api_url = "https://billogram.com/api/v2"; 
  38.  
  39. $this->authorization_code = $options['authorization_code']; 
  40. $this->license_key = $options['license-key']; 
  41. $this->api_key = $options['api-key']; 
  42. $this->billogram_mode = $options['billogram-mode']; 
  43. $this->access_token = get_option('billogram_access_token'); 
  44. $this->localkeydata = $localkeydata; 
  45. if(!$this->access_token) { 
  46. $this->login(); 
  47.  
  48. /** 
  49. * Builds url 
  50. * @access public 
  51. * @param mixed $urlAppendix 
  52. * @return string 
  53. */ 
  54. private function build_url($urlAppendix) { 
  55. //return $this->api_url.'/'.$urlAppendix; 
  56. return $urlAppendix; 
  57.  
  58. /** 
  59. * Creates a HttpRequest and appends the given XML to the request and sends it to Billogram 
  60. * @access public 
  61. * @return bool 
  62. */ 
  63. public function create_api_validation_request() { 
  64. return true; 
  65. //logthis("LISCENSE VALIDATION"); 
  66. if(!isset($this->license_key)) { 
  67. return false; 
  68.  
  69. $apiUsername = $this->api_key; 
  70. $apiPassword = $this->authorization_code; 
  71. $identifier = 'Bilogram API Customer'; 
  72. $apiBaseUrl = $this->api_url; 
  73. $api = new BillogramAPI($apiUsername, $apiPassword, $identifier, $apiBaseUrl); 
  74.  
  75. if($api) { 
  76. return true; 
  77. return false; 
  78.  
  79. /** 
  80. * Creates a HttpRequest and appends the given XML to the request and sends it For license key 
  81. * @access public 
  82. * @return bool 
  83. */ 
  84. public function create_license_validation_request($localkey='') { 
  85. //logthis("LISCENSE VALIDATION"); 
  86. if(!isset($this->license_key)) { 
  87. return false; 
  88. $licensekey = $this->license_key; 
  89. // ----------------------------------- 
  90. // -- Configuration Values -- 
  91. // ----------------------------------- 
  92. // Enter the url to your WHMCS installation here 
  93. $whmcsurl = 'http://whmcs.onlineforce.net/'; 
  94. //$whmcsurl = 'http://139.59.25.189/whmcs/'; 
  95. // Must match what is specified in the MD5 Hash Verification field 
  96. // of the licensing product that will be used with this check. 
  97. $licensing_secret_key = 'ak4762'; 
  98. //$licensing_secret_key = 'itservice'; 
  99. // The number of days to wait between performing remote license checks 
  100. $localkeydays = 15; 
  101. // The number of days to allow failover for after local key expiry 
  102. $allowcheckfaildays = 5; 
  103.  
  104. // ----------------------------------- 
  105. // -- Do not edit below this line -- 
  106. // ----------------------------------- 
  107.  
  108. $check_token = time() . md5(mt_rand(1000000000, 9999999999) . $licensekey); 
  109. $checkdate = date("Ymd"); 
  110. $domain = $_SERVER['SERVER_NAME']; 
  111. $usersip = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']; 
  112. $dirpath = dirname(__FILE__); 
  113. $verifyfilepath = 'modules/servers/licensing/verify.php'; 
  114. $localkeyvalid = false; 
  115. if ($localkey) { 
  116. $localkey = str_replace("\n", '', $localkey); # Remove the line breaks 
  117. $localdata = substr($localkey, 0, strlen($localkey) - 32); # Extract License Data 
  118. $md5hash = substr($localkey, strlen($localkey) - 32); # Extract MD5 Hash 
  119. if ($md5hash == md5($localdata . $licensing_secret_key)) { 
  120. $localdata = strrev($localdata); # Reverse the string 
  121. $md5hash = substr($localdata, 0, 32); # Extract MD5 Hash 
  122. $localdata = substr($localdata, 32); # Extract License Data 
  123. $localdata = base64_decode($localdata); 
  124. $localkeyresults = unserialize($localdata); 
  125. $originalcheckdate = $localkeyresults['checkdate']; 
  126. if ($md5hash == md5($originalcheckdate . $licensing_secret_key)) { 
  127. $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - $localkeydays, date("Y"))); 
  128. if ($originalcheckdate > $localexpiry) { 
  129. $localkeyvalid = true; 
  130. $results = $localkeyresults; 
  131. $validdomains = explode(', ', $results['validdomain']); 
  132. if (!in_array($_SERVER['SERVER_NAME'], $validdomains)) { 
  133. $localkeyvalid = false; 
  134. $localkeyresults['status'] = "Invalid"; 
  135. $results = array(); 
  136. $validips = explode(', ', $results['validip']); 
  137. if (!in_array($usersip, $validips)) { 
  138. $localkeyvalid = false; 
  139. $localkeyresults['status'] = "Invalid"; 
  140. $results = array(); 
  141. $validdirs = explode(', ', $results['validdirectory']); 
  142. if (!in_array($dirpath, $validdirs)) { 
  143. $localkeyvalid = false; 
  144. $localkeyresults['status'] = "Invalid"; 
  145. $results = array(); 
  146. if (!$localkeyvalid) { 
  147. $postfields = array( 
  148. 'licensekey' => $licensekey,  
  149. 'domain' => $domain,  
  150. 'ip' => $usersip,  
  151. 'dir' => $dirpath,  
  152. ); 
  153. if ($check_token) $postfields['check_token'] = $check_token; 
  154. $query_string = ''; 
  155. foreach ($postfields AS $k=>$v) { 
  156. $query_string .= $k.'='.urlencode($v).'&'; 
  157. if (function_exists('curl_exec')) { 
  158. $ch = curl_init(); 
  159. curl_setopt($ch, CURLOPT_URL, $whmcsurl . $verifyfilepath); 
  160. curl_setopt($ch, CURLOPT_POST, 1); 
  161. curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); 
  162. curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
  163. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  164. $data = curl_exec($ch); 
  165. curl_close($ch); 
  166. } else { 
  167. $fp = fsockopen($whmcsurl, 80, $errno, $errstr, 5); 
  168. if ($fp) { 
  169. $newlinefeed = "\r\n"; 
  170. $header = "POST ".$whmcsurl . $verifyfilepath . " HTTP/1.0" . $newlinefeed; 
  171. $header .= "Host: ".$whmcsurl . $newlinefeed; 
  172. $header .= "Content-type: application/x-www-form-urlencoded" . $newlinefeed; 
  173. $header .= "Content-length: ".@strlen($query_string) . $newlinefeed; 
  174. $header .= "Connection: close" . $newlinefeed . $newlinefeed; 
  175. $header .= $query_string; 
  176. $data = ''; 
  177. @stream_set_timeout($fp, 20); 
  178. @fputs($fp, $header); 
  179. $status = @socket_get_status($fp); 
  180. while (!@feof($fp)&&$status) { 
  181. $data .= @fgets($fp, 1024); 
  182. $status = @socket_get_status($fp); 
  183. @fclose ($fp); 
  184. if (!$data) { 
  185. $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - ($localkeydays + $allowcheckfaildays), date("Y"))); 
  186. if ($originalcheckdate > $localexpiry) { 
  187. $results = $localkeyresults; 
  188. } else { 
  189. $results = array(); 
  190. $results['status'] = "Invalid"; 
  191. $results['description'] = "Remote Check Failed"; 
  192. return $results; 
  193. } else { 
  194. preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $matches); 
  195. $results = array(); 
  196. foreach ($matches[1] AS $k=>$v) { 
  197. $results[$v] = $matches[2][$k]; 
  198. if (!is_array($results)) { 
  199. die("Invalid License Server Response"); 
  200. if (isset($results['md5hash'])) { 
  201. if ($results['md5hash'] != md5($licensing_secret_key . $check_token)) { 
  202. $results['status'] = "Invalid"; 
  203. $results['description'] = "MD5 Checksum Verification Failed"; 
  204. return $results; 
  205. if ($results['status'] == "Active") { 
  206. $results['checkdate'] = $checkdate; 
  207. $data_encoded = serialize($results); 
  208. $data_encoded = base64_encode($data_encoded); 
  209. $data_encoded = md5($checkdate . $licensing_secret_key) . $data_encoded; 
  210. $data_encoded = strrev($data_encoded); 
  211. $data_encoded = $data_encoded . md5($data_encoded . $licensing_secret_key); 
  212. $data_encoded = wordwrap($data_encoded, 80, "\n", true); 
  213. $results['localkey'] = $data_encoded; 
  214. $results['remotecheck'] = true; 
  215. unset($postfields, $data, $matches, $whmcsurl, $licensing_secret_key, $checkdate, $usersip, $localkeydays, $allowcheckfaildays, $md5hash); 
  216. return $results; 
  217. //return true; 
  218.  
  219. /** 
  220. * Creates a HttpRequest for creation of an invoice and appends the given XML to the request and sends it to Billogram 
  221. * @access public 
  222. * @param mixed $xml 
  223. * @return bool 
  224. *//** 
  225. public function create_invoice_request($xml) { 
  226.   
  227. return $this->make_post_request($this->build_url("invoices"), $xml); 
  228. */ 
  229. /** 
  230. * Creates a HttpRequest for setting an invoice with given id as bookkeot and sends it to Billogram 
  231. * @access public 
  232. * @param mixed $id 
  233. * @return bool 
  234. *//** 
  235. public function create_invoice_bookkept_request($id) { 
  236. logthis("SET INVOICE AS BOOKKEPT REQUEST"); 
  237. return $this->make_put_request($this->build_url("invoices/". $id . "/bookkeep")); 
  238. */ 
  239. /** 
  240. * Creates a HttpRequest creation of an order and appends the given XML to the request and sends it to Billogram 
  241. * @access public 
  242. * @param mixed $xml 
  243. * @return bool 
  244. */ 
  245. public function create_order_request($xml) { 
  246. logthis("CREATE ORDER REQUEST"); 
  247. //return $this->make_post_request($this->build_url("orders"), $xml); 
  248. return $this->make_post_request("billogram", $xml); 
  249.  
  250. /** 
  251. * Creates a HttpRequest updating an order and appends the given XML to the request and sends it to Billogram 
  252. * @access public 
  253. * @param mixed $xml 
  254. * @param int $orderId 
  255. * @return bool 
  256. */ 
  257. public function update_order_request($xml, $orderId) { 
  258. logthis("UPDATE ORDER REQUEST"); 
  259. return $this->make_put_request($this->build_url("orders/". $orderId), $xml); 
  260.  
  261. /** 
  262. * Creates a HttpRequest creation of an orderinvoice and appends the given XML to the request and sends it to Billogram 
  263. * @access public 
  264. * @param mixed $documentNumber 
  265. * @return bool 
  266. */ 
  267. public function create_order_invoice_request($documentNumber, $InvoiceSendMethod) { 
  268. logthis("CREATE INVOICE REQUEST"); 
  269. return $this->make_put_request($this->build_url("billogram/invoice"), $documentNumber, $InvoiceSendMethod); 
  270.  
  271. /** 
  272. * Creates a HttpRequest Credit of an Invoice 
  273. * @access public 
  274. * @param mixed $invoice_id 
  275. * @return bool 
  276. */ 
  277. public function create_credit_invoice_request($invoice_id, $amount) { 
  278. logthis("CREDIT INVOICE REQUEST"); 
  279. return $this->make_credit_invoice($invoice_id, $amount); 
  280.  
  281. /** 
  282. * Creates the HttpRequest creation of a contact/customer and appends the given XML to the request and sends it to Billogram 
  283. * @access public 
  284. * @param mixed $xml 
  285. * @return bool 
  286. */ 
  287. public function create_customer_request($xml) { 
  288. logthis("CREATE CONTACT PRICE REQUEST"); 
  289. //return $this->make_post_request($this->build_url("customers"), $xml); 
  290. return $this->make_post_request("customers", $xml); 
  291.  
  292. /** 
  293. * Creates a HttpRequest for creation of a product and appends the given XML to the request and sends it to Billogram 
  294. * @access public 
  295. * @param mixed $xml 
  296. * @return bool 
  297. */ 
  298. public function create_product_request($xml) { 
  299. logthis("CREATE PRODUCT REQUEST"); 
  300. return $this->make_post_request("items", $xml); 
  301.  
  302. /** 
  303. * Creates a HttpRequest for creation of product(for given sku) 
  304. * price and appends the given XML to the request and sends it to Billogram 
  305. * @access public 
  306. * @param mixed $xml 
  307. * @return bool 
  308. */ 
  309. public function create_product_price_request($xml) { 
  310. logthis("CREATE PRODUCT PRICE REQUEST"); 
  311. return $this->make_post_request($this->build_url("prices/"), $xml); 
  312.  
  313. /** 
  314. * Creates a HttpRequest for fetching all customer and appends the given XML to the request and sends it to Billogram 
  315. * @access public 
  316. * @return bool 
  317. */ 
  318. public function get_customers() { 
  319. logthis("GET CUSTOMER REQUEST"); 
  320. //return $this->make_get_request($this->build_url("customers")); 
  321. return $this->make_get_request("customers"); 
  322.  
  323.  
  324. /** 
  325. * Creates a HttpRequest for fetching all customerand appends the given XML to the request and sends it to Billogram 
  326. * @access public 
  327. * @return bool 
  328. */ 
  329. public function get_inventory() { 
  330. logthis("GET INVENTORY REQUEST"); 
  331. return $this->make_get_request($this->build_url("articles")); 
  332.  
  333. /** 
  334. * Creates a HttpRequest for fetching invoice data using ID 
  335. * @access public 
  336. * @return bool 
  337. */ 
  338. public function get_invoice($billogramID) { 
  339. logthis("GET INVOICE DATA"); 
  340. return $this->make_get_invoice($billogramID); 
  341.  
  342. /** 
  343. * Creates a HttpRequest and appends the given XML to the request and sends it to Billogram 
  344. * @access public 
  345. * @return bool 
  346. */ 
  347. public function login() { 
  348.  
  349. if(!$this->localkeydata) { 
  350. return false; 
  351.  
  352. //logthis("LOGIN"); 
  353. //logthis($this->authorization_code); 
  354. //logthis($this->client_secret); 
  355. $headers = array( 
  356. 'Accept: application/xml',  
  357. 'Authorization-Code: '.$this->authorization_code,  
  358. 'Client-Secret: '.$this->client_secret,  
  359. 'Content-Type: application/xml',  
  360. ); 
  361. $ch = curl_init(); 
  362. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
  363. curl_setopt ($ch, CURLOPT_URL, $this->api_url); 
  364. curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
  365. curl_setopt ($ch, CURLOPT_VERBOSE, 0); 
  366. curl_setopt ($ch, CURLOPT_POST, 0); 
  367. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
  368. curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 
  369. curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 
  370.  
  371. $data = curl_exec($ch); 
  372. $arrayData = json_decode(json_encode(simplexml_load_string($data)), true); 
  373. $this->access_token = $arrayData['AccessToken']; 
  374. if($this->access_token) { 
  375. update_option( 'billogram_access_token', $this->access_token, '', 'yes' ); 
  376. //logthis(print_r($arrayData, true)); 
  377. curl_close($ch); 
  378. return false; 
  379.  
  380. /** 
  381. * Makes GET request 
  382. * @access private 
  383. * @param mixed $url 
  384. * @return string 
  385. */ 
  386. private function make_get_request($url) { 
  387.  
  388. if(!$this->localkeydata) { 
  389. return false; 
  390.  
  391. $apiUsername = $this->api_key; 
  392. $apiPassword = $this->authorization_code; 
  393. $identifier = 'Bilogram API Customer'; 
  394. $apiBaseUrl = $this->api_url; 
  395. $api = new BillogramAPI($apiUsername, $apiPassword, $identifier, $apiBaseUrl); 
  396. $customersQuery = $api->$url->query()->order( 
  397. 'created_at',  
  398. 'asc' 
  399. ); 
  400. $totalPages = $customersQuery->totalPages(); 
  401. for ($page = 1; $page <= $totalPages; $page++) { 
  402. $customersArray = $customersQuery->getPage($page); 
  403. /** Loop over the customersArray and do something with the customers here. */ 
  404. error_log(print_r($customersArray, true)); 
  405.  
  406. //Send error to plugapi 
  407. if (array_key_exists("Error", $customersArray)) { 
  408. error_log("BILLOGRAM ERROR"); 
  409. $this->post_error($customersArray['Message']); 
  410. return $customersArray; 
  411.  
  412. /** 
  413. * Makes GET request to fetch billogram 
  414. * @access private 
  415. * @param mixed $url 
  416. * @return string 
  417. */ 
  418. private function make_get_invoice($billogramID) { 
  419.  
  420. if(!$this->localkeydata) { 
  421. return false; 
  422.  
  423. $apiUsername = $this->api_key; 
  424. $apiPassword = $this->authorization_code; 
  425. $identifier = 'Bilogram API Customer'; 
  426. $apiBaseUrl = $this->api_url; 
  427. $api = new BillogramAPI($apiUsername, $apiPassword, $identifier, $apiBaseUrl); 
  428. $billogram = $api->billogram->get($billogramID); 
  429.  
  430.  
  431. //Send error to plugapi 
  432. if (array_key_exists("Error", $billogram)) { 
  433. logthis("BILLOGRAM ERROR"); 
  434. return $billogram; 
  435.  
  436. /** 
  437. * Makes GET request to fetch billogram 
  438. * @access private 
  439. * @param mixed $url 
  440. * @return string 
  441. */ 
  442. private function make_credit_invoice($billogramID, $amount) { 
  443.  
  444. if(!$this->localkeydata) { 
  445. return false; 
  446.  
  447. $apiUsername = $this->api_key; 
  448. $apiPassword = $this->authorization_code; 
  449. $identifier = 'Bilogram API Credit'; 
  450. $apiBaseUrl = $this->api_url; 
  451. $api = new BillogramAPI($apiUsername, $apiPassword, $identifier, $apiBaseUrl); 
  452. $billogramObject = $api->billogram->get($billogramID); 
  453. $billogramObject->creditAmount($amount); 
  454.  
  455.  
  456. //Send error to plugapi 
  457. if (array_key_exists("Error", $billogram)) { 
  458. logthis("BILLOGRAM ERROR"); 
  459. return $billogramObject; 
  460.  
  461. /** 
  462. * Makes POST request 
  463. * @access private 
  464. * @param mixed $url 
  465. * @param mixed $xml 
  466. * @return string 
  467. */ 
  468. private function make_post_request($url, $xml) { 
  469.  
  470. if(!$this->localkeydata) { 
  471. return false; 
  472. /**$options = get_option('woocommerce_billogram_general_settings');*/ 
  473. $apiUsername = $this->api_key; 
  474. $apiPassword = $this->authorization_code; 
  475. $identifier = 'Bilogram API Create'; 
  476. $apiBaseUrl = $this->api_url; 
  477. $api = new BillogramAPI($apiUsername, $apiPassword, $identifier, $apiBaseUrl); 
  478.  
  479. //logthis("XML:".print_r($xml, true)); 
  480. //logthis($api); 
  481. $arrayData = $api->$url->create($xml); 
  482. //logthis($arrayData); 
  483. /**if($options['activate-orders']=='Skicka faktura') 
  484. $arrayData->send('Email'); 
  485. }*/ 
  486. //$arrayData->send('Email'); 
  487. //logthis("Billogram:".print_r($arrayData, true)); 
  488.  
  489. //Send error to plugapi 
  490. if (array_key_exists("Error", $arrayData)) { 
  491. logthis("BILLOGRAM ERROR"); 
  492. $this->post_error($arrayData['Message']); 
  493.  
  494. return $arrayData; 
  495.  
  496. /** 
  497. * Makes PUT request 
  498. * @access private 
  499. * @param mixed $url 
  500. * @param mixed $xml 
  501. * @param string $InvoiceSendMethod 
  502. * @return string 
  503. */ 
  504. private function make_put_request($url, $xml = NULL, $InvoiceSendMethod = NULL) { 
  505.  
  506. if(!$this->localkeydata) { 
  507. return false; 
  508.  
  509. $url = explode("/", $url); 
  510. $apiUsername = $this->api_key; 
  511. $apiPassword = $this->authorization_code; 
  512. $identifier = 'Bilogram API Update Customer'; 
  513. $apiBaseUrl = $this->api_url; 
  514. $api = new BillogramAPI($apiUsername, $apiPassword, $identifier, $apiBaseUrl); 
  515. $options = get_option('woocommerce_billogram_general_settings'); 
  516.  
  517. if($url[0]=="billogram") 
  518. if($InvoiceSendMethod == 'email') { 
  519. logthis('------------Skapa faktura och skicka som epost-------------'); 
  520. $xml->send('Email'); 
  521. $array_data = 'true'; 
  522. elseif($InvoiceSendMethod == 'letter') { 
  523. logthis('------------Skapa faktura och skicka som brev-------------'); 
  524. $xml->send('Letter'); 
  525. $array_data = 'true'; 
  526. elseif ($InvoiceSendMethod == 'email+letter') { 
  527. logthis('------------Skapa fakturor och skicka som e-post och brev-------------'); 
  528. $xml->send('Email+Letter'); 
  529. $array_data = 'true'; 
  530. else if($url[0]=="items") 
  531.  
  532. do { 
  533. $array_data = ''; 
  534. $e = ''; 
  535. try { 
  536. $array_data = $api->$url[0]->get($url[1]); 
  537. break; 
  538. } catch (ObjectNotFoundError $e) { // PDF has not been created yet. 
  539. break; 
  540. } while (true); 
  541.  
  542. if($e) 
  543. $array_data = $this->make_post_request('items', $xml); 
  544. else 
  545. $array_data->update($xml); 
  546.  
  547. else 
  548. $array_data = $api->$url[0]->get($url[1]); 
  549. $array_data->update($xml); 
  550. //logthis(print_r($array_data, true)); 
  551.  
  552. //Send error to plugapi 
  553. if (array_key_exists("Error", $array_data)) { 
  554. logthis("BILLOGRAM ERROR"); 
  555. $this->post_error($array_data['Message']); 
  556.  
  557. return $array_data; 
  558.  
  559. /** 
  560. * Makes GET request 
  561. * @access private 
  562. * @param mixed $url 
  563. * @return array 
  564. */ 
  565. private function fetch_settings_request($url) { 
  566.  
  567. if(!$this->localkeydata) { 
  568. return false; 
  569.  
  570. $identifier = 'Bilogram API Settings'; 
  571. $settingsURL = $this->api_url.'/'.$url; 
  572.  
  573. logthis($this->api_key); 
  574. logthis($this->authorization_code); 
  575. $auth = base64_encode($this->api_key . ":" . $this->authorization_code); 
  576. logthis($auth); 
  577.  
  578. $headers = array( 
  579. 'Authorization: Basic ' . $auth,  
  580. 'Content-Type: application/json',  
  581. ); 
  582. $ch = curl_init(); 
  583. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
  584. curl_setopt ($ch, CURLOPT_URL, $settingsURL); 
  585. curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
  586. curl_setopt ($ch, CURLOPT_VERBOSE, 0); 
  587. curl_setopt ($ch, CURLOPT_POST, 0); 
  588. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
  589. curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 
  590. curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 
  591.  
  592. $data = curl_exec($ch); 
  593. $settings = json_decode($data, true); 
  594. return $settings; 
  595.  
  596. /** 
  597. * Creates a HttpRequest for an update of a customer and appends the given XML to the request and sends it to Billogram 
  598. * @access public 
  599. * @param mixed $xml 
  600. * @param mixed $customerNumber 
  601. * @return bool 
  602. */ 
  603. public function update_customer_request($xml, $customerNumber) { 
  604. logthis("UPDATE CUSTOMER REQUEST"); 
  605. //return $this->make_put_request($this->build_url("customers/" . $customerNumber), $xml); 
  606. return $this->make_put_request($this->build_url("customers/" . $customerNumber), $xml); 
  607.  
  608. /** 
  609. * Creates a HttpRequest for an update of a product and appends the given XML to the request and sends it to Billogram 
  610. * @access public 
  611. * @param mixed $xml 
  612. * @param mixed $sku 
  613. * @return bool 
  614. */ 
  615. public function update_product_request($xml, $sku) { 
  616. logthis("UPDATE PRODUCT REQUEST"); 
  617. return $this->make_put_request($this->build_url("items/" . $sku), $xml); 
  618.  
  619. /** 
  620. * Creates a HttpRequest for an update of product(for given sku) 
  621. * price and appends the given XML to the request and sends it to Billogram 
  622. * @access public 
  623. * @param mixed $xml 
  624. * @param mixed $sku 
  625. * @return bool 
  626. */ 
  627. public function update_product_price_request($xml, $sku) { 
  628. logthis("UPDATE PRICE REQUEST"); 
  629. return $this->make_put_request($this->build_url("prices/A/" . $sku . "/0"), $xml); 
  630.  
  631.  
  632. /** 
  633. * Fetches BillogramAPI settings containing Company name to validate the Billogram API account. 
  634. * @access public 
  635. * @return sting (settings company name) 
  636. */ 
  637. public function fetch_settings() { 
  638. logthis("FETCHING SETTINGS"); 
  639. return $this->fetch_settings_request("settings"); 
  640.  
  641.  
  642. private function post_error($message) { 
  643. if(!$this->localkeydata) { 
  644. return false; 
  645.  
  646. $fields = array( 
  647. 'license_key' => $this->license_key,  
  648. 'message' => $message,  
  649. ); 
  650.  
  651. $ch = curl_init(); 
  652. $url = "http://plugapi.consuasor.se/api_post.php"; 
  653. curl_setopt ($ch, CURLOPT_URL, $url); 
  654. curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
  655. curl_setopt ($ch, CURLOPT_VERBOSE, 0); 
  656. curl_setopt ($ch, CURLOPT_POST, 1); 
  657. curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields); 
  658. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
  659. curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 
  660. curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 
  661.  
  662. $data = curl_exec($ch); 
  663. curl_close($ch); 
  664. logthis($data);