#rich-jones_webhooks

1 messages ยท Page 1 of 1 (latest)

slow coralBOT
#

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

steep cairn
#

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.

modest lichen
#

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?

steep cairn
#

Can you acces that ?

modest lichen
#

That's a product id

#

Subscription id's start with sub_

steep cairn
#

Sorry, sub_1SBZxiK5rXwa4H0qVvXd0JPW

modest lichen
#

Yeah that's a charge_automatically subscription

#

So what do you mean by due date here?

steep cairn
#

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 ?

modest lichen
#

There's no concept of a due date here

#

We attempt to charge the invoice automatically

#

But there's no due date

steep cairn
#

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 ?

modest lichen
#

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 ๐Ÿ˜„

steep cairn
#

OK, good advice, thank you.

modest lichen
#

It's just the date we attempt to bill

steep cairn
#

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 ?

modest lichen
#

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

steep cairn
#

Yes but I'd rather configure the trial period in my stripe dashboard rather than have my code set it ...

modest lichen
#

It's something that's configured on a per subscription basis not globally

steep cairn
#

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 ?

modest lichen
#

Yeah

#

Looks fine to me

#

You might can get away with just customer.subscription.updated, invoice.paid, and invoice.payment_failed for example

steep cairn
#

Thank you I have, but not knowing stripe internals I wanted some advice on the fewest hooks to process.

modest lichen
#

Based on what you said, those 3 might be sufficient

#

But up to you

steep cairn
#

OK, I'll look at billing_cycle_anchor too

modest lichen
#

Yep when you get customer.subscription.updated, you can check if billing cycle anchor changed and store it in your database if so

steep cairn
#

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 ?

modest lichen
#

Payment is attempted automatically with subscriptions

#

So if it fails, you get invoice.payment_failed webhook event

#

You can action that

steep cairn
#

I'd like to prevent that by nudging them to add one to avoid payment failure ๐Ÿ™‚

modest lichen
#

Oh you mean payment method

#

You said lack of payment

steep cairn
#

My bad, yes

modest lichen
#

So it depends where you set the default payment method

steep cairn
#

I have said card payment only

modest lichen
#

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

steep cairn
#

Good point, but either way I can track the addition of a payment method ?

modest lichen
#

But addition of payment method isn't enough here

#

It needs to be set as the default

steep cairn
#

those are API docs, will a webhook trigger when a payment method is added ?

modest lichen
#

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

steep cairn
#

Or if the user sets it as default on the portal I direct them to ?

modest lichen
#

Yep

#

You should test this out in test mode

#

I believe portal sets default at customer level

#

But I don't remember offhand

steep cairn
#

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

slow coralBOT
modest lichen
#

Up to you

#

You can try out different scenarios in test mode/sandbox

#

And see what works best for your usecase

steep cairn
#

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 ๐Ÿ™

steep cairn
#

Thank you very much for your help

#

Have a great weekend