CCAvenue 响应返回 URL 回调中的 Laravel “405 Method Not Allowed”

问题描述

我正在 PHP 7.2 上的 laravel 5.3 中添加 CcAvenue 网关,一切正常,直到 CcAvenue 的付款页面,但付款完成或用户取消付款后,返回响应 URL 显示以下错误

“糟糕!发生错误 服务器返回“405 Method Not Allowed”。 东西坏了。请让我们知道发生此错误时您在做什么。我们会尽快修复它。对造成的任何不便深表歉意。”

我的返回网址是:https://www.domainname.com/booking/cancel/cc_checkout_gateway?c=f4b7d25d6e894a44725fff59adafcf82

路由文件中的代码

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');
});

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);
    }

网关 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('/'));
       }
    }

经过过多的研发,我发现我的路由代码允许方法是 GET & HEAD,但 Ccavenue 响应 URL 以 POST 方法发送响应

我已尝试更改所有可能的解决方案 Route::get('/cancel/{gateway}','BookingController@cancelPayment');

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

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

但之后它显示错误 419:页面已过期

请告诉我如何解决上述问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)