Hi folks, I was integrating FLutterwave on my laravel app, on the process i found a bunch of errors while trying to use it accept payment on my site. Have been a Paystack heavy user but decided to use Flutterwave for a reason that I love to do. Going through this article I will list the two types of error or bug that you must encounter while using Laravel Rave steps to get Flutterwave payment working.
Types of error
- Error on the payment page when user try to refresh the page without making payment
- Error when a user successfully made the payment but you have callback issues
How to fix this two type of errors
First error Fixed -> Error on the payment page when user try to refresh the page without making paymment
Your laravel Rave route for making payment is below:
Route::post('/pay', 'RaveController@initialize')->name('pay');
The error you will get when user refresh the payment page without making a payment is below:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: POST.
The GET method is not supported for this route. Supported methods: POST.
You get this error because your pay route is a post method
Solved error
You can solve this error by using matching route or create separate GET and POST route, where get route will redirect your user back to pay now button, but I choose to use match method in which user has to go back and click pay now button again because Flutterwave wouldn't see those post credential again., code below is for matching when the route have GET or POST method without showing a user those ugly codes
Route::match(['GET', 'POST'],'/pay', 'PaymentController@initialize')->name('pay');
Second error Fixed -> Error when a user successfully made the payment but you have callback issues
This second error is when the user has successfully made payment whether success or not but you the developer want to do something with the returned data.
Default Laravel Rave callback route
Route::post('/rave/callback', 'RaveController@callback')->name('callback');
Error screen below:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: POST.
http://127.0.0.1:4000/rave/callback?resp=%7B%22name%22%3A%22vbvcomplete%22%2C%22data%22%3A%7B%22transactionobject%22%3A%7B%22id%22%3A1441931%2C%22txRef%22%3A%22rave_5f246d0cb9dac%22%2C%22orderRef%22%3A%22URF_1596222756471_8337635%22%2C%22flwRef%22%3A%22FLW-MOCK-2aa82bc680c707b438cf9d2be8d30871%22%2C%22redirectUrl%22%3A%22http%3A%2F%2F127.0.0.1%3A4000%2Frave%2Fcallback%22%2C%22device_fingerprint%22%3A%22e5b87fff9ee84c0a929bf1e9fa408bb2%22%2C%22settlement_token%22%3Anull%2C%22cycle%22%3A%22one-time%22%2C%22amount%22%3A19.9999999999998%2C%22charged_amount%22%3A20%2C%22appfee%22%3A0.76%2C%22merchantfee%22%3A0%2C%22merchantbearsfee%22%3A1%2C%22chargeResponseCode%22%3A%2200%22%2C%22raveRef%22%3A%22RV3159622275508265EAA00C0E%22%2C%22chargeResponseMessage%22%3A%22Please%20enter%20the%20OTP%20sent%20to%20your%20mobile%20number%20080%2A%2A%2A%2A%2A%2A%20and%20email%20te%2A%2A%40rave%2A%2A.com%22%2C%22authModelUsed%22%3A%22VBVSECURECODE%22%2C%22currency%22%3A%22USD%22%2C%22IP%22%3A%22105.112.99.180%22%2C%22narration%22%3A%22CARD%20Transaction%20%22%2C%22status%22%3A%22successful%22%2C%22modalauditid%22%3A%22f90383b37b6e0e4194c6bb6f5573e0d2%22%2C%22vbvrespmessage%22%3A%22Approved.%20Successful%22%2C%22authurl%22%3A%22https%3A%2F%2Fravesandboxapi.flutterwave.com%2Fmockvbvpage%3Fref%3DFLW-MOCK-2aa82bc680c707b438cf9d2be8d30871%26code%3D00%26message%3DApproved.%20Successful%26receiptno%3DRN1596222756556%22%2C%22vbvrespcode%22%3A%2200%22%2C%22acctvalrespmsg%22%3Anull%2C%22acctvalrespcode%22%3A%22RN1596222756556%22%2C%22paymentType%22%3A%22card%22%2C%22paymentPlan%22%3A1%2C%22paymentPage%22%3Anull%2C%22paymentId%22%3A%226527778%22%2C%22fraud_status%22%3A%22ok%22%2C%22charge_type%22%3A%22normal%22%2C%22is_live%22%3A0%2C%22retry_attempt%22%3Anull%2C%22getpaidBatchId%22%3Anull%2C%22createdAt%22%3A%222020-07-31T19%3A12%3A36.000Z%22%2C%22updatedAt%22%3A%222020-07-31T19%3A12%3A46.000Z%22%2C%22deletedAt%22%3Anull%2C%22customerId%22%3A432208%2C%22AccountId%22%3A154719%2C%22customer%22%3A%7B%22id%22%3A432208%2C%22phone%22%3A%22%2B2348137140110%22%2C%22fullName%22%3A%22Kizito%20Adike%22%2C%22customertoken%22%3Anull%2C%22email%22%3A%22adikekizinho%40gmail.com%22%2C%22createdAt%22%3A%222020-07-31T19%3A12%3A35.000Z%22%2C%22updatedAt%22%3A%222020-07-31T19%3A12%3A35.000Z%22%2C%22deletedAt%22%3Anull%2C%22AccountId%22%3A154719%7D%2C%22chargeToken%22%3A%7B%22user_token%22%3A%22af107%22%2C%22embed_token%22%3A%22flw-t0-2d8204278bcb83865eedfbccc21980f1-m03k%22%7D%2C%22airtime_flag%22%3Afalse%7D%2C%22name%22%3A%22vbvcomplete%22%2C%22data%22%3A%7B%22status%22%3A%22successful%22%2C%22txRef%22%3A%22rave_5f246d0cb9dac%22%2C%22amount%22%3A%2219.9999999999998%22%7D%2C%22respcode%22%3A%2200%22%2C%22respmsg%22%3A%22Approved.%20Successful%22%7D%2C%22respcode%22%3A%2200%22%2C%22tx%22%3A%7B%22id%22%3A1441931%2C%22txRef%22%3A%22rave_5f246d0cb9dac%22%2C%22orderRef%22%3A%22URF_1596222756471_8337635%22%2C%22flwRef%22%3A%22FLW-MOCK-2aa82bc680c707b438cf9d2be8d30871%22%2C%22redirectUrl%22%3A%22http%3A%2F%2F127.0.0.1%3A4000%2Frave%2Fcallback%22%2C%22device_fingerprint%22%3A%22e5b87fff9ee84c0a929bf1e9fa408bb2%22%2C%22settlement_token%22%3Anull%2C%22cycle%22%3A%22one-time%22%2C%22amount%22%3A19.9999999999998%2C%22charged_amount%22%3A20%2C%22appfee%22%3A0.76%2C%22merchantfee%22%3A0%2C%22merchantbearsfee%22%3A1%2C%22chargeResponseCode%22%3A%2200%22%2C%22raveRef%22%3A%22RV3159622275508265EAA00C0E%22%2C%22chargeResponseMessage%22%3A%22Please%20enter%20the%20OTP%20sent%20to%20your%20mobile%20number%20080%2A%2A%2A%2A%2A%2A%20and%20email%20te%2A%2A%40rave%2A%2A.com%22%2C%22authModelUsed%22%3A%22VBVSECURECODE%22%2C%22currency%22%3A%22USD%22%2C%22IP%22%3A%22105.112.99.180%22%2C%22narration%22%3A%22CARD%20Transaction%20%22%2C%22status%22%3A%22successful%22%2C%22modalauditid%22%3A%22f90383b37b6e0e4194c6bb6f5573e0d2%22%2C%22vbvrespmessage%22%3A%22Approved.%20Successful%22%2C%22authurl%22%3A%22https%3A%2F%2Fravesandboxapi.flutterwave.com%2Fmockvbvpage%3Fref%3DFLW-MOCK-2aa82bc680c707b438cf9d2be8d30871%26code%3D00%26message%3DApproved.%20Successful%26receiptno%3DRN1596222756556%22%2C%22vbvrespcode%22%3A%2200%22%2C%22acctvalrespmsg%22%3Anull%2C%22acctvalrespcode%22%3A%22RN1596222756556%22%2C%22paymentType%22%3A%22card%22%2C%22paymentPlan%22%3A1%2C%22paymentPage%22%3Anull%2C%22paymentId%22%3A%226527778%22%2C%22fraud_status%22%3A%22ok%22%2C%22charge_type%22%3A%22normal%22%2C%22is_live%22%3A0%2C%22retry_attempt%22%3Anull%2C%22getpaidBatchId%22%3Anull%2C%22createdAt%22%3A%222020-07-31T19%3A12%3A36.000Z%22%2C%22updatedAt%22%3A%222020-07-31T19%3A12%3A46.000Z%22%2C%22deletedAt%22%3Anull%2C%22customerId%22%3A432208%2C%22AccountId%22%3A154719%2C%22customer%22%3A%7B%22id%22%3A432208%2C%22phone%22%3A%22%2B2348137140110%22%2C%22fullName%22%3A%22Kizito%20Adike%22%2C%22customertoken%22%3Anull%2C%22email%22%3A%22adikekizinho%40gmail.com%22%2C%22createdAt%22%3A%222020-07-31T19%3A12%3A35.000Z%22%2C%22updatedAt%22%3A%222020-07-31T19%3A12%3A35.000Z%22%2C%22deletedAt%22%3Anull%2C%22AccountId%22%3A154719%7D%2C%22chargeToken%22%3A%7B%22user_token%22%3A%22af107%22%2C%22embed_token%22%3A%22flw-t0-2d8204278bcb83865eedfbccc21980f1-m03k%22%7D%2C%22airtime_flag%22%3Afalse%7D%2C%22respmsg%22%3A%22Approved.%20Successful%22%7D
How to fix these error
changing callback from post to get
Route::get('/rave/callback', 'PaymentController@callback')->name('callback');
Now you wouldn't be able to get those data from flutterwave because this will return null, you have to do something on your callback function
default laravel Rave callback function
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Rave;
class PaymentController extends Controller {
public function initialize() {
Rave::initialize(route('callback'));
}
public function callback() {
$data = Rave::verifyTransaction(request()->txref);
dd($data);
}
}
Now you have to modify it to be able to receive the payment data's
code below
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Rave;
class PaymentController extends Controller {
public function initialize() {
Rave::initialize(route('callback'));
}
public function callback(Request $request) {
$resp = $request->resp;
$body = json_decode($resp, true);
$txRef = $body['data']['data']['txRef'];
$data = Rave::verifyTransaction($txRef);
dd($data);
}
}
After that, you now get those datas and do something, love this buy me a beer
Davis
Please help me mine keeps returning invalid pubick key passed. But I am very very sure of my public key it just seems the package cannot reach the .env parameters. I use laravel 7
kizinho
No you might have made some mistake, let me see your .env
Davis
Please help me mine keeps returning invalid pubick key passed. But I am very very sure of my public key it just seems the package cannot reach the .env parameters. I use laravel 7
ucee Tony
Nice one Odogwu... U Are doing well
kizinho
Thank you sir and enjoy , have just love flutterwave , easily accept any currency