#Thomas B-payment_failed_test
1 messages ยท Page 1 of 1 (latest)
One thing I have done before to get around that Checkout restriction is set metadata like 'trial_seconds': 10 and then have my webhook handler for creating a subscription check for that metadata and update the subscription accordingly
Let me think of other viable options here...
Thank you for replying!
- Not sure that I understand what you mean correctly though hehe. ๐
It is the Checkout Session itself that creates the subscription. Not anything on my end.
So in my case, I have a webhook endpoint listening for when subscriptions are created. When one is created, it checks if I marked it to have a shorter trial than Checkout can create, if so it updates that.
you can also manually do this in the API if you have the subscription ID. Have you created a sub with a 2 day trial as part of your testing here?
Well, I do actually listen to the customer.subscription.created event, but only to update stuff in my DB. So what you talk about is that I would add some "test code" in that event to help me do what I want here? (update trial time accordingly to trial_seconds I add in the metadata of the checkout sessions)
- subscriptions are created with 5 days of trial normally, but more or less the same. ๐ (unless you actually want to wait for it to end of course hehe)
Right. That is possible. Otherwise you can just make that subscription.update call yourself apart from your Checkout session.
Oh or you can just create a completely new subscription for that customer with the API. Specify the default_payment_method as whatever PM you expect to fail and set the trial_end for a few seconds from now (API lets you do that) and you should get the failure you are expecting
For the record, there is something on the roadmaps so that you don't have to wait these two days otherwise. For now a short trial is likely the best way to test an auto-renewal failing.
Yeah, I was really trying to make it as realistic as possible to make sure it behaves the same way in production - which ideally is just the trial time running out OR the subscription period running out.
- So I guess what I am going to try now, is creating the customer & subscription(with the 5 days trial) like always via the checkout session, and then in the
customer.subscription.createdevent updating the trial time to be like only 10 seconds instead. Hopefully this is possible. ๐
Is this the "Test clocks" you are referring to here? ๐
Indeed it is, have you already put your email in here? https://stripe.com/docs/billing/testing#test-clocks-
And yes, that should be possible. I have tested like that before