index.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. $pbConf = parse_ini_file('config/privat.ini');
  3. //вытаскиваем из конфига все что нам нужно в будущем
  4. $ispUrl = $pbConf['TEMPLATE_ISP_URL'];
  5. $ispName = $pbConf['TEMPLATE_ISP'];
  6. $ispLogo = $pbConf['TEMPLATE_ISP_LOGO'];
  7. $merchant_service = $pbConf['MERCHANT_SERVICE'];
  8. /*
  9. * generates random transaction hash
  10. *
  11. * @return string
  12. */
  13. function pb_SessionGen($size=16) {
  14. $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
  15. $string = "PB24PAY_";
  16. for ($p = 0; $p < $size; $p++) {
  17. $string .= $characters[mt_rand(0, (strlen($characters)-1))];
  18. }
  19. return ($string);
  20. }
  21. /*
  22. * shows payment summ selection form
  23. *
  24. * @return string
  25. */
  26. function pb_PricesForm() {
  27. global $pbConf;
  28. $result = '<form action="" method="POST">';
  29. $addCommission = (isset($pbConf['ADD_COMMISSION'])) ? $pbConf['ADD_COMMISSION'] : 1;
  30. if (!empty($pbConf['AVAIL_PRICES'])) {
  31. $pricesArr = array();
  32. $pricesRaw = explode(',', $pbConf['AVAIL_PRICES']);
  33. if (!empty($pricesRaw)) {
  34. $i=0;
  35. foreach ($pricesRaw as $eachPrice) {
  36. $selected = ($i==0) ?'CHECKED' : '' ;
  37. $result.= '<input type="radio" name="amount" value="' . (trim($eachPrice)*($addCommission)) . '" ' . $selected . '> ' . trim($eachPrice) . ' ' . $pbConf['TEMPLATE_CURRENCY'] . '<br>';
  38. $i++;
  39. }
  40. }
  41. }
  42. if (isset($pbConf['CUSTOM_PRICE']) AND ! empty($pbConf['CUSTOM_PRICE'])) {
  43. // Script for change custom amount value
  44. $result.= '<script>
  45. function change_custom_amount(){
  46. var custom_amount = document.getElementById("radio_custom_amount");
  47. custom_amount.value = document.getElementById("input_custom_amount").value;
  48. custom_amount.value = (custom_amount.value * ' . $addCommission . ').toFixed(2);
  49. }
  50. </script>
  51. ';
  52. $result.= '<input type="radio" name="amount" value="custom_amount" id="radio_custom_amount" onClick="change_custom_amount()">';
  53. $result.= '<input onchange="change_custom_amount()" id="input_custom_amount" type="number" style="width: 4em;" value="' . $pbConf['CUSTOM_PRICE'] . '" min="' . $pbConf['CUSTOM_PRICE'] . '" step="any" /> ' . $pbConf['TEMPLATE_CURRENCY'] . '<br>';
  54. }
  55. $result .= '<input type="submit" value="'.$pbConf['TEMPLATE_NEXT'].'">';
  56. $result .= '</form>';
  57. return ($result);
  58. }
  59. /*
  60. * returns Privat24 hashed form
  61. *
  62. * @param $customer_id string valid Payment ID
  63. *
  64. * @return string
  65. */
  66. function pb_PaymentForm($customer_id) {
  67. global $pbConf;
  68. $merchant_id = $pbConf['MERCHANT_ID'];
  69. $summ = $_POST['amount'];
  70. $resultUrl = $pbConf['RESULT_URL'];
  71. $serverUrl = $pbConf['SERVER_URL'];
  72. $session = pb_SessionGen();
  73. $result = '
  74. <form method="POST" action="' . $pbConf['PBURL'] . '">
  75. <input type="hidden" name="amt" value="' . $summ . '"/>
  76. <input type="hidden" name="ccy" value="UAH"/>
  77. <input type="hidden" name="merchant" value="' . $merchant_id . '"/>
  78. <input type="hidden" name="order" value="' . $session . '"/>
  79. <input type="hidden" name="details" value="' . $pbConf['TEMPLATE_ISP_SERVICE'] . " " . $customer_id . '"/>
  80. <input type="hidden" name="ext_details" value="' . $customer_id . '"/>
  81. <input type="hidden" name="return_url" value="' . $resultUrl . '"/>
  82. <input type="hidden" name="server_url" value="' . $serverUrl . '"/>
  83. <input type="hidden" name="pay_way" value="PRIVAT24"/>
  84. <input type="submit" value="' . $pbConf['TEMPLATE_GOPAYMENT'] . '">
  85. </form>
  86. ';
  87. return ($result);
  88. }
  89. /*
  90. * main codepart
  91. */
  92. if (isset($_GET['customer_id'])) {
  93. $customer_id = $_GET['customer_id'];
  94. if (!isset($_POST['amount'])) {
  95. $paymentForm = pb_PricesForm();
  96. } else {
  97. $paymentForm = pb_PaymentForm($customer_id);
  98. }
  99. //рендерим все в темплейт
  100. include('template.html');
  101. } else {
  102. die('WRONG_CUSTOMERID');
  103. }
  104. ?>