#Matt11-test-clock
1 messages Β· Page 1 of 1 (latest)
Hi, I'll explain to you my setup
I have a plan with trial period of 7 days
I setup a test clock with a customer and a subscription with the plan
I advanced time by 7days + 1 hours and I started reading the webhook log in my application
I attached to the subscription the payment method 4000000000000341, that is the error card
two weird things after the time advance:
1- the subscription status is "active"
2- the invoice is in draft
why?
Can you share the subscription ID?
the test one?
Yes, the one that you're facing the issue. It should be something like sub_xxx
sub_1L1PqLApMCw5clA3WG5jx4ny
the problem here is that I'm doing some stuff on my application according with the subscription status, so since it is 'active' I'm activating my user. But the payment is not really active
stripe says that the invoice is scheduled to be processed on may 27th, but I advanced time
This is expected. The subscription will move to active as soon as the trial is over and the customer will start getting charged. Customer is given time to make the payment. https://stripe.com/docs/billing/subscriptions/overview#subscription-lifecycle
where did you read that?
I read "When the payment succeeds the subscription status moves to active", so since is not successfull I expect it isn't active
"The status can also become active if you offer trials that donβt require payments. When the trial is over, the subscription moves to active and the subscribed customer starts to be charged.".
How do I force the subscription to require payment?
my need is that during the transition from trial to active the customer is charged immediately
I need to do a synchronous event
When the trial is over, the subscription moves to active and the subscribed customer starts to be charged.
I'm checking internally on how to do that
thanks
π , I'm taking over for @fair crystal, just give me a few minutes to catch up
could you try to advance the test clock for one day please?
now the payment failed right?
yep
the idea is that after the invoice gets created it will be in a draft mode, and it will try to get finalized and paid after some time
the event that you should be listening to is invoice.paid instead of the customer.subscription.updated
https://stripe.com/docs/billing/subscriptions/webhooks
invoice.paidSent when the invoice is successfully paid. You can provision access to your product when you receive this event and the subscription status is active.
the problem here is that inside my application the users need to be activated when it pass from trial to active
I cannot let them wait 1 week when Stripe tries to pay the invoice
yes you can do that in two steps
you will receive the invoice.paid event when you first create the subscription for the trial period
and the amount of that invoice would be 0
and the subscription status would be trialing
when the trial period ends you will get another invoice.paid or invoice.payment_failed(in your case) and you will change the status in your application accordingly
ok
but
how much time it will pass between the end of trial and the event invoice.paid or invoice.payment_failed?
it is something I can edit?
no unfortunately
ok, so inside my application the customer will be "not active" during the stripe delay
correct?
they will still be on trial no?
nope, because when I create my own subscription inside a database I have a from and to = from + 7 days
so when current_time > to the user is disabled
maybe I could set the to = from + 7 days + 5 hours
so in the meanwhile Stripe it will try to pay the invoice
ok thanks
so listening for customer.subscription.updated is incorrect?
because until now everything is working
is it luck? π
yeah it was π
no but to put it in a more serious way, it was working because the payment was not declined
the thread does not get deleted
where can I find it when it's closed?
you could still search the discord for the conversation
ah ok thanks
just bear in mind that when using test clocks you won't be able to add more than 3 subscriptions per user
another question sorry
Why when I advanced time the invoice try day stayed the same? I mean I expect that also the try date changes
it will change when you get to the retry attempt
the next retry is on 2022-05-29 02:01:15
your test_clock is still on the 28th
yes but when I started the clock the date was 2022-05-20
the first payment was on the 27th
for now it's everything ok
I will try the new event listener
hey @tawdry vault I have another question
sure
inside my application I have the "old" logic with subscriptions and a new logic with payment_intents
If I change the listener to invoice.paid and invoice.payment_failed, will I receive also the event from the payment_intents?
yes but it would be duplicated events
you should listen to invoice events for subscriptions
I meant that when an invoice.paid is fired there will also be a payment_intent.succeeded that will fire as well
exactly why I said for invoice you should only look at invoice.paid and not the payment_intent
yes but if I have subscriptions and payment_intent I will receive events from both of them, isn't it?
basically what you can do is ignoring the event on the payment_intent if the invoice https://stripe.com/docs/api/payment_intents/object#payment_intent_object-invoice is not null
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I don't need to pass from webhook if it is a payment_intent
the webhook are required only for subscriptions
then you don't need to listen to the payment_intent events in that case
sorry I don't understand. when I confirm a payment_intent, stripe creates an invoice?
oh ok, so for a payment_intent there will not be an invoice.paid event
yes
this is why I said if you want to listen for both events the best thing to do is to ignore the payment_intent events when the invoice field on that payment_intent is not null
right now i'm listening only for subscription.updated
so every invoice has the 'subscription' field filled
yes thanks
and what is the difference between invoice.paid and invoice.payment_success?
invoice.paid happens whenever an invoice moves to the paid status, but invoice.payment_succeeded only happens if there was an actual payment charging a payment method in Stripe
so for example it doesn't happen if the invoice was for $0 because of coupons or stuff, so it's generally not as useful or consistent and everyone should use invoice.paid