Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Get Masa Deposit.
- */
- function kraken_stock_get_masa() {
- $output = '';
- module_load_include('inc', 'masa');
- $masa_deposit = masa_get_deposit();
- if ($masa_deposit === NULL) {
- $response = 'Deposit Info Not Found';
- }
- else {
- $response = number_format($masa_deposit);
- }
- $output .= "<h4>Deposit: " . $response . '</h4>';
- return $output;
- }
- function masa_get_deposit() {
- $sub_module = 'masa_pdam';
- $params = array(
- 'command' => 'SAL',
- 'modul' => 'DEP',
- );
- $response = NULL;
- $balance = NULL;
- $api = masa_api($params, $sub_module);
- $response = json_decode(json_encode(@simplexml_load_string($api->data)), TRUE);
- if (!empty($response)) {
- $balance = $response['balance'];
- }
- return $balance;
- }
- function masa_api($params, $sub_module, $settings = NULL, $pid = NULL) {
- // Get settings credentials.
- if (empty($settings)) {
- $settings = variable_get('masa_settings');
- }
- // Join params.
- $query = array(
- 'cid' => $settings['client_id'],
- 'dt' => date("Ymd"),
- );
- $query['hc'] = hash('SHA256', $query['cid'] . $query['dt'] . $settings['secret_key']);
- $query = array_merge($query + $params);
- $query['resp'] = 'XML';
- // Save for log.
- $log_query = $query;
- // Build URL.
- $query = drupal_http_build_query($query);
- $url = $settings['endpoint'];
- $url .= '?' . $query;
- // Options.
- $options['timeout'] = $settings['timeout'];
- $options['context'] = stream_context_create(array(
- 'ssl' => array(
- 'verify_peer' => FALSE,
- 'verify_peer_name' => FALSE,
- ),
- ));
- if ($settings[$sub_module]['production']) {
- $response = drupal_http_request($url, $options);
- }
- else {
- // Mock file must follow this pattern
- // [masa_pln_postpaid].mock.inc
- // and have [masa_pln_postpaid]_mock function.
- $mock_file = $sub_module . '.mock';
- module_load_include('inc', $sub_module, $mock_file);
- $func = $sub_module . '_mock_api';
- $response = $func($params);
- }
- // Logging response message on debug mode.
- if ($settings[$sub_module]['debug']) {
- $link = $log_query['command'];
- if (!empty($pid)) {
- $link = $log_query['command'] . ':' . $pid;
- }
- watchdog($sub_module, "<pre>Request : \n!query\n\nResponse : \n@data</pre>",
- array(
- '!query' => print_r($log_query, TRUE),
- '@data' => print_r($response, TRUE),
- ), WATCHDOG_DEBUG, $link);
- }
- return $response;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement