#Vishakvkt
1 messages ยท Page 1 of 1 (latest)
Hi there ๐ to do this you'll need to pivot to creating Subscriptions rather Payment Intents.
Payment Intents only support one-time payments, but Subscriptions set up recurring payments and allow you to include items that are one-time payments in the Invoice that a Subscription creates.
When you create a Subscription, it will create an Invoice, and that Invoice will generate a Payment Intent that you can use to initialize the Payment Element.
This guide walks through that process:
https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
Thanks for getting back to me quickly! Regarding using the subscriptions api, It wasn't clear to me how to transition the one-off item amounts to the subscription generated payment intent?
My understanding is, there is an items list which contains all subscription products (identified by price_id) the basket contains. Should I be adding the one-off items into this items list?
To note, we currently only work with keeping the payment intent amount up to date and thus, don't/can't model every item we sell in stripe as a product due to volume.
Let me double check that, I don't recall offhand if the one-time items go in items or add_invoice_items.
Found it, add_invoice_items is where the one-time payment items should be placed:
https://stripe.com/docs/billing/invoices/subscription#first-invoice-extra
If you don't have a Price object created for those items, then you can use price_data to create one ad-hoc:
https://stripe.com/docs/api/subscriptions/create#create_subscription-add_invoice_items-price_data
Great!
So, say I add a single invoice item called purchases to add_invoice_items and keep the unit_amount for this price_data, I should be able to keep this amount updated (via update subscriptions) and charge the customer correctly.
What if the customer chooses not to purchase a subscription but just some one-off items? The docs say items is a required property in the create subscription api.
So I assume I can't use the payment intent from the subscription and instead need to fall back on the payment intent only flow?
You shouldn't create the Subscription until you know what it will be created for, the first Invoice will immediately be finalized when you create the Subscription and won't be able to edit it after that.
Yes, if your customer decides to only purchase one-time items, then you'll need to pivot back to a Payment Intent instead of a Subscription. To me it sounds like it would be easiest if you tracked the customer's cart state on your end, and then start creating Stripe objects once it's confirmed what the customer will be buying.
I understand. This is what I was afraid off i.e. needing to maintain both payment intent and subscription based workflows based on the state of the basket.
Thanks for all your input. Let me investigate more on my end ๐
Any time!