index.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. require_once('../../libs/api.compat.php');
  3. require_once('../../libs/api.astral.php');
  4. require_once('../../libs/api.ubrouting.php');
  5. $cfgPltn = parse_ini_file('config/platon.ini');
  6. $merchant_name = $cfgPltn['MERCHANT_NAME'];
  7. $merchant_url = $cfgPltn['MERCHANT_URL'];
  8. $merchant_service = $cfgPltn['MERCHANT_SERVICE'];
  9. $merchant_logo = $cfgPltn['MERCHANT_LOGO'];
  10. $merchant_currency = $cfgPltn['MERCHANT_CURRENCY'];
  11. $avail_prices = $cfgPltn['AVAIL_PRICES'];
  12. define('PAYSYS_PREFIX', 'PLATONM' . '_');
  13. /**
  14. * Returns user's assigned agent extended data, if available
  15. *
  16. * @param $gentID
  17. *
  18. * @return array|empty
  19. */
  20. function getGoosData($customerId, $amountRaw = '') {
  21. global $cfgPltn;
  22. $baseUrl = $cfgPltn['BILLING_URL'] . '?module=remoteapi&key=' . $cfgPltn['BILLING_KEY'] . '&action=goose';
  23. $callbackUrl = $baseUrl . '&amount=' . $amountRaw . '&paymentid=' . $customerId;
  24. $gooseResult = @file_get_contents($callbackUrl);
  25. return ($gooseResult);
  26. }
  27. function platonSumm($customer_id, $avail_prices, $merchant_currency) {
  28. global $cfgPltn;
  29. $inputs = '';
  30. $result = '';
  31. if (!empty($avail_prices)) {
  32. $avail_prices = explode(',', $avail_prices);
  33. $i = 0;
  34. foreach ($avail_prices as $eachprice) {
  35. $selected = false;
  36. if ($i == 0) {
  37. $selected = true;
  38. }
  39. $inputs .= wf_RadioInput('amount', $eachprice . ' ' . $merchant_currency, $eachprice, true, $selected);
  40. $i++;
  41. }
  42. if (isset($cfgPltn['CUSTOM_PRICE']) and ! empty($cfgPltn['CUSTOM_PRICE'])) {
  43. $jsCode = 'function change_custom_amount(){
  44. var custom_amount = document.getElementById("radio_custom_amount");
  45. custom_amount.value = document.getElementById("input_custom_amount").value;
  46. custom_amount.value = (custom_amount.value).toFixed(2);
  47. }
  48. document.addEventListener(\'DOMContentLoaded\', function() {
  49. change_custom_amount();
  50. }, false);';
  51. $inputs .= wf_tag('script') . $jsCode . wf_tag('script', true);
  52. $inputs .= wf_tag('input', false, '', 'type="radio" name="amount" value="' . $cfgPltn['CUSTOM_PRICE'] . '" id="radio_custom_amount" onClick="change_custom_amount()"');
  53. $inputs .= wf_tag('input', false, '', 'onchange="change_custom_amount()" id="input_custom_amount" type="number" style="width: 4em;" value="' . $cfgPltn['CUSTOM_PRICE'] . '" min="' . $cfgPltn['CUSTOM_PRICE'] . '" step="any"') . ' ';
  54. $inputs .= wf_tag('label', false, '', 'for="radio_custom_amount"') . $cfgPltn['MERCHANT_CURRENCY'] . wf_tag('label', true) . wf_delimiter(0);
  55. }
  56. } else {
  57. $inputs .= wf_TextInput('amount', $merchant_currency, '', true, 5, 'finance');
  58. }
  59. $inputs .= wf_HiddenInput('paymentid', $customer_id);
  60. $inputs .= wf_delimiter(0);
  61. $inputs .= wf_Submit('Оплатити');
  62. $result .= wf_Form('', 'POST', $inputs, '');
  63. return ($result);
  64. }
  65. $payment_form = '';
  66. if (!ubRouting::checkPost('amount') and ! ubRouting::checkPost('paymentid')) {
  67. if (ubRouting::checkGet('customer_id')) {
  68. $customer_id = ubRouting::get('customer_id', 'vf');
  69. $payment_form = platonSumm($customer_id, $avail_prices, $merchant_currency);
  70. } else {
  71. $payment_form = 'FAIL: no customer ID set';
  72. }
  73. } else {
  74. //push form
  75. $customerId = ubRouting::post('paymentid', 'vf');
  76. $amountRaw = ubRouting::post('amount', 'float');
  77. $gooseResult = getGoosData($customerId, $amountRaw);
  78. //optional external service payment
  79. if (isset($cfgPltn['SERVICE_PAYMENT_PERCENT'])) {
  80. if ($cfgPltn['SERVICE_PAYMENT_PERCENT']) {
  81. $externalPercent = ubRouting::filters($cfgPltn['SERVICE_PAYMENT_PERCENT'], 'float');
  82. $amountRaw = $amountRaw + ($amountRaw * ($externalPercent / 100));
  83. }
  84. }
  85. if (!empty($customerId) and ! empty($amountRaw)) {
  86. if (!empty($gooseResult)) {
  87. $gooseResult = @json_decode($gooseResult);
  88. if (!empty($gooseResult)) {
  89. $amount = number_format($amountRaw, 2, '.', ''); //required with two finishing zeroes
  90. $key = $cfgPltn['KEY'];
  91. $pass = $cfgPltn['PASSWORD'];
  92. $payment = 'CC';
  93. $req_token = 'Y';
  94. $url = $cfgPltn['URL_OK'];
  95. $apiUrl = $cfgPltn['API_URL'];
  96. $splitProp = array();
  97. $splitRulesArr = array();
  98. $inputs = '';
  99. if ($gooseResult->agents) {
  100. if (!empty($gooseResult->agentsextinfo)) {
  101. $agentsExtInfo = preg_grep("/^" . PAYSYS_PREFIX . ".+/", array_column((array)$gooseResult->agentsextinfo, 'internal_paysys_name', 'id'));
  102. // Перевіряємо чи заповнена розширена інформація по агенту. Бо для взаємодією с приват необхідні додаткові параметри
  103. if (!empty($agentsExtInfo)) {
  104. foreach ($agentsExtInfo as $id => $paysysPrefix) {
  105. $agentId = $gooseResult->agentsextinfo->{$id}->agentid;
  106. if (!empty($gooseResult->agents->{$agentId}->ipn) or ! empty($gooseResult->agents->{$agentId}->edrpo)) {
  107. $splittedAmount = round(($gooseResult->agents->{$agentId}->splitamount ), 2);
  108. $splittedAmount = number_format($splittedAmount, 2, '.', '');
  109. $agentIdent = (!empty($gooseResult->agents->{$agentId}->ipn)) ? $gooseResult->agents->{$agentId}->ipn : $gooseResult->agents->{$agentId}->edrpo;
  110. $splitRulesArr[$agentIdent] = $splittedAmount;
  111. }
  112. }
  113. } else {
  114. die('Critical error. No advanced information found for agents');
  115. }
  116. } else {
  117. die('Critical error. No advanced information found for agents');
  118. }
  119. } else {
  120. die('Empty agents received');
  121. }
  122. //optional split rules append
  123. if (!empty($splitRulesArr)) {
  124. $amount = number_format(array_sum($splitRulesArr), 2, '.', ''); //required with two finishing zeroes
  125. $sRulesJson = htmlspecialchars(json_encode($splitRulesArr));
  126. $inputs .= wf_HiddenInput('split_rules', $sRulesJson);
  127. $inputs .= wf_HiddenInput('ext1', $sRulesJson);
  128. } else {
  129. die('Critical error. No found for IPN or EDRPO for agents');
  130. }
  131. $rawData = array(
  132. 'amount' => $amount,
  133. 'description' => $customerId,
  134. 'currency' => 'UAH',
  135. 'recurring' => 'Y'
  136. );
  137. $data = base64_encode(json_encode($rawData));
  138. $sign = md5(
  139. strtoupper(
  140. strrev($key) .
  141. strrev($payment) .
  142. strrev($data) .
  143. strrev($url) .
  144. strrev($pass)
  145. )
  146. );
  147. $inputs .= wf_HiddenInput('payment', $payment);
  148. $inputs .= wf_HiddenInput('key', $key);
  149. $inputs .= wf_HiddenInput('url', $url);
  150. $inputs .= wf_HiddenInput('error_url', $cfgPltn['URL_FAIL']);
  151. $inputs .= wf_HiddenInput('data', $data);
  152. $inputs .= wf_HiddenInput('req_token', $req_token);
  153. $inputs .= wf_HiddenInput('sign', $sign);
  154. $inputs .= wf_HiddenInput('lang', 'UK');
  155. $inputs .= wf_HiddenInput('phone', @$gooseResult->user->mobile);
  156. $inputs .= wf_HiddenInput('first_name', @$gooseResult->user->realname);
  157. $inputs .= wf_HiddenInput('address', @$gooseResult->user->fulladress);
  158. $inputs .= wf_HiddenInput('city', @$gooseResult->user->cityname);
  159. $form = wf_Form($apiUrl, 'POST', $inputs);
  160. //auto form submit
  161. $form .= wf_tag('script', false, '', 'type="text/javascript"');
  162. $form .= ' document.forms[0].submit();';
  163. $form .= wf_tag('script', true);
  164. print($form);
  165. } else {
  166. die('Something wrong with Goose data - decode error');
  167. }
  168. } else {
  169. die('Empty Goose data received');
  170. }
  171. }
  172. }
  173. include('template.html');