首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel Mollie payment - 419页过期

Laravel Mollie payment - 419页过期
EN

Stack Overflow用户
提问于 2021-06-21 17:18:59
回答 1查看 39关注 0票数 0

我是新来的Mollie API,我正在尝试准备一个新的付款。因此,我有一个具有订单id、订单总数和发票编号的表单。下面是这个表单的代码:

代码语言:javascript
复制
<form action="{{ route('payInvoice') }}" method="POST">
  @csrf
  <input type="text" name="invoice_id" value="{{ $invoice->id }}" hidden>
  <input type="text" name="order_total" value="{{ $order->total_price }}" hidden>
  <input type="text" name="order_number" value="{{ $order->number}}" hidden>
  <button class="btn btn-primary btn-icon icon-left"><i class="fas fa-credit-card"></i> Factuur betalen</button>
</form>

web.php:

代码语言:javascript
复制
Route::post('/pay-invoice', [App\Http\Controllers\MollieController::class, 'preparePayment'])->name('payInvoice');

MollieController preparePayment类:

代码语言:javascript
复制
public function preparePayment(Request $request)
{
    $invoice_id = $request->get('invoice_id');
    $order_total = $request->get('order_total');
    $order_number = $request->get('order_number');
    
    $payment = Mollie::api()->payments()->create([
        'amount' => [
            'currency' => 'EUR',
            'value' =>  $order_total,
        ],
        'description' => 'Betaling voor factuur' . $invoice_id,
        'redirectUrl' => route('showInvoice', 1),
        'webhookUrl'   => route('webhooks.mollie'),
        'metadata' => [
            'order_id' => $order_number,
        ]
    ]);
    
    $payment = Mollie::api()->payments()->get($payment->id);
    
    return redirect($payment->getCheckoutUrl(), 303);
}

当我点击按钮时,我得到一个419页过期的错误。

有谁能帮我吗?

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-21 17:29:54

我认为您需要将showInvoice (重定向url)路由添加到VerifyCsrfToken中间件的$except数组中的异常。

代码语言:javascript
复制
namespace App\Http\Middleware;

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

class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        route('showInvoice'),
    ];
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68065428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档