How to include multiple products with diffrent mode in stripe?

Viewed 22

I want a stripe checkout page for subscription but now I want to use same checkout page for subscription mode and payment mode. suppose my subscription is for $99, and user selects $10 as top-up or add-on then I want to add that money also as payment not as subscription, how can I acheive this ? my code for stripe checkout session for subscription is as below.

        sessionObj = {
            mode: "subscription",
            line_items: [
                {
                    price: priceId,
                    quantity: 1,
                }
            ],
            subscription_data: {
                metadata
            },
            metadata,
            success_url: `${Meteor.settings.private.PUBLIC_SITE_URL}/contact-us`,
            cancel_url: `${Meteor.settings.private.PUBLIC_SITE_URL}/payment-failure`,
            payment_method_types: ["card"]
        }
        const stripeRes = await stripe.checkout.sessions.create(sessionObj);
1 Answers

You can combine recurring and non-recurring price with Checkout Sessions in subscription mode. For example you could do this:

const session = await stripe.checkout.sessions.create({
    mode: "subscription",
    line_items: [
        { price: 'price_aaa', quantity: 1 }, // $99 monthly recurring payment
        { price: 'price_bbb', quantity: 1 }, // $10 on time payment
    ],
    success_url: 'http://www.example.com',
    cancel_url: 'http://www.example.com',
});

Here the customer will be charged $109 ($99 + $10) the first month, and then $99 for the following months.

Related