index.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. $liqConf = parse_ini_file('config/liqpay.ini');
  3. //вытаскиваем из конфига все что нам нужно в будущем
  4. $ispUrl = $liqConf['TEMPLATE_ISP_URL'];
  5. $ispName = $liqConf['TEMPLATE_ISP'];
  6. $ispLogo = $liqConf['TEMPLATE_ISP_LOGO'];
  7. $merchant_service = $liqConf['MERCHANT_SERVICE'];
  8. /*
  9. * generates random transaction hash
  10. *
  11. * @return string
  12. */
  13. function lq_SessionGen($size=16) {
  14. $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
  15. $string = "LIQPAY_";
  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 lq_PricesForm() {
  27. global $liqConf;
  28. $result = '<form action="" method="POST">';
  29. if (!empty($liqConf['AVAIL_PRICES'])) {
  30. $pricesArr = array();
  31. $pricesRaw = explode(',', $liqConf['AVAIL_PRICES']);
  32. if (!empty($pricesRaw)) {
  33. $i=0;
  34. foreach ($pricesRaw as $eachPrice) {
  35. $selected = ($i==0) ?'CHECKED' : '' ;
  36. $result .='<input type="radio" name="amount" value="'.$eachPrice.'" '.$selected.'> '.$eachPrice.' '.$liqConf['TEMPLATE_CURRENCY'].'<br>';
  37. $i++;
  38. }
  39. }
  40. }
  41. $result .= '<input type="submit" value="'.$liqConf['TEMPLATE_NEXT'].'">';
  42. $result .= '</form>';
  43. return ($result);
  44. }
  45. /*
  46. * returns LiqPay hashed form
  47. *
  48. * @param $customer_id string valid Payment ID
  49. *
  50. * @return string
  51. */
  52. function lq_PaymentForm($customer_id) {
  53. global $liqConf;
  54. $merchant_id = $liqConf['MERCHANT_ID'];
  55. $signature = $liqConf['SIGNATURE'];
  56. $url = $liqConf['LIQURL'];
  57. $method = $liqConf['METHOD'];
  58. $currency = $liqConf['CURRENCY'];
  59. $summ = $_POST['amount'];
  60. $resultUrl = $liqConf['RESULT_URL'];
  61. $serverUrl = $liqConf['SERVER_URL'];
  62. $phone = '';
  63. $session = lq_SessionGen();
  64. $xml='<request>
  65. <version>1.2</version>
  66. <result_url>'.$resultUrl.'</result_url>
  67. <server_url>'.$serverUrl.'</server_url>
  68. <merchant_id>'.$merchant_id.'</merchant_id>
  69. <order_id>'.$session.'</order_id>
  70. <amount>'.$summ.'</amount>
  71. <currency>'.$currency.'</currency>
  72. <description>'.$customer_id.'</description>
  73. <default_phone>'.$phone.'</default_phone>
  74. <pay_way>'.$method.'</pay_way>
  75. </request>
  76. ';
  77. $xml_encoded = base64_encode($xml);
  78. $lqsignature = base64_encode(sha1($signature.$xml.$signature,1));
  79. $result="<h2>".$liqConf['TEMPLATE_ISP_SERVICE']." ".$customer_id."</h2>
  80. <form action='".$url."' method='POST'>
  81. <input type='hidden' name='operation_xml' value='$xml_encoded' />
  82. <input type='hidden' name='signature' value='$lqsignature' />
  83. <input type='submit' value='".$liqConf['TEMPLATE_GOPAYMENT']."'/>
  84. </form>";
  85. return ($result);
  86. }
  87. /*
  88. * main codepart
  89. */
  90. if (isset($_GET['customer_id'])) {
  91. $customer_id = $_GET['customer_id'];
  92. if (!isset($_POST['amount'])) {
  93. $paymentForm = lq_PricesForm();
  94. } else {
  95. $paymentForm = lq_PaymentForm($customer_id);
  96. }
  97. //рендерим все в темплейт
  98. include('template.html');
  99. } else {
  100. die('WRONG_CUSTOMERID');
  101. }
  102. ?>