index.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // для начала получаем айди кастомера
  3. if (isset($_GET['customer_id'])) {
  4. $customer_id = $_GET['customer_id'];
  5. } else {
  6. die('customer_id fail');
  7. }
  8. // подключаем API OpenPayz
  9. include ("../../libs/api.openpayz.php");
  10. // подгружаем конфиг
  11. $conf_fondy = parse_ini_file("config/fondy.ini");
  12. // выбираем нужные нам переменные о мерчанте
  13. $merchant_name = $conf_fondy['MERCHANT_NAME'];
  14. $merchant_url = $conf_fondy['MERCHANT_URL'];
  15. $merchant_service = $conf_fondy['MERCHANT_SERVICE'];
  16. $merchant_logo = $conf_fondy['MERCHANT_LOGO'];
  17. $template_file = $conf_fondy['TEMPLATE'];
  18. /**
  19. * Renders amount select form
  20. *
  21. * @global array $conf_fondy
  22. *
  23. * @return string
  24. */
  25. function renderAmountForm() {
  26. global $conf_fondy;
  27. $avail_prices = explode(',', $conf_fondy['AVAIL_PRICES']);
  28. $result = '<h3>' . $conf_fondy['LOCALE_AMOUNT'] . '</h3> <br>';
  29. $result.= '<form method="POST" action="">';
  30. if (!empty($avail_prices)) {
  31. $i = 0;
  32. foreach ($avail_prices as $io => $eachprice) {
  33. $selected = ($i == 0) ? 'CHECKED' : '';
  34. $result.='<input type="radio" name="amount" id="am_' . $i . '" value="' . $eachprice . '" ' . $selected . '>';
  35. $result.='<label for="am_' . $i . '">' . $eachprice . ' ' . $conf_fondy['MERCHANT_CURRENCY'] . '</label> <br>';
  36. $i++;
  37. }
  38. }
  39. $result.='<br>';
  40. $result.='<input type="submit" value="' . $conf_fondy['LOCALE_SUBMIT'] . '">';
  41. $result.='</form>';
  42. return ($result);
  43. }
  44. /**
  45. * Renders JS payment form
  46. *
  47. * @param int $amount
  48. *
  49. * @return string
  50. */
  51. function renderForm($amount) {
  52. global $conf_fondy, $customer_id;
  53. $amount = vf($amount, 3);
  54. $result = $conf_fondy['LOCALE_SUM'] . ': ' . $amount . ' ' . $conf_fondy['MERCHANT_CURRENCY'] . ' ';
  55. $result.= '
  56. <script src="https://api.fondy.eu/static_common/v1/checkout/oplata.js"></script>
  57. <script>
  58. var button = $ipsp.get(\'button\');
  59. button.setMerchantId(' . $conf_fondy['MERCHANT_ID'] . ');
  60. button.setAmount(' . $amount . ', \'' . $conf_fondy['FONDY_CURRENCY'] . '\', true);
  61. button.setResponseUrl(\'' . $conf_fondy['RESPONSE_URL'] . '\');
  62. button.addParam(\'server_callback_url\',\'' . $conf_fondy['FRONTEND_URL'] . '\');
  63. button.setHost(\'api.fondy.eu\');
  64. button.addField({
  65. label: \'Payment ID\',
  66. name: \'paymentid\',
  67. value: \'' . $customer_id . '\',
  68. readonly :true,
  69. required: true
  70. });
  71. </script>
  72. <button onclick="location.href=button.getUrl()">' . $conf_fondy['LOCALE_SUBMIT'] . '</button>
  73. ';
  74. return ($result);
  75. }
  76. if (isset($_POST['amount'])) {
  77. // собираем форму для отправки ПС
  78. $payment_form = renderForm($_POST['amount']);
  79. } else {
  80. //формочка выбора суммы платежа
  81. $payment_form = renderAmountForm();
  82. }
  83. //показываем все что нужно в темплейт
  84. include($template_file);
  85. ?>