#dheepsandy_api

1 messages ยท Page 1 of 1 (latest)

ancient boneBOT
#

๐Ÿ‘‹ 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.

split crown
#

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.

wide orbit
#

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.

split crown
#

Can you add more details here on what exactly is not working as expected on the yearly subscription with the one time invoice item?

wide orbit
#

This is how it shows up in stripe dashboard

#

Issues: invoice status is "incomplete" and unable to set quantity for upfront user count

split crown
#

Can you share the invoice id with me?

#

It starts with in_

wide orbit
#

invoice is open, even after setting 'autoadvance' true, it says auto collection is off

#

in_1PQweVRqKBJVF46JlepBN2WT

#

fyi, my account is still in TEST mode

split crown
#

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.

wide orbit
#

okay, i will try it.

#

I added this line, but it didn't work

#

in_1PQx05RqKBJVF46JAmsS6a84

full nestBOT
light mauve
#

๐Ÿ‘‹ stepping in here and taking a look

wide orbit
#

along with setupIntent, should i be creating a paymentIntent and use its paymentMethodId?

light mauve
#

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?

wide orbit
#

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

light mauve
#

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

wide orbit
#

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

light mauve
#

Yeah so let's start with the monthly Sub.

#

In this case the initial payment is $0

wide orbit
#

yes, there is no payment, that's why i haven't called stripe.confirmPayment, instead i am calling stripe.confirmSetup

light mauve
#

Instead of creating a separate SetupIntent, you should be using the one that is returned from the Subscription creation.

#

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

wide orbit
#

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

light mauve
#

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

wide orbit
#

Thank you sir, i will look into your suggestions.