index.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. $mypConf = parse_ini_file('config/mypayprivat.ini');
  3. // подключаем API MySQL
  4. include ("../../libs/api.mysql.php");
  5. //вытаскиваем из конфига все что нам нужно в будущем
  6. $ispUrl = $mypConf['TEMPLATE_ISP_URL'];
  7. $ispName = $mypConf['TEMPLATE_ISP'];
  8. $ispLogo = $mypConf['TEMPLATE_ISP_LOGO'];
  9. $merchant_service = $mypConf['MERCHANT_SERVICE'];
  10. if (!function_exists('rcms_redirect')) {
  11. /**
  12. * Shows redirection javascript.
  13. *
  14. * @param string $url
  15. * @param bool $header
  16. */
  17. function rcms_redirect($url, $header = false) {
  18. if ($header) {
  19. @header('Location: ' . $url);
  20. } else {
  21. echo '<script language="javascript">document.location.href="' . $url . '";</script>';
  22. }
  23. }
  24. }
  25. /*
  26. * shows payment summ selection form
  27. *
  28. * @return string
  29. */
  30. function myp_PricesForm() {
  31. global $mypConf;
  32. $result = '<form action="" method="POST">';
  33. $addCommission = (isset($mypConf['ADD_COMMISSION'])) ? $mypConf['ADD_COMMISSION'] : 1;
  34. if (!empty($mypConf['AVAIL_PRICES'])) {
  35. $pricesArr = array();
  36. $pricesRaw = explode(',', $mypConf['AVAIL_PRICES']);
  37. if (!empty($pricesRaw)) {
  38. $i = 0;
  39. foreach ($pricesRaw as $eachPrice) {
  40. $selected = ($i == 0) ? 'CHECKED' : '';
  41. $result .= '<input type="radio" name="amount" value="' . (trim($eachPrice) * ($addCommission)) . '" ' . $selected . '> ' . trim($eachPrice) . ' ' . $mypConf['TEMPLATE_CURRENCY'] . '<br>';
  42. $i++;
  43. }
  44. }
  45. }
  46. if (isset($mypConf['CUSTOM_PRICE']) AND ! empty($mypConf['CUSTOM_PRICE'])) {
  47. // Script for change custom amount value
  48. $result .= '<script>
  49. function change_custom_amount(){
  50. var custom_amount = document.getElementById("radio_custom_amount");
  51. custom_amount.value = document.getElementById("input_custom_amount").value;
  52. custom_amount.value = (custom_amount.value * ' . $addCommission . ').toFixed(2);
  53. }
  54. document.addEventListener(\'DOMContentLoaded\', function() {
  55. // just to apply $addCommission after the page loads
  56. change_custom_amount();
  57. }, false);
  58. </script>
  59. ';
  60. if (!empty($mypConf['AVAIL_PRICES'])) {
  61. $result .= '<input type="radio" name="amount" value="' . $mypConf['CUSTOM_PRICE'] . '" id="radio_custom_amount" onClick="change_custom_amount()">';
  62. } else {
  63. $result .= '<input type="hidden" name="amount" value="' . $mypConf['CUSTOM_PRICE'] . '" id="radio_custom_amount">';
  64. }
  65. $result .= '<input onchange="change_custom_amount()" id="input_custom_amount" type="number" style="width: 4em;" value="' . $mypConf['CUSTOM_PRICE'] . '" min="' . $mypConf['CUSTOM_PRICE'] . '" step="any" /> ' . $mypConf['TEMPLATE_CURRENCY'] . '<br>';
  66. }
  67. $result .= '<input type="submit" value="' . $mypConf['TEMPLATE_NEXT'] . '">';
  68. $result .= '</form>';
  69. return ($result);
  70. }
  71. /*
  72. * returns my-payments link
  73. *
  74. * @param $customer_id string valid Payment ID
  75. *
  76. * @return string
  77. */
  78. function myp_PaymentForm($customer_id) {
  79. global $mypConf;
  80. $summ = trim($_POST['amount']);
  81. if (is_array($mypConf['STATIC_TOKEN'])) {
  82. if (array_key_exists('default', $mypConf['STATIC_TOKEN'])) {
  83. $avaibleTagsRaw = explode(',', $mypConf['AVAIBLE_TAGS_ID']);
  84. if (!empty($avaibleTagsRaw)) {
  85. $where = '';
  86. foreach ($avaibleTagsRaw as $tag) {
  87. if ($tag != end($avaibleTagsRaw)) {
  88. $where .= "`tagid` = '" . trim($tag) . "' OR ";
  89. } else {
  90. $where .= "`tagid` = '" . trim($tag) . "'";
  91. }
  92. }
  93. $customer_id_m = mysql_real_escape_string($customer_id);
  94. $query = "SELECT `tagid` FROM `tags` INNER JOIN `op_customers` ON (`tags`.`login`= `op_customers`.`realid`) WHERE `op_customers`.`virtualid` = '" . $customer_id_m . "' AND (" . $where . ")";
  95. $data = simple_query($query);
  96. if (!empty($data)) {
  97. $tag_id = $data['tagid'];
  98. $staticToken = $mypConf['STATIC_TOKEN'][$tag_id];
  99. } else {
  100. $staticToken = $mypConf['STATIC_TOKEN']['default'];
  101. }
  102. } else {
  103. $staticToken = $mypConf['STATIC_TOKEN']['default'];
  104. }
  105. } else {
  106. $staticToken = $mypConf['STATIC_TOKEN'];
  107. }
  108. } else {
  109. $staticToken = $mypConf['STATIC_TOKEN'];
  110. }
  111. $result = 'https://my-payments.privatbank.ua/mypayments/customauth/identification/fp/static?staticToken=' . $staticToken . '&acc=' . $customer_id . '&amount=' . $summ;
  112. return ($result);
  113. }
  114. /*
  115. * main codepart
  116. */
  117. if (isset($_GET['customer_id'])) {
  118. $customer_id = $_GET['customer_id'];
  119. if (!isset($_POST['amount'])) {
  120. $paymentForm = myp_PricesForm();
  121. } else {
  122. $paymentForm = myp_PaymentForm($customer_id);
  123. rcms_redirect($paymentForm);
  124. }
  125. //рендерим все в темплейт
  126. include('template.html');
  127. } else {
  128. die('WRONG_CUSTOMERID');
  129. }
  130. ?>