#rich-jones_webhooks
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/1421126825337294869
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- rich-jones_best-practices, 4 days ago, 63 messages
This is the sandbox I am using: https://dashboard.stripe.com/acct_1RvyOzK5rXwa4H0q/test/
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
My app creates a stripe customer when a business creates an account in my app, with the first user creating a stripe subscription (which only has 1 product/proce), with a 30 day free trial silently via API call, setting the quantity for the price to 1. When other users sign-up if it is within the trial period, the quantity is incremented for each user. Within my app the first user is designated as the 'billing contact', their email is reflected in the stripe customer. They are able to to access a stripe checkout to add a payment method. I want to know when an invoice is due, has been paid or not so that I can alert the billing contact and control access in the event of a late or non payment of the invoice. Using the fewest web-hooks calls.
So if you are using a charge automatically subscription in stripe, they don't really have a concept of due date
They're billed automatically on the billing cycle anchor
Are you creating send_invoice subscriptions?
Can you share a sample subscription id so I can take a look?
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Can you acces that ?
Sorry, sub_1SBZxiK5rXwa4H0qVvXd0JPW
Yeah that's a charge_automatically subscription
So what do you mean by due date here?
I'm not an accountant, but I guess I mean the date the invoice is due for payment.
But I guess here the payments are due immediatley ?
There's no concept of a due date here
We attempt to charge the invoice automatically
But there's no due date
So I'd like to let them know in my app when a payment is due, and warn them if there is no payment methiod attached, and then give them a short grace period beyond which the payment should have been paid .
So I'd like a trial period countdown timer which I can handle, but after that a days to payment due and days payment overdue
And an ability to warn if no or invalid payment method held in stripe
When the billing contact signs in I could check via an API call as well as using web hooks I guess ?
To check the date the subscription bills on you'd look at billing_cycle_anchor on the subscription object: https://docs.stripe.com/api/subscriptions/object#subscription_object-billing_cycle_anchor
I recommend using webhooks as much as possible
GET requests to our api add up and tend to contribute to most rate limiting issues we see
It's not a due date though ๐
OK, good advice, thank you.
It's just the date we attempt to bill
On a related point, I am specifiying the 30 day trial on cust or subs call (I can't recall), can I set them up in stripe instead ?
can I set them up in stripe instead ?
What do you mean by this? By setting them in the subscription api call that does set it in Stripe
Yes but I'd rather configure the trial period in my stripe dashboard rather than have my code set it ...
It's something that's configured on a per subscription basis not globally
My code : // Create Essential subscription with 30-day trial and idempotency key
const subscription = await stripe.subscriptions.create({
customer: tenant.stripe_customer_id,
items: [{ price: essentialPrice.id, quantity: 1 }],
trial_period_days: params.trial_period_days || 30,
metadata: {
tenant_id: tenantId,
user_id: user.id,
tenant_name: tenant.tenant_name,
product_type: 'essential',
subscription_source: params.metadata?.source || 'stripe_gateway',
active_user_emails: activeUserEmails.join(','),
active_user_count: activeUserEmails.length.toString(),
last_updated: new Date().toISOString(),
...params.metadata // Merge additional metadata
}
}, {
idempotencyKey // Add Stripe idempotency key
});
is that best practice ?
Yeah
Looks fine to me
But in terms of which webhooks you should listen to, it kind of depends on what you want to store and when. Recommend giving https://docs.stripe.com/billing/subscriptions/webhooks a good read
You might can get away with just customer.subscription.updated, invoice.paid, and invoice.payment_failed for example
Thank you I have, but not knowing stripe internals I wanted some advice on the fewest hooks to process.
OK, I'll look at billing_cycle_anchor too
Yep when you get customer.subscription.updated, you can check if billing cycle anchor changed and store it in your database if so
How might I alert billing_contact that there has been no payment, the lack of customer.subscription.updated tellign us that one has been added ?
Payment is attempted automatically with subscriptions
So if it fails, you get invoice.payment_failed webhook event
You can action that
I'd like to prevent that by nudging them to add one to avoid payment failure ๐
My bad, yes
So it depends where you set the default payment method
I have said card payment only
If you set it at subscription level then you'd get a customer.subscription.updated event
If you set it at customer level, then you'd get a customer.updated event
Good point, but either way I can track the addition of a payment method ?
You can
But addition of payment method isn't enough here
It needs to be set as the default
those are API docs, will a webhook trigger when a payment method is added ?
yes but like I said just attaching a payment method isn't enough here
You need to make another api call to update subscription or customer
And set the default somewhere
Then you'd get customer.subsription.update or customer.updated
Or if the user sets it as default on the portal I direct them to ?
Yep
You should test this out in test mode
I believe portal sets default at customer level
But I don't remember offhand
OK, thank you. I might just let stripe take care of it and track payments or payment fails
Keep it as simple as poss at my end
Up to you
You can try out different scenarios in test mode/sandbox
And see what works best for your usecase
I think I will display a next payment event to the billing_contact on sign in with a link to the portal each time and let them handle the process. If payments work ๐ , if not I'll lock access until a payment is made ๐
I am using one thanks.
Thank you very much for your help
Have a great weekend