jeudi 4 février 2021

Laravel "405 Method Not Allowed" on CCAvenue response return URL callback

I am adding CcAvenue gateway in laravel 5.3 on PHP 7.2, everything working fine till the payment page of CcAvenue, but after payment is done or payment canceled by the user, the return response URL is showing the following error

"Oops! An Error Occurred The server returned a "405 Method Not Allowed". Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused."

My return URL is this: https:// www.domainname.com/booking/cancel/cc_checkout_gateway?c=f4b7d25d6e894a44725fff59adafcf82

Code in the Routes file

use Illuminate\Support\Facades\Route;
// Booking
Route::group(['prefix'=>config('booking.booking_route_prefix')],function(){
    Route::post('/addToCart','BookingController@addToCart');
    Route::post('/doCheckout','BookingController@doCheckout')->name('booking.doCheckout');
    Route::get('/confirm/{gateway}','BookingController@confirmPayment');
    Route::get('/cancel/{gateway}','BookingController@cancelPayment');
    Route::get('/{code}','BookingController@detail');
    Route::get('/{code}/checkout','BookingController@checkout');
    Route::get('/{code}/check-status','BookingController@checkStatusCheckout');

    //ical
    Route::get('/export-ical/{type}/{id}','BookingController@exportIcal')->name('booking.admin.export-ical');
    //inquiry
    Route::post('/addEnquiry','BookingController@addEnquiry');
});
Route::group(['prefix'=>'gateway'],function(){
    Route::get('/confirm/{gateway}','NormalCheckoutController@confirmPayment')->name('gateway.confirm');
    Route::get('/cancel/{gateway}','NormalCheckoutController@cancelPayment')->name('gateway.cancel');
    Route::get('/info','NormalCheckoutController@showInfo')->name('gateway.info');
});

Code in BookingController.php

 public function cancelPayment(Request $request, $gateway)
    {

        $gateways = get_payment_gateways();
        if (empty($gateways[$gateway]) or !class_exists($gateways[$gateway])) {
            return $this->sendError(__("Payment gateway not found"));
        }
        $gatewayObj = new $gateways[$gateway]($gateway);
        if (!$gatewayObj->isAvailable()) {
            return $this->sendError(__("Payment gateway is not available"));
        }
       
        return $gatewayObj->cancelPayment($request);
    }

Code in Gateway CcCheckoutGateway.php

public function cancelPayment(Request $request)
    {
        
        
        $c = $request->query('c');
        $booking = Booking::where('code', $c)->first();
        
        if (!empty($booking) and in_array($booking->status, [$booking::UNPAID])) {
            $payment = $booking->payment;
            
            if ($payment) {
                $payment->status = 'cancel';
                $payment->logs = \GuzzleHttp\json_encode([
                    'customer_cancel' => 1
                ]);
                
                $payment->save();

                // Refund without check status
                $booking->tryRefundToWallet(false);
            }
           
           return redirect($booking->getDetailUrl())->with("error", __("You cancelled the payment"));
        }
        
        if (!empty($booking)) {
            return redirect($booking->getDetailUrl());
       } else {
           return redirect(url('/'));
       }
    }

After too much R&D I found that my routes code is allowing method is GET & HEAD, but Ccavenue response URL is sending the response in POST method

I have tried every possible solution changed Route::get('/cancel/{gateway}','BookingController@cancelPayment');

to Route::post('/cancel/{gateway}','BookingController@cancelPayment');

and Route::any('/cancel/{gateway}','BookingController@cancelPayment');

but after that it showing error 419: page expired

Please tell me how can I resolve the above issue.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3oJRxjW
via IFTTT

Aucun commentaire:

Enregistrer un commentaire