0

I've got a test subscription set up that is active. I'm trying to test what happens when the payment fails. I need to be able to pass some metadata (cognito user ID) to the webhook endpoint, I think I know how to do this but can't work out how to test it.

Using the test webhook doesn't work because it sends a fake charge ID. I've tried using the payment failure card but not having much luck as it doesn't seem to be triggering my endpoint.

Here is what I've been reading already:

https://stripe.com/docs/billing/testing

Stripe charge after subscription, get metadata from subscription

Stripe subscription webhooks missing metadata and client_reference_id

How can I test subscription renewal flows in stripe?

jbflow
  • 578
  • 2
  • 16

1 Answers1

1

Getting charge.failed event, but struggling to associate this charge to subscription, because the charge has customerId and the customer has a list of subscriptions. Now I think below code can help From event can get charge id and then retrieve charge obj with 'expand' property.

params := &stripe.ChargeParams{}
params.AddExpand("customer")
params.AddExpand("invoice.subscription")
ch, err := charge.Get("ch_3K4yJG2eZvKYlo2C14TZsir9", params)