#hurin_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/1298811019715543072
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi @keen saddle , to give you more background info,
I am implementing a referral system and the referrer only get the credit granted when the the person they referred has bought a subscription and they have surpassed the trial period and have been charged for a month.
In my current logic, I require the status of the subscription to be active (and do not accept weekly subscriptions):
// Check if this is a payment for a monthly or quarterly plan
const subscription = await stripe.subscriptions.retrieve(subscriptionId);
const interval = subscription.items.data[0].price.recurring?.interval;
console.log('Interval:', interval);
console.log('Subscription status:', subscription.status);
if (subscription.status !== 'active' || interval === 'week') {
console.log('Not eligible for referral credit (weekly plan or not active)');
return; // Not eligible for referral credit (weekly plan or not active)
}
// Check if this is the first billing cycle
// We'll use the created timestamp and current_period_start to determine this
const isFirstBillingCycle = subscription.created === subscription.current_period_start;
console.log('Is first billing cycle:', isFirstBillingCycle);
if (!isFirstBillingCycle) {
console.log('Not the first payment');
return; // Not the first payment
}
I am executing this in a function when I get the invoice.payment_suceeded event, so the question is whether I will get a second event when the user has been charged after the trial period - it has to be the invoice.payment_suceeded.
My AI suggested I tweak my code to this to account for trial periods by replacing the above with this:
// Check if this is the first paid invoice
const invoices = await stripe.invoices.list({
customer: customerId,
subscription: subscriptionId,
limit: 2,
status: 'paid'
});
if (invoices.data.length !== 1) {
console.log('Not the first paid invoice');
return; // Not the first payment
}
Hi @lavish crystal is this a question about whether you'll receive a invoice.payment_succeeded event for the first $0 invoice?
yes, sir and if I will receive a second one after the trial period
yes and yes. You can test this out by using a test clock https://docs.stripe.com/billing/testing/test-clocks
Thanks for this, I saw these clocks, very comprehensive docs but I am afraid I am not as smart as the people who wrote them. I shall test my clocks all al naturale... I have just gone through the entire process and I have just updated my trial period to 1 day instead of 2 days and for some reason, Stripe doesn't recognise 1 day of a trial - immediately goes on to charge the users - is this by design? 2 days of trial shows up on the check out - try out for 2 days for free, while 1 day doesn't - why is that?
what's the subscrpition ID?
sub_1QDFtmCszBkpi7B0YDjtMyBW
https://dashboard.stripe.com/test/logs/req_sYL3BxuKPE9TpR this is the checkout session creation request, and I don't see trial here
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Hmm, good spot, there seems to be a unique function which calcultes when the trial is supposed to finish and it had null, undefined, <2 days - when I changed it to <1 day and left the 1 day in my sql table I got the following error from Stripe:
StripeInvalidRequestError: The trial_end date has to be at least 2 days in the future.
at generateV1Error
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Yes, this is expected, as per documented here https://docs.stripe.com/api/checkout/sessions/create?lang=python#create_checkout_session-subscription_data-trial_end
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
https://docs.stripe.com/api/checkout/sessions/create?lang=python#create_checkout_session-subscription_data-trial_period_days or you can use trial_period_days , it's minimum value is 1
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
oh I see, by one of the strings it is by design 2 days free as a minimum, and by the other when you specify the actual days not the end date - it's 1 day