Advertisement
Guest User

MASA GET STOCK K1

a guest
Feb 27th, 2020
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. /**
  2. * Get Masa Deposit.
  3. */
  4. function kraken_stock_get_masa() {
  5. $output = '';
  6. module_load_include('inc', 'masa');
  7. $masa_deposit = masa_get_deposit();
  8. if ($masa_deposit === NULL) {
  9. $response = 'Deposit Info Not Found';
  10. }
  11. else {
  12. $response = number_format($masa_deposit);
  13. }
  14.  
  15. $output .= "<h4>Deposit: " . $response . '</h4>';
  16. return $output;
  17. }
  18.  
  19. function masa_get_deposit() {
  20. $sub_module = 'masa_pdam';
  21. $params = array(
  22. 'command' => 'SAL',
  23. 'modul' => 'DEP',
  24. );
  25. $response = NULL;
  26. $balance = NULL;
  27. $api = masa_api($params, $sub_module);
  28. $response = json_decode(json_encode(@simplexml_load_string($api->data)), TRUE);
  29.  
  30. if (!empty($response)) {
  31. $balance = $response['balance'];
  32. }
  33.  
  34. return $balance;
  35. }
  36.  
  37. function masa_api($params, $sub_module, $settings = NULL, $pid = NULL) {
  38. // Get settings credentials.
  39. if (empty($settings)) {
  40. $settings = variable_get('masa_settings');
  41. }
  42.  
  43. // Join params.
  44. $query = array(
  45. 'cid' => $settings['client_id'],
  46. 'dt' => date("Ymd"),
  47. );
  48. $query['hc'] = hash('SHA256', $query['cid'] . $query['dt'] . $settings['secret_key']);
  49. $query = array_merge($query + $params);
  50. $query['resp'] = 'XML';
  51.  
  52. // Save for log.
  53. $log_query = $query;
  54.  
  55. // Build URL.
  56. $query = drupal_http_build_query($query);
  57. $url = $settings['endpoint'];
  58. $url .= '?' . $query;
  59.  
  60. // Options.
  61. $options['timeout'] = $settings['timeout'];
  62. $options['context'] = stream_context_create(array(
  63. 'ssl' => array(
  64. 'verify_peer' => FALSE,
  65. 'verify_peer_name' => FALSE,
  66. ),
  67. ));
  68.  
  69. if ($settings[$sub_module]['production']) {
  70. $response = drupal_http_request($url, $options);
  71. }
  72. else {
  73. // Mock file must follow this pattern
  74. // [masa_pln_postpaid].mock.inc
  75. // and have [masa_pln_postpaid]_mock function.
  76. $mock_file = $sub_module . '.mock';
  77. module_load_include('inc', $sub_module, $mock_file);
  78. $func = $sub_module . '_mock_api';
  79. $response = $func($params);
  80. }
  81.  
  82. // Logging response message on debug mode.
  83. if ($settings[$sub_module]['debug']) {
  84. $link = $log_query['command'];
  85. if (!empty($pid)) {
  86. $link = $log_query['command'] . ':' . $pid;
  87. }
  88.  
  89. watchdog($sub_module, "<pre>Request : \n!query\n\nResponse : \n@data</pre>",
  90. array(
  91. '!query' => print_r($log_query, TRUE),
  92. '@data' => print_r($response, TRUE),
  93. ), WATCHDOG_DEBUG, $link);
  94. }
  95.  
  96. return $response;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement