Advertisement
abidkhan484

Untitled

Jan 26th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. <?php
  2.  
  3. DEFINE('INEW_DATAMIXER_API_BASEURL', 'https://dev.skitto.com/inew_api/test/rest/');
  4.  
  5.  
  6. DEFINE('INEW_INT_HASH_KEY', '3D0FD055649155A8A8665D413B5AA133');
  7. DEFINE('REST_ACCESS_KEY', '1_clq8dg5qb4nu510high64b6eot');
  8. DEFINE('REQUEST_START', microtime(TRUE));
  9. $filename = "test.csv";
  10. global $log_file;
  11. $log_file = "log_file.txt";
  12. // $filename = "inactive_datamixer.csv";
  13.  
  14.  
  15.  
  16. function inew_datamixer_api_call($method, $URL, $data = NULL, $api_name = '') {
  17.  
  18. global $log_file;
  19.  
  20.  
  21. $api_call_status = '1';
  22. $ch = curl_init($URL);
  23. if (!empty($data)) {
  24. // $data=urldecode(http_build_query($data));
  25. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  26. }
  27. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  28. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  29. curl_setopt($ch, CURLOPT_TIMEOUT, '30');
  30. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  31. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  32. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'accessKey:' . REST_ACCESS_KEY, 'x-auth-api-key:' . INEW_INT_HASH_KEY));
  33. $result = curl_exec($ch);
  34. $inew_time = (microtime(TRUE) - REQUEST_START);
  35. if ($errno = curl_errno($ch)) {
  36. $result = json_encode(array('url' => $URL, 'request' => $data, 'method' => $method, 'response' => $errno . ':' . curl_error($ch)));
  37. // $this->inew_log($result);
  38. $api_call_status = '0';
  39. }
  40.  
  41. curl_close($ch);
  42. // $this->inew_log(json_encode(array('url' => $URL, 'request' => $data, 'method' => $method, 'response' => $result)));
  43.  
  44. if (!empty($api_name)) {
  45. /* Logging api access */
  46. $log = array(
  47. 'api_name' => !empty($api_name) ? $api_name : '',
  48. 'status' => $api_call_status,
  49. 'inew_time' => $inew_time
  50. );
  51. $file = fopen($log_file,"a+");
  52. fwrite($file,implode("|",$log).PHP_EOL);
  53. fclose($file);
  54. // write_api_access($log);
  55. /* Loggin end *//* Logging api access */
  56. }
  57.  
  58. return $result;
  59. }
  60.  
  61. function deactivate_auto_renew($subscriber_id, $tarrif_id) {
  62. $URL = INEW_DATAMIXER_API_BASEURL . "subscriptions/$subscriber_id/activePlan/$tarrif_id/deactivate";
  63. $inew_resp = inew_datamixer_api_call("PUT", $URL, '', 'deactiveAutoRenew');
  64. $resp = json_decode($inew_resp);
  65. if ($resp->responseCode == 0)
  66. return true;
  67. return false;
  68. }
  69.  
  70.  
  71. // $csv = array_map('str_getcsv', file($filename));
  72.  
  73. deactivate_auto_renew($subscriber_id, $tarrif_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement