index.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. $paymeConf = parse_ini_file('config/mypaymeuz.ini');
  3. // подключаем API MySQL
  4. include ("../../libs/api.mysql.php");
  5. //вытаскиваем из конфига все что нам нужно в будущем
  6. $ispUrl = $paymeConf['TEMPLATE_ISP_URL'];
  7. $ispName = $paymeConf['TEMPLATE_ISP'];
  8. $ispLogo = $paymeConf['TEMPLATE_ISP_LOGO'];
  9. $merchant_service = $paymeConf['MERCHANT_SERVICE'];
  10. /*
  11. * shows payment summ selection form
  12. *
  13. * @return string
  14. */
  15. function payme_PricesForm() {
  16. global $paymeConf;
  17. $result = '<form action="" method="POST">';
  18. $addCommission = (isset($paymeConf['ADD_COMMISSION'])) ? $paymeConf['ADD_COMMISSION'] : 1;
  19. if (!empty($paymeConf['AVAIL_PRICES'])) {
  20. $pricesArr = array();
  21. $pricesRaw = explode(',', $paymeConf['AVAIL_PRICES']);
  22. if (!empty($pricesRaw)) {
  23. $i=0;
  24. foreach ($pricesRaw as $eachPrice) {
  25. $selected = ($i==0) ? 'CHECKED' : '';
  26. $result.= '<input type="radio" name="amount" value="' . (trim($eachPrice)*($addCommission)) . '" ' . $selected . '> ' . trim($eachPrice) . ' ' . $paymeConf['TEMPLATE_CURRENCY'] . '<br>';
  27. $i++;
  28. }
  29. }
  30. }
  31. if (isset($paymeConf['CUSTOM_PRICE']) AND ! empty($paymeConf['CUSTOM_PRICE'])) {
  32. // Script for change custom amount value
  33. $result.= '<script>
  34. function change_custom_amount(){
  35. var custom_amount = document.getElementById("radio_custom_amount");
  36. custom_amount.value = document.getElementById("input_custom_amount").value;
  37. custom_amount.value = (custom_amount.value * ' . $addCommission . ').toFixed(2);
  38. }
  39. document.addEventListener(\'DOMContentLoaded\', function() {
  40. // just to apply $addCommission after the page loads
  41. change_custom_amount();
  42. }, false);
  43. </script>
  44. ';
  45. if (!empty($paymeConf['AVAIL_PRICES'])) {
  46. $result.= '<input type="radio" name="amount" value="' . $paymeConf['CUSTOM_PRICE'] . '" id="radio_custom_amount" onClick="change_custom_amount()">';
  47. } else {
  48. $result.= '<input type="hidden" name="amount" value="' . $paymeConf['CUSTOM_PRICE'] . '" id="radio_custom_amount">';
  49. }
  50. $result.= '<input onchange="change_custom_amount()" id="input_custom_amount" type="number" style="width: 4em;" value="' . $paymeConf['CUSTOM_PRICE'] . '" min="' . $paymeConf['CUSTOM_PRICE'] . '" step="any" /> ' . $paymeConf['TEMPLATE_CURRENCY'] . '<br>';
  51. }
  52. $result.= '<input type="submit" value="' . $paymeConf['TEMPLATE_NEXT'] . '">';
  53. $result.= '</form>';
  54. return ($result);
  55. }
  56. /*
  57. * returns form with ClickUZ payment button
  58. *
  59. * @param $customer_id string valid Payment ID
  60. *
  61. * @return string
  62. */
  63. function payme_PaymentForm($customer_id) {
  64. global $paymeConf;
  65. $lang = $paymeConf['LANG'];
  66. $paymentDescr = $paymeConf['PAYMENT_DESCR'] . ' ' . $customer_id;
  67. $genQREnabled = $paymeConf['QR_CODE_ON'];
  68. $returnURL = $paymeConf['RETURN_URL'];
  69. $customerIDField = $paymeConf['CUSTOMERID_FIELD_NAME'];
  70. $summ = (trim($_POST['amount']) * 100);
  71. if (isset($paymeConf['MERCHANT_ID']['default'])) {
  72. $avaibleTagsRaw = explode(',', $paymeConf['AVAIBLE_TAGS_ID']);
  73. if (!empty($avaibleTagsRaw)) {
  74. $where = '';
  75. foreach ($avaibleTagsRaw as $tag) {
  76. if($tag != end($avaibleTagsRaw)) {
  77. $where.= "`tagid` = '" . trim($tag) . "' OR ";
  78. } else {
  79. $where.= "`tagid` = '" . trim($tag) . "'";
  80. }
  81. }
  82. $customer_id_m = mysql_real_escape_string($customer_id);
  83. $query = "SELECT `tagid` FROM `tags` INNER JOIN `op_customers` ON (`tags`.`login`= `op_customers`.`realid`) WHERE `op_customers`.`virtualid` = '" . $customer_id_m . "' AND (" . $where . ")";
  84. $data = simple_query($query);
  85. if (!empty($data)) {
  86. $tag_id = $data['tagid'];
  87. $merchant_id = $paymeConf['MERCHANT_ID'][$tag_id];
  88. } else {
  89. $merchant_id = $paymeConf['MERCHANT_ID']['default'];
  90. }
  91. } else {
  92. $merchant_id = $paymeConf['MERCHANT_ID']['default'];
  93. }
  94. } else {
  95. $merchant_id = $paymeConf['MERCHANT_ID'];
  96. }
  97. $qrControl = '';
  98. $qrJS = '';
  99. if ($genQREnabled) {
  100. $qrJS = 'Paycom.QR(\'#form-payme\', \'#qr-container\')';
  101. $qrControl = '
  102. <input type="hidden" name="qr" data-width="250">
  103. <div id="qr-container"></div>
  104. ';
  105. }
  106. $result = "<h2>" . $paymeConf['TEMPLATE_ISP_SERVICE'] . " " . $customer_id . "</h2>";
  107. $result.= '<br /><br />';
  108. $result.= '
  109. <script src="https://cdn.paycom.uz/integration/js/checkout.min.js"></script>
  110. <script type="text/javascript">
  111. window.onload = function() {
  112. Paycom.Button(\'#form-payme\', \'#button-container\');
  113. ' . $qrJS . '
  114. };
  115. </script>
  116. <form id="form-payme" method="POST" action="https://checkout.paycom.uz/">
  117. <input type="hidden" name="merchant" value="' . $merchant_id . '">
  118. <input type="hidden" name="account[' . $customerIDField . ']" value="' . $customer_id . '">
  119. <input type="hidden" name="amount" value="' . $summ . '">
  120. <input type="hidden" name="lang" value="' . $lang . '">
  121. <input type="hidden" name="callback" value="' . $returnURL . '"/>
  122. <input type="hidden" name="button" data-type="svg" value="colored">
  123. <div id="button-container"></div>
  124. <br />
  125. ' . $qrControl . '
  126. </form>
  127. ';
  128. return ($result);
  129. }
  130. /*
  131. * main codepart
  132. */
  133. if (isset($_GET['customer_id'])) {
  134. $customer_id = $_GET['customer_id'];
  135. if (!isset($_POST['amount'])) {
  136. $paymentForm = payme_PricesForm();
  137. } else {
  138. $paymentForm = payme_PaymentForm($customer_id);
  139. }
  140. //рендерим все в темплейт
  141. include('template.html');
  142. } else {
  143. die('WRONG_CUSTOMERID');
  144. }
  145. ?>