#dominikganic_best-practices
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/1333376956280082432
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
hi there!
you would update the payment method of the customer/subscription to one that would fail the payment.
or a simpler option is to create a subscription with a short free trial (a dew seconds), and without a payment method. as soon as the trial ends, the subscription becomes upaid
Ah alright. I will try that fast, will come asap back in a second
In my SubscriptionOptions I can set "trial_period_days" but how do I set this to seconds as it requires days and minimum 1? (Backend Subscription Creation API)
I've set this to "now"
The subscription has been created with status "incomplete" as the payment intent hasn't been paid yet
But it's still not "unpaid" - Do I have to perform a failed payment?
I've set this to "now"
no, you need to set it to a few seconds in the future
You can also use Test Clocks to test Subscriptions without waiting: https://docs.stripe.com/billing/testing/test-clocks
I don't understand Test Clocks to be honest, I don't know what to do there haha
Okay, I'll try setting it a few secs ahead, even though the docs mention "now" is a possible value
This is btw. the created sub yet: sub_1QlpGjLZihhBkt1cTXpHu0fa
Basically, if you use Test clocks, you can set trial time to 1 day, and instead of actually waiting for a day in real life, you can just advance the test clock and see what happens to the Subscription.
Okay now I've created a new subscription with trial_end from now + 10 seconds (time() + 10)
The subscription was in state "trialing"
After the 10 seconds, it became now "active" even though no payment has been done and an invalid payment method was added (Testcard with failing)
Now I see in the stripe dashboard the notice that the invoice will be created and charged in one hour?
sub_1QlpLoLZihhBkt1cOPQgtCmG
Yes, the behavior is expected. After an hour, the Invoice will attempt to charge the PaymentMethod and will fail.
Yes I've tried manually paying it with the invalid payment method and now I'm in mode "past_due" which is also great for me for implenenting an alert "Please pay your invoices" ๐
Now I will try re-paying it a few times until it triggers to set the state to "unpaid"
I've re-tried now the payment 4 times.
But when I call my API to get the information for the "past_due" status, I receive this:
attempt_count: 1
max_retry_attempts: 3
I wonder why I still receive the attempt_count is 1?
This is how I fetch the attempt_count in my backend through the API:
$AmountDue = $LatestInvoice->amount_due / 100;
$NextAttempt = $LatestInvoice->next_payment_attempt ? $LatestInvoice->next_payment_attempt : null;
$MaxRetryAttempts = $Subscription->automatic_tax->enabled ? 3 : 3;```
I feel like $MaxRetryAttempts is wrong.
But why is attempt_count 1, even though I've retried the payment already 4 times as you can see on the picture? ๐
I think it counts only automatic retries, not manual retries.
Ah okay, that makes sense
Can I create a clock now to this subscription and this customer to retry that?
Okay nevermind I will just await this invoice, I'm not in a hurry actually.
But, where can I setup retry attempts counts?
I'd like to set it to 2 retries within 1 day
So I don't have to wait now for 8 retries in 14 days ๐ I remember there are some settings in the dashboard anywhere.
Not for existing one, unfortunately.
I would recommend always using Test clocks with Subscriptions, instead of waiting. Sometimes you might want to test longer processes, so it's good to use Test clocks by default.
I will for sure give this a hit when I have some free time ๐