fork download
  1. <?php
  2.  
  3. function initiatePayment()
  4. {
  5. $payload = [
  6. 'key' => 'gkJFyi',
  7. 'txnid' => 'dfhlkdshfldshflds',
  8. 'upiAppName' => 'phonepe',
  9. 'amount' => 10.00,
  10. 'productinfo' => 'iPhone',
  11. 'firstname' => 'Customer',
  12. 'lastname' => 'Name',
  13. 'email' => 'customer@gmail.com',
  14. 'phone' => '9090909090',
  15. 'pg' => 'UPI',
  16. 'bankcode' => 'INTENT',
  17. 'txn_s2s_flow' => 4,
  18. 'udf1' => '',
  19. 'udf2' => '',
  20. 'udf3' => '',
  21. 'udf4' => '',
  22. 'udf5' => '',
  23. ];
  24.  
  25. $salt = 'b6RUxr5Zx04rCYV0Dpk4Ph9f1pzoeJ9G';
  26. $payload['hash'] = generateHash($payload, $salt);
  27.  
  28. $mainUrl = 'https://s...content-available-to-author-only...u.in/_payment';
  29.  
  30. // Initialize cURL
  31. $ch = curl_init($mainUrl);
  32.  
  33. // Set cURL options
  34. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  35. curl_setopt($ch, CURLOPT_POST, true);
  36. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
  37.  
  38. // Execute the request
  39. $response = curl_exec($ch);
  40.  
  41. // Check for cURL errors
  42. if (curl_errno($ch)) {
  43. echo 'Curl error: ' . curl_error($ch);
  44. curl_close($ch);
  45. return;
  46. }
  47.  
  48. // Get the HTTP status code
  49. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  50. curl_close($ch);
  51.  
  52. // Check response status
  53. if ($httpCode !== 200) {
  54. echo 'Failed to initiate payment with PayU. HTTP Code: ' . $httpCode;
  55. return;
  56. }
  57.  
  58. // Output response (HTML form or redirect content from PayU)
  59. echo $response;
  60. }
  61.  
  62. function generateHash(array $payload, string $salt): string
  63. {
  64. $input = implode('|', [
  65. $payload['key'],
  66. $payload['txnid'],
  67. $payload['amount'],
  68. $payload['productinfo'],
  69. $payload['firstname'],
  70. $payload['email'],
  71. $payload['udf1'],
  72. $payload['udf2'],
  73. $payload['udf3'],
  74. $payload['udf4'],
  75. $payload['udf5'],
  76. '',
  77. '',
  78. '',
  79. '',
  80. '',
  81. $salt
  82. ]);
  83.  
  84. return hash('sha512', $input);
  85. }
  86.  
  87. // Call the function to test
  88. initiatePayment();
  89.  
Success #stdin #stdout 0.03s 26064KB
stdin
Standard input is empty
stdout
Curl error: Could not resolve host: secure.payu.in