fork download
  1. <?php
  2.  
  3. $passphrase = 'reservit4321';
  4.  
  5. $data = [
  6. 'merchant_id' => '10050937',
  7. 'merchant_key' => '978nbtuc7bnjc',
  8. 'return_url' => 'http://127.0.0.1:8000/api/payment/return',
  9. 'cancel_url' => 'http://127.0.0.1:8000/api/payment/cancel',
  10. 'notify_url' => 'http://127.0.0.1:8000/api/payment/notify',
  11. 'name_first' => 'Sthembiso',
  12. 'name_last' => 'Mathebula',
  13. 'email_address' => 'smathebula.sb11@gmail.com',
  14. 'cell_number' => '0721496687',
  15. 'm_payment_id' => '27',
  16. 'amount' => '100.00',
  17. 'item_name' => 'Booking for Yoga Class',
  18. 'item_description' => 'Service booking - Date: 2026-07-06',
  19. //'reference' => 'BOOKING-41-PAYMENT-27', // Leave commented for now
  20. 'custom_int1' => '27',
  21. 'custom_str1' => 'booking_payment',
  22. ];
  23.  
  24. //
  25. // Generate Signature
  26. //
  27. $paramString = '';
  28.  
  29. foreach ($data as $key => $value) {
  30.  
  31. if ($value === '') {
  32. continue;
  33. }
  34.  
  35. $paramString .= $key . '=' . urlencode(trim($value)) . '&';
  36. }
  37.  
  38. $paramString = rtrim($paramString, '&');
  39.  
  40. if ($passphrase !== '') {
  41. $paramString .= '&passphrase=' . urlencode($passphrase);
  42. }
  43.  
  44. $signature = md5($paramString);
  45.  
  46. $data['signature'] = $signature;
  47.  
  48. echo "==============================\n";
  49. echo "PARAM STRING\n";
  50. echo "==============================\n";
  51. echo $paramString . "\n\n";
  52.  
  53. echo "==============================\n";
  54. echo "SIGNATURE\n";
  55. echo "==============================\n";
  56. echo $signature . "\n\n";
  57.  
  58. //
  59. // Send to PayFast
  60. //
  61.  
  62. $ch = curl_init('https://s...content-available-to-author-only...o.za/eng/process');
  63.  
  64. CURLOPT_POST => true,
  65. CURLOPT_POSTFIELDS => http_build_query($data),
  66. CURLOPT_RETURNTRANSFER => true,
  67. CURLOPT_HEADER => true,
  68. CURLOPT_FOLLOWLOCATION => false,
  69. CURLOPT_SSL_VERIFYPEER => true,
  70. CURLOPT_HTTPHEADER => [
  71. 'Content-Type: application/x-www-form-urlencoded'
  72. ],
  73. ]);
  74.  
  75. $response = curl_exec($ch);
  76.  
  77. if ($response === false) {
  78. die(curl_error($ch));
  79. }
  80.  
  81. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  82. $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  83.  
  84. $headers = substr($response, 0, $headerSize);
  85. $body = substr($response, $headerSize);
  86.  
  87.  
  88. echo "==============================\n";
  89. echo "HTTP STATUS\n";
  90. echo "==============================\n";
  91. echo $httpCode . "\n\n";
  92.  
  93. echo "==============================\n";
  94. echo "HEADERS\n";
  95. echo "==============================\n";
  96. echo $headers . "\n";
  97.  
  98. echo "==============================\n";
  99. echo "BODY\n";
  100. echo "==============================\n";
  101. echo $body;
  102.  
Success #stdin #stdout 0.02s 26240KB
stdin
Standard input is empty
stdout
==============================
PARAM STRING
==============================
merchant_id=10050937&merchant_key=978nbtuc7bnjc&return_url=http%3A%2F%2F127.0.0.1%3A8000%2Fapi%2Fpayment%2Freturn&cancel_url=http%3A%2F%2F127.0.0.1%3A8000%2Fapi%2Fpayment%2Fcancel&notify_url=http%3A%2F%2F127.0.0.1%3A8000%2Fapi%2Fpayment%2Fnotify&name_first=Sthembiso&name_last=Mathebula&email_address=smathebula.sb11%40gmail.com&cell_number=0721496687&m_payment_id=27&amount=100.00&item_name=Booking+for+Yoga+Class&item_description=Service+booking+-+Date%3A+2026-07-06&custom_int1=27&custom_str1=booking_payment&passphrase=reservit4321

==============================
SIGNATURE
==============================
3eb38c8f56dc8a2bbf41587875789ffd

Could not resolve host: sandbox.payfast.co.za