#Thomas B-payment_failed_test

1 messages ยท Page 1 of 1 (latest)

zenith elbow
#

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...

supple mesa
#

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.
zenith elbow
#

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?

supple mesa
#

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)
zenith elbow
#

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.

supple mesa
#

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.created event updating the trial time to be like only 10 seconds instead. Hopefully this is possible. ๐Ÿ™‚
supple mesa
zenith elbow
#

And yes, that should be possible. I have tested like that before