The GET method is not supported for this route. Supported methods: POST on Flutterwave implementation with laravel

139 Views Asked by At

I am implementing Flutterwave implementation as found on Medium but I am getting the error:

The GET method is not supported for this route. Supported methods: POST. http://localhost:8000/rave/callback?resp=%7B%22name%22%3A%22opop%22%2C%22data%22%3A%7B%22data%22%3A%7B%22responsecode%22%3A%2200%22%2C%22responsetoken%22%3Anull%2C%22responsemessage%22%3A%22successful%22%7D%2C%22tx%22%3A%7B%22id%22%3A2424493%2C%22txRef%22%3A%22rave_611fc5fe12df9%22%2C%22orderRef%22%3A%22URF_1629472286526_3670035%22%2C%22flwRef%22%3A%22FLW-MOCK-44b7ecdb3a2183c971db03d669dc1554%22%2C%22redirectUrl%22%3A%22http%3A%2F%2Flocalhost%3A8000%2Frave%2Fcallback%22%2C%22device_fingerprint%22%3A%22888b449800a5003eaf1eeea02d5d52db%22%2C%22settlement_token%22%3_

I am implementing Post routes as shown in:

Route::post('/pay', 'RaveController@initialize')->name('pay');
Route::post('/rave/callback', 'RaveController@callback')->name('callback');

And on my controller, I've got:

public function initialize() {
    //This initializes payment and redirects to the payment gateway
    //The initialize method takes the parameter of the redirect URL
    Rave::initialize(route('callback'));
}

/**
 * Obtain Rave callback information
 * @return void
 */
public function callback() {
    $data = Rave::verifyTransaction(request()->txref);
    dd($data);  // view the data response
    if ($data->status == 'success') {
        //do something to your database
    } else {
        //return invalid payment
    }
}

Please can anyone help me solve this problem? Especially since changing the route to get returns null. Thanks a whole lot!

2

There are 2 best solutions below

0
On

that's because of you are calling the route again here that is mean you will go to this direction with get method

public function initialize(){
 
  Rave::initialize(route('callback'));
}

the best solution to you you have to call this function without routing it as following

public function initialize(Request $request){
      //here now you will not routing with get you will call the function inside it
      Rave::initialize($this->callback($request->all()));
    }
  /**
     * Obtain Rave callback information
     * @return void
     */public function callback($request){
  $data = Rave::verifyTransaction($request->txref);
  dd($data);  // view the data response
        if ($data->status == 'success') {
            
  //do something to your database
  }
  else {
  //return invalid payment
  }
  }
0
On

I suppose Route::post('/rave/callback', 'RaveController@callback')->name('callback'); Is your problem. It should be Route::get

Hi. I am sorry for editing this directly as I cant find the reply button. Route::get() returns null for this particular implementation.