#dheepsandy_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1250524309500198939
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
Hi, you would need to create separate subscriptions as you can't have one subscription with different billing intervals. So you would have one yearly subscription and a monthly subscription. As you mentioned, the monthly subscription works as expected. On the yearly subscription, if you want to charge one-time upfront fee, you can add a one-time invoice item, https://docs.stripe.com/api/subscriptions/create#create_subscription-add_invoice_items on the yearly subscription on top of the metered usage pricing. I highly recommend that you test this using Stripe Test Clock, https://docs.stripe.com/billing/testing/test-clocks which is a tool that helps you simulate the forward movement of time in test mode.
Hi, Yes, I have implemented separate subscriptions for monthly and yearly. Monthly works as expected. When creating Yearly invoice, i am adding Upfront Invoice Item to get upfront payment.
Can you add more details here on what exactly is not working as expected on the yearly subscription with the one time invoice item?
This is how it shows up in stripe dashboard
Issues: invoice status is "incomplete" and unable to set quantity for upfront user count
invoice is open, even after setting 'autoadvance' true, it says auto collection is off
in_1PQweVRqKBJVF46JlepBN2WT
fyi, my account is still in TEST mode
Taking a look here
The issue here is that you need to add a payment method. You can set one of the payment methods attached to the customer as the default payment method on the customer so it can be charged automatically.
okay, i will try it.
I added this line, but it didn't work
in_1PQx05RqKBJVF46JAmsS6a84
๐ stepping in here and taking a look
along with setupIntent, should i be creating a paymentIntent and use its paymentMethodId?
Okay sorry was just getting caught up
So why are you creating an Invoice here?
You shouldn't be doing that
Let's pause for one moment though
When you create this Subscription, are you also going to be collecting the payment method at that time or will you have already collected it in the past? Or could both occur?
okay, let me explain everything i have
client: on the website i am mounting stripe's payment element, on submit button click, server: i am creating a new customer and also creating a setupintent and sending back the setupIntent.clientsecret back to client
using this secret, i am calling confirmSetup from client and on success i am trying to create a subscription
Yeah so instead of doing that the Subscription itself will generate a PaymentIntent or SetupIntent that you should be using here.
And if the initial Invoice is $0 then instead of using the latest_invoice.payment_intent.client_secret you use the pending_setup_intent.client_secret
Little confused
for monthly, i need stripe.confirmSetup to setup customer with monthly price and charge customer after one month
for yearly, i need customer to pay upfront fee and also need to setup yearly subscription to charge customer after one year
to get upfront free, i added that invoiceItem only for yearly subscription
yes, there is no payment, that's why i haven't called stripe.confirmPayment, instead i am calling stripe.confirmSetup
So when you create the Subscription, it will generate a pending_setup_intent: https://docs.stripe.com/api/subscriptions/object#subscription_object-pending_setup_intent
Instead of creating a separate SetupIntent, you should be using the one that is returned from the Subscription creation.
When you create the Subscription you also set payment_settings.save_default_payment_method: https://docs.stripe.com/api/subscriptions/create#create_subscription-payment_settings-save_default_payment_method
Then when you call confirmSetup() using the SetupIntent returned by the Subscription itself the collected PaymentMethod will be set as the default on the Subscription for future payments
i am doing it the other way, first doing the createsetupIntent and confirmSetupIntent. if successful, only then i am creating the subscription using this code
To avoid fake customers from creating subscriptions, i have to make sure that confirmIntent returns success first by validating payment information from the payment-element mounted on the page
Alright, that isn't the recommended route as it can lead to duplicate authorizations/3DS but if you want to go that way then that's fine.
Overall to solve your issue you want to use payment_behavior: allow_incomplete when you create your Subscription and you set default_payment_method with the PaymentMethod from your SetupIntent.
That will result in an immediate initial charge attempt when you create your Subscription
Thank you sir, i will look into your suggestions.