Hello,
This is the first time I'm using GuzzleHttp and a payment gateway.
I'm trying to implement it on an old Laravel site version 5.7.
Please excuse me if my question is unclear, but I'm very confused.
I am sending a payment request to the payment gateway, from my local machine.
I set the "notify_url" to https://mysite.co.za/payfast-notify
I create this route in web.php:
Route::post('payfast-notify', 'PayfastController@payfastNotify');
Their documentation says this: (https://developers.payfast.co.za/docs#step_4_confirm_payment)
Confirm payment is successful
Before the customer is returned to the URL you specified in the “return_url” parameter, Payfast will send a notification to your “notify_url” page.
4.1. Setting up your notification page:
On receiving the payment notification from Payfast, return a header 200 to prevent further retries.
If no 200 response is returned the notification will be re-sent immediately, then after 10 minutes and then at exponentially longer intervals until eventually stopping.
Their code example:
<?php
// Tell Payfast that this page is reachable by triggering a header 200
header( 'HTTP/1.0 200 OK' );
flush();
define( 'SANDBOX_MODE', true );
$pfHost = SANDBOX_MODE ? 'sandbox.payfast.co.za' : 'www.payfast.co.za';
// Posted variables from ITN
$pfData = $_POST;
// Strip any slashes in data
foreach( $pfData as $key => $val ) {
$pfData[$key] = stripslashes( $val );
}
// Convert posted variables to a string
foreach( $pfData as $key => $val ) {
if( $key !== 'signature' ) {
$pfParamString .= $key .'='. urlencode( $val ) .'&';
} else {
break;
}
}
$pfParamString = substr( $pfParamString, 0, -1 );
I am not sure how do I return 200 response? How can I test this?
I created a controller called: PayfastController.
In it I have this method:
function payfastNotify(Request $request)
{
// Tell Payfast that this page is reachable by triggering a header 200
header( 'HTTP/1.0 200 OK' );
flush();
$pfHost = 'sandbox.payfast.co.za';
$pfParamString = '';
// Posted variables from ITN
$pfData = $request; //$_POST;
// Strip any slashes in data
foreach( $pfData as $key => $val ) {
$pfData[$key] = stripslashes( $val );
}
// Convert posted variables to a string
foreach( $pfData as $key => $val ) {
if( $key !== 'signature' ) {
$pfParamString .= $key .'='. urlencode( $val ) .'&';
} else {
break;
}
}
$pfParamString = substr( $pfParamString, 0, -1 );
Log::debug('payfat: {result}', ['result' => $pfParamString]);
}
After sending the request from my local machine, I check the logs on the live server, but no log file was created.
Not sure how to implement this procedure and how to test.
I read Laravel documentaion about Fake, but I don't really understand it, I'm not sure if that can help me test the response that should go to the nofiy_url?
As I said, very confused.
Please can someone help?