#gullible_best-practices
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1319408513268711456
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
For additional context, I have UIs built for adding, removing and setting a payment method as a default using StripeJS + Custom Elements. I also have a UI built that allows the user to provide billing information including address. This all works. My next step is to start a subscription based on the users selected subscription. Something like this:
async doSubscriptionCreate(varCustomerId, varPaymentMethodId, varPriceId) {
try {
const response = await this.stripe.subscriptions.create({
customer: varCustomerId,
default_payment_method: varPaymentMethodId,
items: [{
price: varPriceId,
quantity: 1
}],
trial_settings: {
end_behavior: {
missing_payment_method: 'pause'
}
},
trial_from_plan: true
})
console.log(response)
return response
} catch (error) {
return new Error(error)
}
}
I want to ensure that the trial period is added but it seems like the only way to do that is to create a payment link but I do not want to use Stripe's UIs for handling payments.
Hi ๐
Particularly, how do I start a subscription for a user with a 30 day free trial?
For this you can settrial_period_daysto30when creating the Subscription:
https://docs.stripe.com/api/subscriptions/create#create_subscription-trial_period_days
Or you can settrial_endto the desired end of the trial period:
https://docs.stripe.com/api/subscriptions/create#create_subscription-trial_end
Okay, so I do not need to worry about creating the payment link which gives me the ability to add the trial period there? I should be able to add trial_period_days to the code I provided above and be good?
Sorry, I don't understand the question, as I thought you said you weren't using any of our UIs so I'm not sure how Payment Links are relevant here.
Yes, you can add either of those parameters, and remove trial_from_plan so those don't conflict, and it should do what you're describing. Let me know if that isn't what you see in your testing.
I have not tested yet because I wanted to ensure this was going to work and what I wanted first. Once I test this and assume it works, are there webhooks I can set up for when a subscription changes statuses?
How do I ensure that they receive an invoice when paid as well as an invoice for upcoming charges directly from Stripe?
Email settings for Subscriptions are controlled from your Stripe dashboard here:
https://dashboard.stripe.com/settings/billing/automatic
Also, when a subscription changes statuses likes goes from active to paused or cancelled, is there a webhook I can use to trigger an update in my app?
Yes,customer.subscription.updatedEvents:
https://docs.stripe.com/api/events/types#event_types-customer.subscription.updated
Awesome, thank you, I appreciate it. How long will this chat stay open just in case I have more questions?
Probably about 20 minutes, but you're welcome to open a new thread if I close this one and additional questions come up.
Actually, I do have another question. Because this is a subscription and I do plan to collect payment information during user sign up (I know, the vast majority of companies do not do this today), when the subscription is created there will already be a default payment method set in the users account. From my understanding, once their trial period has ended, the payment method will automatically be charged. Is this accurate? I do not need to worry about payment intents and stuff like that or creating check sessions or anything?
Correct. If there is already a Payment Method specified to be used as the default, then that will be charged.
That can either be specified in the default_payment_method field on the Subscription object, which will take precedence but only apply for that specific Subscription, or in the invoice_settings.default_payment_method field on the Customer object, which will be used for all of the Customer's Subscriptions that don't have their own default payment method set at the Subscription level.