#bill92_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/1308589359532085350
๐ 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.
- bill92_webhooks, 36 minutes ago, 26 messages
- bill92_webhooks, 17 hours ago, 44 messages
- bill92_webhooks, 21 hours ago, 5 messages
- bill92_webhooks, 4 days ago, 25 messages
- bill_subscription-trial, 5 days ago, 20 messages
Hi, let me help you with this.
case 'customer.subscription.trial_will_end': {
// Send email to the customer
await postmark.sendEmailWithTemplate({
From,
To,
TemplateAlias: 'template-alias',
TemplateModel: {},
});
break;
}
Why do you want to prevent it from firing?
I want to send an email to the user only when their trial is exactly 3 days away from ending, not just when the trial_will_end event is triggered. (which happens when I update a subscription on the customer portal)
I need to make the distinction
I want to send an email to the user only when their trial is exactly 3 days away from ending, not just when the trial_will_end event is triggered. (which happens when I update a subscription on the customer portal)
I don't think I understand it from your message. According to the docs this happens in 2 cases:
(1) 3 days before trial ends
(2) when you settrial_end=now
Do you want to do it just in case (1), or both (1) and (2)?
these are the order of the events
In any case, it's best to check the value of the trial_end property when you receive the webhook and make the decision in the code.
here is my flow:
1 - user signs up to my platform
2 - they select a product and a price id
3 - a subscription is created with a trial of 7 days with trial_period_days
4- if the user goes to the customer portal and updates his subscription to a paid one (lets say he pays the annual fee)
5- the trial_will_end event is triggered
isn't there a way to prevent this behavior? like a checkbox on settings? ๐ค
No. You need to make the decision in your own code.
due to the nature of webhooks, the decision can not always be precise
but I'll give it a shot
What do you mean by this?
the slight offset between when the stripe event is fired and when I compute the current time (now)
const trialEndDate = stripeEvent.data.object.trial_end;
const now = Date.now() / 1000;
if (trialEndDate < now) {
console.log('no email sending since the trial will not end now');
break;
}
but, then again.. its not the end of the day
doing some testing real quick
have you had other users talk about this to you river?
This is expected behaviour
Your code should handle accordingly. There can be latency due to network and other factors that cause the slight offset
weird, on both cases my email is being sent ๐ค
I'd recommend logging the timestamp in your code and different code block to identify why the email was sent
stripe trial_end is in seconds and not in miliseconds, right?
trial_end is UNIX timestamp in seconds in UTC
I'd recommend ensuring your current timestamp is in UTC as well
I'll need to add the three days from now, otherwise the email will always be sent
๐ค
Please also ensure your โnow()โ timestamp is in UTC, same timezone as the trial_end
let me try that, one sec
// Convert to timestamp in seconds
const trialEndDate = Number(stripeEvent.data.object.trial_end); // seconds
const threeDaysBeforeTheTrialPeriodEnds = Math.floor(trialEndDate - 60 * 60 * 24 * 3); // seconds
const nowDate = Math.floor(Date.now() / 1000); // seconds
if (nowDate > threeDaysBeforeTheTrialPeriodEnds) {
console.log('skipping sending trial_will_end email');
break;
}
looks like its not working, maybe its due that my server is in the present but stripe's simulations are in the future? ๐ค
If you use test clock, then that is likely the case
yes, using test clocks