#paul_subscription-testclock
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/1219790474450309212
๐ 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.
- paulc7053_webhooks, 3 hours ago, 50 messages
- paulc7053_webhooks, 1 day ago, 21 messages
- paulc7053_code, 1 day ago, 36 messages
- paul_ece-googlepay, 4 days ago, 58 messages
- paulc7053_code, 5 days ago, 99 messages
- paulc7053_code, 5 days ago, 51 messages
and 1 more
paul_subscription-testclock
Hello
๐ Hey @crude juniper ! I understand you say you have no Event id but you must have something relevant I can use to help you such as an exact Subscription id, an exact Invoice id, etc. that explains what you are trying to do
looking
Thanks!
Okay so TestClocks can be tricky to grasp. So can you first explain exactly what you are doing and then what isn't happening and what you are seeing in the API?
Sure
My ultimate goal is to simulate a billing_reason where the value is subscriptino_cycle if I remember correctly. Then I created 2 subscriptions: one which is supposed to go through (used the 4242 card), and another one which is supposed to be declined (used the 4000) card. I looked at the requests log for my webhook, and not one clock triggered a request
Okay sorry I'm going to be a bit nitpicky because I'm missing a lot of crucial information to help you right now. Let's ignore the webhook entirely for a sec.
The first step is to explain what you are doing to the Subscription exactly and then what the result is that is different from what you expect.
I'm a developer so I help with code-related questions. I assume you are doing a set of steps to end up in the state you want. But I'm seeing some Dashboard clicks on those and not sure I follow what you are doing end to end as the developer. Can you try and share your end to end reproduction script for example?
Well, repro for what exactly?
For what you have been trying to do for a couple hours that you are stuck on
So I've previously talked to your colleague about this too (https://discord.com/channels/841573134531821608/1217873911006625833), he recommended I create these test clocks in the dashboard (which seems to be the only way)
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
for example the first Subscription you shared is associated with a TestClock that you seem to have created in the Dashboard and I don't see you advancing time
No TestClocks can be done fully in code, that's what I do. The Dashboard works fine too but it's important to understand what you are trying to do.
Give me a few minutes to write something
Sure
My understanding is that you want to simulate a case where a future Invoice on a Subscription suddenly fails a payment after having previous Invoices working fine.
If so, here's what I'd do as a developer
- Create a TestClock set to say 2024-03-01 00:00:00 UTC
- Create a Customer on that TestClock
- Create a Subscription on that Customer with the
pm_card_visaPaymentMethod so that it's paid successfully - Advance the TestClock to 2024-04-02 00:00:00 UTC
- Wait for the time advancement to finish (write a for loop that polls).
- Confirm the latest Invoice for April 1st - May 1st is paid
- Update the Customer's default PaymentMethod to
pm_card_chargeCustomerFail - Advance the TestClock to 2024-05-02 00:00:00 UTC
- Wait for the time advancement to finish (write a for loop that polls).
- Confirm the most recent Invoice's payment failed
So first when you read all of this, does it make sense?
You writing real code to do this. Can you read PHP code?
All good was just asking because I have end to end PHP scripts for this
But in node you write const testClock = await stripe.testHelpers.testClocks.advance( 'clock_1Mr3I22eZvKYlo2Ck0rgMqd7', { frozen_time: 1680199613, } ); to advance a TestClock right?
I'm not familiar with this API, but I can look it up
Ah so you have been doing all of this by hand in the Dashboard?
Exactly
I have just re-read the docs for test clocks, and it's possible I misunderstood something
At the time T1 when I set the clock, does it have to be after the subscirption billing cycle or it can be any time where T1> T0+ 2 Hours (which is what I did )?
it's kinda neither
Today is March 19. Let's say it's 16:54 for both of us (not sure where you live)
If I create a TestClock, by default it will be pinned to that exact time.
Now if you and I talk for 10 minutes, it will be March 19 17:04 at that point. But for the TestClock it is still March 19 16:54. And the Subscription that is associated with it is "stuck" at that exact second of the day.
What you can do is tell us "hey that TestClock, advance the time to April 2nd 15:43 please" and we will do that. and as we advance the time in our test environment for that TestClock we also look at all the objects in that TestClock and advance the time for those too one by one
So imagine you have a Subscription that is set to renew on May 1st at 00:00. Without a TestClock you'd have to wait 12 days to test this logic
With TestClock you tell us "advance the time please" and we pretend we're in the future
Not sure how clear this is to you
No, that was clear
And so I think you forgot to "advance" the time
So, since the subscription ought to renew on May 1st at 00:00, I should advance the clock to that time
Okay, let me tell you how I've been trying to test this: Accept Payment with ECE -> create customer -> create subscription -> go in the Dashboard and click Run Simulation -> input the date the subscription would have to rebill the customer -> click advance time. Then, there is an Advance Time button that prompts me to again select a date.
Did I get that right?
Yes but if I were you I would bypass all of those manual flows and do it with code end to end
not entirely sure what you mean by that
Previously, I've been told I can just advance the clock to that time & the webhook will be touched (or I understood wrong?)
I mean you can advance the TestClock to a certain time, and if that certain time is past the Subscription's current_period_end then it will trigger a new cycle yes
I've been told I can advance the clock to this DateTime + 1 Hour
I understand
Thanks a lot for your time, hope it's gonna work now!
when testing I'd do one day not just one hour
but yes
https://pastebin.com/raw/e7ZT1ANR I know you said you don't know PHP but this is an example script I have to simulate a Subscription change in the future for example
Thanks, thats helpvul
Okay, now seems to work as expected
Although I'm not sure why the payment_succeeded didn't retry (my server's down so they both got a 404)
you can click on each one and see their status
then it'll be retried, Events are retried async
Alright, got it
One more question if I may: are there any best practices when a payment fails?
Or should I just let stripe handleeverything through retries?
There are a lot of things you can do so it depends a bit on various factors. We (Stripe) will retry automatically every X days (depends on various things) so letting us do things is a good idea.
Additionally we can send an email to the customer to come and change their card details for example which helps. You can also use the CustomerPortal
https://docs.stripe.com/billing/revenue-recovery/smart-retries is likely a good start
Thanks a lot for your time, will look into it!
Happy to help ๐