Callback Issue
kenprogrammer opened this issue · 9 comments
After payment has been processed successfully,on callback i get the following error:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: POST.
http://localhost:8000/rave/callback?resp=the long encrypted string here
My routes: (As in the docs)
Route::post('/pay', 'RaveController@initialize')->name('pay');
Route::post('/rave/callback', 'RaveController@callback')->name('callback');
Excluded call back route from CSRF verification as directed on the docs.
Please also note that redirects are not working on Brave browser. (Though I think this could be an issue on the flutterwave side due to blocking of cookies). Just hangs on the payment successful page. (See attached screenshot)
Please help need to release an update on my store
I've tested the Rave Standard(PHP) and the callback works with Brave Browser. There could be a problem redirecting with package.
Also make a GET route with same param.
Route::post('/rave/callback', 'RaveController@callback')->name('callback');
I hope it helps.
I am also facing the issue, with the error on the callback method.
Doing:
Route::any(('/rave/callback', 'RaveController@callback')->name('callback');
returns $data
is undefined.
Is there any workaround to implement successful payment?
I am also facing the issue, with the error on the callback method.
Doing:
Route::any(('/rave/callback', 'RaveController@callback')->name('callback');
returns$data
is undefined.
Is there any workaround to implement successful payment?
In your controller action, you should be able to access the response body returned from Rave using request()->resp
//$txref = $request->ref;
//dd($get_ref);
$data = Rave::verifyTransaction($get_ref->tx_ref_id);
//dd($data);
$chargeResponsecode = $data->data->chargecode;
$chargeAmount = $data->data->chargedamount;
$chargeCurrency = $data->data->currency;
$amount = $data->data->amount;
$currency = $data->data->currency;
if (($chargeResponsecode == "00" || $chargeResponsecode == "0") && ($chargeAmount == $amount) && ($chargeCurrency == $currency)) {
// transaction was successful...
// please check other things like whether you already gave value for this ref
// if the email matches the customer who owns the product etc
//Give Value and return to Success page
flash(translate('payment_successful'))->success();
return redirect('/success');
} else {
//Don't Give Value and return to the Failure page
return redirect('/failed');
}
That is how I treat my controller to get back the response from Rave, but you can dump and die this
$data = Rave::verifyTransaction($get_ref->tx_ref_id);
dd($data);
To solve this issue first of all :
change Route::post('/rave/callback', 'RaveController@callback')->name('callback');
to a get method Route::get('/rave/callback', 'RaveController@callback')->name('callback');
and also
change this Route::post( '/pay', 'RaveController@initialize')->name('pay');
//to control error when closing the payment modal without payment successful
To Route::match(['GET', 'POST'], '/pay', 'RaveController@initialize')->name('pay');
public function callback(Request $request){
//now in your callback, to access the response body you can do request()->resp
or $body = $request->resp;
//dump the body
dd($body); viola there you have it, but you might have issue accessing the txRef from this body as it is purely a string so all you have to do is to convert the $body back to json object like:
$obj = json_decode($body,true);
//now lets get the txRef using $obj
$txRef = $obj['data']['data']['txRef'];
//now you have your txRef you can pass it into verification endpoint as a param like so:
$data = Rave::verifyTransaction($txRef); // thats all you are good to
below is the complete working code
public function initialize(Request $request)
{
//This initializes payment and redirects to the payment gateway
//The initialize method takes the parameter of the redirect URL
switch ($request->method()) {
case 'POST':
Rave::initialize(route('callback'));
break;
case 'GET':
return redirect()->route('myaccount.home');
break;
}
}
/**
- Obtain Rave callback information
- @return void
*/
public function callback(Request $request)
{
$obj = json_decode($request->resp,true);
$txRef = $obj['data']['data']['txRef'];
$data = Rave::verifyTransaction($txRef);
$chargeResponsecode = $data->data->chargecode;
$chargeAmount = $data->data->chargedamount;
$chargeCurrency = $data->data->currency;
$amount = $data->data->amount;
$currency = "NGN";
if (($chargeResponsecode == "00" || $chargeResponsecode == "0") && ($chargeAmount == $amount) && ($chargeCurrency == $currency)) {
TransactionsController::getInstance()->storeGh(userID(),1,$amount);
AccountsController::getInstance()->IncreaseUserWallet($amount);
return redirect()->route('myaccount.home');
} else {
//Dont Give Value and return to Failure page
return redirect('transaction.failed');
}
}
}
Here is what works:
public function callback(Request $request)
{
$obj = json_decode($request->resp,true);
$txRef = $obj['data']['tx']['txRef'];
if ($txRef) {
$response = Rave::verifyTransaction($txRef);
$data = $response->data;
$chargeResponsecode = $data->chargecode;
$chargeAmount = $data->amount;
}
else {
redirect()->route('home')->with('error', 'Transaction Failed No Reference');
}
}
This worked for me
{
$resp = json_decode(request()->resp);
$data = Rave::verifyTransaction($resp->tx->txRef);
}
Here is what works:
public function callback(Request $request)
{
$obj = json_decode($request->resp,true);
$txRef = $obj['data']['tx']['txRef'];
if ($txRef) {
$response = Rave::verifyTransaction($txRef);
$data = $response->data;
$chargeResponsecode = $data->chargecode;
$chargeAmount = $data->amount;} else { redirect()->route('home')->with('error', 'Transaction Failed No Reference'); } }
Hey @fredEbho
It's advisable that the data you use for checking if payment was successful should be this
$data = Rave::verifyTransaction($resp->tx->txRef);
// $data