Laravel 中的未知状态 419 payfast 通知 url

Nav*_*Ali -1 php callback payment-gateway notify laravel

我正在尝试将 PayFast 支付网关集成到我的 laravel 应用程序中,但收到 419 错误,我认为这很奇怪,下面是代码。

我已经按照 PayFast 文档中的方式配置了所有内容,并且在 ngrok 和通知 url 上检查它,我收到 419 未知状态,我不知道我缺少什么。请查看我的代码并让我知道我缺少什么。

PayFast 表单视图

<form target="_blank" action="https://sandbox.payfast.co.za/eng/process" method="POST">
    <input type="hidden" name="merchant_id" value="10015150">
    <input type="hidden" name="merchant_key" value="aaid6ctdo8lxz">
    <input type="hidden" name="custom_str1" value="{{$business->id}}">
    <input type="hidden" name="amount" value="200.00">
    <input type="hidden" name="name_first" value="">
    <input type="hidden" name="name_last" value="">
    <input type="hidden" name="email_address" value="">
    <input type="hidden" name="cell_number" value="0823456789">
    <input type="hidden" name="item_name" value="Making your business Featured on our Website">
    <input type="hidden" name="return_url" value="http://95d16c17.ngrok.io/return">
    <input type="hidden" name="cancel_url" value="http://95d16c17.ngrok.io/cancel">
    <input type="hidden" name="notify_url" value="http://95d16c17.ngrok.io/notify">
    <button type="submit" title="You will have to pay to make your business featured" class="btn btn-primary">Make Business Featured</button>
</form>
Run Code Online (Sandbox Code Playgroud)

网页.php

Route::post('notify','HomeController@updatedBusiness');
Run Code Online (Sandbox Code Playgroud)

家庭控制器

public function updatedBusiness(Request $request){
    header('HTTP/1.0 200 OK');
    flush();
    $business = Business::find($request->get('custom_str1'));
    $business->featured_business = 1;
    $business->save();
    return 'success';
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激。

Nav*_*Ali 5

这是 csrf 的问题,因为 laravel 在每个路由上应用了 verifyCsrfToken 中间件,当 PayFast 在通知 URL 上发回 POST 请求时,Laravel 会像评论中提到的 @delboy1978uk 那样哭泣。在VerifyCsrfToken中间件中禁用它可以达到以下目的

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

 class VerifyCsrfToken extends Middleware
{
    /**
     * Indicates whether the XSRF-TOKEN cookie should be set on the response.
     *
     * @var bool
     */
    protected $addHttpCookie = true;

    /**
    * The URIs that should be excluded from CSRF verification.
    *
    * @var array
    */
    protected $except = [
     'notify',
    ];
}
Run Code Online (Sandbox Code Playgroud)