Home > Enterprise >  Stripe Payment element show saved card
Stripe Payment element show saved card

Time:06-17

I am using laravel with stripe payment element. I am trying to show the saved cards for the customers that we already have. I have followed the enter image description here

When authenticating with an ephemeral key, you must set the Stripe-Version header to an explicit API version, such as 2020-08-27

I have checked and changed lot of versions from here:

$ephemeralKey = \Stripe\EphemeralKey::create(
                    ['customer' => "$user->stripe_customer_id"],
                    ['stripe_version' => '2019-11-05']
                );

I changed the version to different version that I can see on my stripe dashboard:

enter image description here

This is my Js Initialize function:

    // Fetches a payment intent and captures the client secret
async function initialize() {
    // Customize the appearance of Elements using the Appearance API.
    const appearance = { /* ... */ };

    // Enable the skeleton loader UI for the optimal loading experience.
    const loader = 'auto';
    const { clientSecret, customerOptions } = await fetch("{{ route("user-create-stripe-element-payment") }}", {
        method: "POST",
        headers: {
            "Content-Type" : "application/json",
            "accept" : "application/json",
            'X-CSRF-TOKEN': "{{ csrf_token() }}",
            'stripe_version':"2019-11-05"
        },
        body: JSON.stringify({ totalCharge:total }),
    }).then((r) => r.json());

    elements = stripe.elements({
        clientSecret,
        appearance,
        loader,
        customerOptions
    });

    const paymentElement = elements.create("payment");
    paymentElement.mount("#payment-element");
}

And I am also using the betas which is given in the documentation:

    const stripe = Stripe("{{env('STRIPE_KEY')}}", {
    betas: ['elements_customers_beta_1'],
});

But this error is not going away. And its not even populating the Payment element.

Please help me debug this or if someone has any suggestion to check what is going on here.

Thanks in advance.

CodePudding user response:

You are not providing an API version in your JS here

const stripe = Stripe("{{env('STRIPE_KEY')}}", {
    betas: ['elements_customers_beta_1'],
});

change the above code to

const stripe = Stripe("{{env('STRIPE_KEY')}}", {
    betas: ['elements_customers_beta_1'],
    apiVersion: 'Your Version Here'
});

In your case, it should be something like this

const stripe = Stripe("{{env('STRIPE_KEY')}}", {
    betas: ['elements_customers_beta_1'],
    apiVersion: '2019-11-05'
});

You can read more here. https://stripe.com/docs/api/versioning?lang=node It is for nodejs but the API version override will work in the same way.

  • Related