Josh Bolton
Josh Bolton

Reputation: 768

Express Checkout without Payment Methods

We have a payment flow whereby a payment intent is created with the following options

$options = [
            'customer'                  => $stripeCustomerId,
            'amount'                    => $amount,
            'currency'                  => 'gbp',
            'automatic_payment_methods' => [
                'enabled' => 'true',
            ],
        ];

We then present our customers with a payment form which utilises both Stripe Elements (for card payments) And Express Checkout (For GPay/Apple Pay).

Stripe elements works fine, and is fully functional. However, when adding in express checkout, and trying the payment flow, the following error is returned from Stripe: You cannot confirm this PaymentIntent because it's missing a payment method. To confirm the PaymentIntent with CUSTOMER_ID, specify a payment method attached to this customer along with the customer ID.

We instantiate express checkout as follows:

const expressCheckoutOptions = {
            buttonType: {
                applePay: 'order',
                googlePay: 'order',
            },
            layout: {
                maxColumns: 1,
            }
        }

        expressElements = stripe.elements({
            mode: 'payment',
            amount: Number(window.payment.payment_amount),
            currency:'gbp',
        });

        const expressCheckoutElement = expressElements.create('expressCheckout', expressCheckoutOptions)
        expressCheckoutElement.mount('#express-checkout');

And then we confirm the payment like so:

expressCheckoutElement.on('confirm', async (event) => {
            const {error: submitError} = await expressElements.submit();
            if (submitError) {
                showMessage(submitError.message);
                return;
            }

            let clientSecret = 'Our Client Secret'
            const {error} = await stripe.confirmPayment({
                expressElements,
                clientSecret,
                confirmParams: {
                    return_url: window.location.href,
                },
                redirect: 'if_required',
            });

            if (error) {
                showMessage(error.message);
            } else {
                console.log('Payment confirmation successful!');
            }
        });
    }

This integration is taken moreorless verbatim from the Stripe docs, however, the error mentioned above is thrown. Any help is greatly appreciated!

Here is a link to the Stripe Express Checkout documentation https://docs.stripe.com/checkout/one-click-payment-buttons?payment-ui=embedded-components

Code has been snippeted for privacy

Upvotes: 0

Views: 25

Answers (0)

Related Questions