最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Stripe Express Checkout Element for Subscriptions is not appearing? - Stack Overflow

programmeradmin5浏览0评论

Here is my code based on the documentation


        const appearance = {
            theme: 'stripe',
            variables: {
                borderRadius: '36px',
            },
        };
        const expressCheckoutOptions = {
            buttonHeight: 50,
            buttonType: {
                applePay: 'buy',
                googlePay: 'buy',
                paypal: 'checkout',
                klarna: 'pay',
            },
        };
        const elements = stripe.elements({
            mode: 'payment',
          //  mode: 'subscription', DOES NOT WORK despite documentation saying it does?
            amount: amount * 100, // Convert to smallest currency unit
            currency: currency,
            appearance,
        });
        const expressCheckoutElement = elements.create('expressCheckout', expressCheckoutOptions);
        expressCheckoutElement.mount(mountElementId);

It does not work if I change mode to subscription. Im not sure why. The element will not be created and it will return an empty element. However with payment, I can see my express checkout, like so:

Here is my code based on the documentation https://docs.stripe/elements/express-checkout-element/accept-a-payment#additional-options


        const appearance = {
            theme: 'stripe',
            variables: {
                borderRadius: '36px',
            },
        };
        const expressCheckoutOptions = {
            buttonHeight: 50,
            buttonType: {
                applePay: 'buy',
                googlePay: 'buy',
                paypal: 'checkout',
                klarna: 'pay',
            },
        };
        const elements = stripe.elements({
            mode: 'payment',
          //  mode: 'subscription', DOES NOT WORK despite documentation saying it does?
            amount: amount * 100, // Convert to smallest currency unit
            currency: currency,
            appearance,
        });
        const expressCheckoutElement = elements.create('expressCheckout', expressCheckoutOptions);
        expressCheckoutElement.mount(mountElementId);

It does not work if I change mode to subscription. Im not sure why. The element will not be created and it will return an empty element. However with payment, I can see my express checkout, like so:

Share Improve this question asked Mar 26 at 6:03 Matthew FrancisMatthew Francis 7403 gold badges11 silver badges27 bronze badges 1
  • What is the issue you are facing when passing subscription as a mode ? Can you share the error message you got ? – os4m37 Commented Mar 26 at 8:18
Add a comment  | 

1 Answer 1

Reset to default 0

you can do it like this

first Set Up the Elements Instance for Subscriptions

    mode: 'setup',
    amount: amount * 100,
    currency: currency,
    appearance,
});

Create and Mount the Express Checkout Element

const expressCheckoutElement = elements.create('expressCheckout', expressCheckoutOptions);
expressCheckoutElement.mount(mountElementId);

then Handle the Confirmation Event

    const { error: submitError } = await elements.submit();
    if (submitError) {
        handleError(submitError);
        return;
    }
    
    const { error, paymentMethod } = await stripe.createPaymentMethod({
        elements,
        params: {
            billing_details: event.billingDetails,
        },
    });
    if (error) {
        handleError(error);
        return;
    }
    // Use the paymentMethod.id to create a subscription on your server
});
发布评论

评论列表(0)

  1. 暂无评论