我是新来的Mollie API,我正在尝试准备一个新的付款。因此,我有一个具有订单id、订单总数和发票编号的表单。下面是这个表单的代码:
<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:
Route::post('/pay-invoice', [App\Http\Controllers\MollieController::class, 'preparePayment'])->name('payInvoice');MollieController preparePayment类:
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页过期的错误。
有谁能帮我吗?
提前谢谢。
发布于 2021-06-21 17:29:54
我认为您需要将showInvoice (重定向url)路由添加到VerifyCsrfToken中间件的$except数组中的异常。
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'),
];
}https://stackoverflow.com/questions/68065428
复制相似问题