1

Firebase, Stripe extension integration.

I have one product on Stripe, and two recurring prices (subscription options)

The problem is appearing when I try to add yearly and monthly subscription options, in line-items, before that I used one subscription option it was sent via the "price" param.

Now When I want to send two subscription prices for the same product on the stripe side, I cannot generate the stripe checkout session... cus "payload" is not good.

This is the code that generated the checkout session.

  • I created a product on stripe
  • Created two recurring prices
  • Take those IDs and included them in line-items
  • as the Response checkout session is not created

Note: If I remove line-items and include just one price, and send it with "price: priceId" it works

const checkoutSessionRef = collection(
      firestore,
      `users/${uid}/checkout_sessions`,
    );
    const docData = {
      success_url: url,
      cancel_url: url,
    
      line_items: [
        {
          price: montlyPriceId,
          quantity: 1,
        },
        {
          price: yearlyPriceId,
          quantity: 1,
        },
      ],
    };
}

    await addDoc(checkoutSessionRef, docData);

Documentation explanation on including multiple subscription options in checkout sessions:

enter image description here

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mark James
  • 338
  • 4
  • 15
  • 43

1 Answers1

1

You can’t use 2 recurring prices with different billing periods - e.g. annual and monthly - in a single Subscription. You can only combine prices that have the same billing periods - e.g. both monthly, or both annual. If you want the same Customer to have both monthly and annual subscriptions, you will need to create 2 separate Subscriptions, or, in your case, two Checkout Sessions.

vanya
  • 228
  • 4
  • How to create two different checkout sessions? two trigger twice the same API for checkout session? – Mark James May 24 '23 at 12:10
  • Yes. What's your use case? Why you need both Prices for the same Customer? – vanya May 24 '23 at 12:59
  • I created two sessions, but still the same result, I got just one option to select. Could you pls give me an example in code? The use case is a yearly or monthly subscription: 10$ or 100$ for accessing the website and using the features. – Mark James May 24 '23 at 13:07
  • Do you want your customers to choose between monthly and annual? Or do you want one customer to have both? – vanya May 25 '23 at 14:05
  • I want customers on the stripe checkout UI, to have the option to choose a monthly or annual subscription... – Mark James May 25 '23 at 22:42
  • 1
    Checkout doesn't allow choosing the plan on the page itself. You will have to ask the customers to choose the plan on your website and then you will redirect them to a Checkout Session with the appropriate Price ID. You can consider using Pricing Table as well: https://stripe.com/docs/payments/checkout/pricing-table – vanya May 26 '23 at 15:18