Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

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 IlluminateSupportFacadesRoute;
// 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 = GuzzleHttpjson_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.

question from:https://stackoverflow.com/questions/66058943/laravel-405-method-not-allowed-on-ccavenue-response-return-url-callback

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...