Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I include a CSRF token with the Affirm Confirmation URL?

Using Laravel, I have added Affirm and in my affirm.checkout data, I have the user_confirmation_url set to go to a route that specifically processes Affirm orders:

affirm.checkout({
        "merchant": {
            "user_confirmation_url": "http://127.0.0.1:8000/affirm-order",
            ...

When a request is made to that URL, I get a 419 error because there is no CSRF token.

How can I include a csrf token to that url?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried adding @csrf to the page, and making the url "user_confirmation_url": "http://127.0.0.1:8000/affirm-order?token={{csrf_token()}}",, but that didn’t work.

>Solution :

If http://127.0.0.1:8000/affirm-order is the url the checkout service must call when it is done, then it has no way of knowing the correct CSRF token. You must add an exception for that particular endpoint in the VerifyCsrfToken Middleware.

<?php

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<int, string>
     */
    protected $except = [
        'affirm-order',
    ];
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading