#zzawaideh-react-upgrade
1 messages ยท Page 1 of 1 (latest)
Hey guys
@fallow cedar Stripe API allows you to do a recurring payment
the one time charge uses PaymentElement
Ah okay and you expect to always collect the one-time first ahead of upgrading to the recurring Subscription?
So the business model is that customers can buy an online product one time (I already have this part). Or they can get a premium plan and get unlimited free products
And the premium is monthly, correct?
Yes
Okay cool. So you'll want to integrate two flows.
Yes
First, for your one-time payment, you will want to make a couple changes.
@ashen sphinx isn't it easier to have just different code for the reccuring one?
You will want to follow https://stripe.com/docs/payments/save-during-payment and create a Customer and use setup_future_usage for the PaymentIntent so the PaymentMethod is ready for a future upgrade to a Subscription.
Then, you will also want to build out the flow we describe here: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
If you already have the Customer and PaymentMethod then you can just create the Subscription, but if you don't have either of those yet then you will need the whole Subscription flow.
Just as a side note, if it gets too complicated, you can just have the customer pay every month manually using the one time payment way
app.post('/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: 'T-shirt',
},
unit_amount: 2000,
},
quantity: 1,
},
],
mode: 'payment',
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
});
res.redirect(303, session.url);
});
Can I use this to allow a subscription purchase?
You can use Stripe Checkout if you prefer โ you would use mode: 'subscription'.
However, if you already have Payment Element implemented then it seems a bit odd you would want to use Checkout.
They are for two different types of purchases
That is why
Is that bad?
This is my first time using stripe, so I may not know what is right
I mean it is fine from the Stripe side of things. Just a little weird you would want to include a redirect as well as an embedded flow on your website.
But that is up to you.
Oh okay, thank you.
I am getting the following error: You must provide at least one recurring price in subscription mode when using
prices.
Does the "unit_amount" not suffice for the price?
You need to set line_items.price_data.recurring as well: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-recurring
The interval indicates how it should recur
What purpose does this data serve?
It determines whether it is a daily/weekly/monthly/annual sub
๐
Yep that looks good to me.
Best thing to do is to test it ๐
Also, since you are starting to work with Subscriptions, you may want to look into using Test Clocks (https://stripe.com/docs/billing/testing/test-clocks) to do full testing.