index.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. function platonSumm($customer_id, $avail_prices, $merchant_currency) {
  13. global $cfgPltn;
  14. $inputs = '';
  15. $result = '';
  16. if (!empty($avail_prices)) {
  17. $avail_prices = explode(',', $avail_prices);
  18. $i = 0;
  19. foreach ($avail_prices as $eachprice) {
  20. $selected = false;
  21. if ($i == 0) {
  22. $selected = true;
  23. }
  24. $inputs .= wf_RadioInput('amount', $eachprice . ' ' . $merchant_currency, $eachprice, true, $selected);
  25. $i++;
  26. }
  27. if (isset($cfgPltn['CUSTOM_PRICE']) and ! empty($cfgPltn['CUSTOM_PRICE'])) {
  28. $jsCode = 'function change_custom_amount(){
  29. var custom_amount = document.getElementById("radio_custom_amount");
  30. custom_amount.value = document.getElementById("input_custom_amount").value;
  31. custom_amount.value = (custom_amount.value).toFixed(2);
  32. }
  33. document.addEventListener(\'DOMContentLoaded\', function() {
  34. change_custom_amount();
  35. }, false);';
  36. $inputs .= wf_tag('script') . $jsCode . wf_tag('script', true);
  37. $inputs .= wf_tag('input', false, '', 'type="radio" name="amount" value="' . $cfgPltn['CUSTOM_PRICE'] . '" id="radio_custom_amount" onClick="change_custom_amount()"');
  38. $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"') . ' ';
  39. $inputs .= wf_tag('label', false, '', 'for="radio_custom_amount"') . $cfgPltn['MERCHANT_CURRENCY'] . wf_tag('label', true) . wf_delimiter(0);
  40. }
  41. } else {
  42. $inputs .= wf_TextInput('amount', $merchant_currency, '', true, 5, 'finance');
  43. }
  44. $inputs .= wf_HiddenInput('paymentid', $customer_id);
  45. $inputs .= wf_delimiter(0);
  46. $inputs .= wf_Submit('Оплатити');
  47. $result .= wf_Form('', 'POST', $inputs, '');
  48. return ($result);
  49. }
  50. $payment_form = '';
  51. if (!ubRouting::checkPost('amount') and ! ubRouting::checkPost('paymentid')) {
  52. if (ubRouting::checkGet('customer_id')) {
  53. $customer_id = ubRouting::get('customer_id', 'vf');
  54. $payment_form = platonSumm($customer_id, $avail_prices, $merchant_currency);
  55. } else {
  56. $payment_form = 'FAIL: no customer ID set';
  57. }
  58. } else {
  59. //push form
  60. $customerId = ubRouting::post('paymentid', 'vf');
  61. $amountRaw = ubRouting::post('amount', 'float');
  62. //optional external service payment
  63. if (isset($cfgPltn['SERVICE_PAYMENT_PERCENT'])) {
  64. if ($cfgPltn['SERVICE_PAYMENT_PERCENT']) {
  65. $externalPercent = ubRouting::filters($cfgPltn['SERVICE_PAYMENT_PERCENT'], 'float');
  66. $amountRaw = ceil($amountRaw + ($amountRaw * ($externalPercent / 100)));
  67. }
  68. }
  69. if (!empty($customerId) and ! empty($amountRaw)) {
  70. $amount = number_format($amountRaw, 2, '.', ''); //required with two finishing zeroes
  71. $key = $cfgPltn['KEY'];
  72. $pass = $cfgPltn['PASSWORD'];
  73. $payment = 'CC';
  74. $req_token = 'Y';
  75. $url = $cfgPltn['URL_OK'];
  76. $apiUrl = $cfgPltn['API_URL'];
  77. $splitProp = array();
  78. $splitRulesArr = array();
  79. $splitRules = '';
  80. //proportional static split
  81. if (isset($cfgPltn['SPLIT_STATIC'])) {
  82. if (!empty($cfgPltn['SPLIT_STATIC'])) {
  83. $splitProp = explode(',', $cfgPltn['SPLIT_STATIC']);
  84. foreach ($splitProp as $io => $eachSplit) {
  85. if (!empty($eachSplit)) {
  86. $cleanSplit = trim($eachSplit);
  87. $splitRulesArr[$cleanSplit] = 0;
  88. }
  89. }
  90. $splitAmountRatio = sizeof($splitRulesArr);
  91. $splittedAmount = round(($amountRaw / $splitAmountRatio), 2);
  92. $splittedAmount = number_format($splittedAmount, 2, '.', '');
  93. foreach ($splitRulesArr as $eachSplit => $eachAmount) {
  94. if (!empty($eachSplit)) {
  95. $splitRulesArr[$eachSplit] = $splittedAmount;
  96. }
  97. }
  98. }
  99. }
  100. //goose resistance is here
  101. if (isset($cfgPltn['GOOSE_RESISTANCE']) and $cfgPltn['GOOSE_RESISTANCE']) {
  102. $baseUrl = $cfgPltn['BILLING_URL'] . '/?module=remoteapi&key=' . $cfgPltn['BILLING_KEY'] . '&action=goose';
  103. $callbackUrl = $baseUrl . '&amount=' . $amountRaw . '&paymentid=' . $customerId;
  104. $gooseResult = @file_get_contents($callbackUrl);
  105. if (!empty($gooseResult)) {
  106. $gooseResult = @json_decode($gooseResult, true);
  107. if (!empty($gooseResult)) {
  108. if ($gooseResult['agents']) {
  109. foreach ($gooseResult['agents'] as $io => $each) {
  110. $splittedAmount = round(($each['splitamount']), 2);
  111. $splittedAmount = number_format($splittedAmount, 2, '.', '');
  112. $splitRulesArr[$each['edrpo']] = $splittedAmount;
  113. }
  114. } else {
  115. die('Empty agents received');
  116. }
  117. } else {
  118. die('Something went wrong - decode error');
  119. }
  120. } else {
  121. die('Something went wrong - empty reply');
  122. }
  123. }
  124. $rawData = array(
  125. 'amount' => $amount,
  126. 'description' => $customerId,
  127. 'currency' => 'UAH',
  128. 'recurring' => 'Y'
  129. );
  130. $data = base64_encode(json_encode($rawData));
  131. $sign = md5(
  132. strtoupper(
  133. strrev($key) .
  134. strrev($payment) .
  135. strrev($data) .
  136. strrev($url) .
  137. strrev($pass)
  138. )
  139. );
  140. //optional split rules append
  141. if (!empty($splitRulesArr)) {
  142. $splitRules .= wf_HiddenInput('split_rules', htmlspecialchars(json_encode($splitRulesArr)));
  143. }
  144. $inputs = '';
  145. $inputs .= wf_HiddenInput('payment', $payment);
  146. $inputs .= wf_HiddenInput('key', $key);
  147. $inputs .= wf_HiddenInput('url', $url);
  148. $inputs .= wf_HiddenInput('error_url', $cfgPltn['URL_FAIL']);
  149. $inputs .= wf_HiddenInput('data', $data);
  150. $inputs .= wf_HiddenInput('req_token', $req_token);
  151. $inputs .= wf_HiddenInput('sign', $sign);
  152. $inputs .= wf_HiddenInput('lang', 'UK');
  153. $inputs .= $splitRules;
  154. $form = wf_Form($apiUrl, 'POST', $inputs);
  155. //auto form submit
  156. $form .= wf_tag('script', false, '', 'type="text/javascript"');
  157. $form .= ' document.forms[0].submit();';
  158. $form .= wf_tag('script', true);
  159. print($form);
  160. }
  161. }
  162. include('template.html');