As far as I can tell, Subscriptions API appears to be built on top of Invoices API, so I am tagging both in hopes it is specific enough.
Our subscription service requires the subscription to be paused immediately when a payment fails. As this is not the default behavior of the Subscriptions API, I am attempting to manually pause the subscription.
Pausing a subscription requires the subscription ID. I am currently subscribed to the invoices.scheduled_charge_failed webhook. Can I access the subscription ID directly from the invoice? Or do I need to retrieve the invoice separately? Also, does an invoice recognize the difference between a subscription and, say, some other type of service?
TLDR; How do I access a subscription ID from an invoice?
I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:
If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.
I see that you’ve marked the documentation as a solution. Were you able to get the answer from the documentation?
Also please note that the invoices.scheduled_charge_failed event won’t fire with failed subscription payments. It’s for recurring invoices which is a separate feature then the Subscriptions API.
Yes, I saw in the docs that the subscription_id will be passed in the response if the invoice is a subscription.
But with invoices.scheduled_charge_failed not working with subscriptions, which webhook am I looking for? It is essential to know when a payment fails.
If a subscription is scheduled to begin at a future date, if the card on file fails for that initial charge (attempting to activate the subscription) on that date, will that also trigger a payments.updated webhook event?
Not exactly. The subscription is already created. It’s the scheduled payment that failed. That failed payment will trigger a payment.created event. We will send the customer an invoice. They can then pay through the invoice which will trigger invoice.payment_made, payment.created, and payment.updated events.
Yes, with card on file subscriptions it will. If a subscription doesn’t have a card on file you may want to listen to invoices webhooks so you know when they’re sent to the customer.
Hi @Bryan-Square , So, pls confirm me this, what I am doing is this whenever I get an invoice.updated webhook, I look for subscription_id in it then I fetch the API response from retrieve_susbcription method using that subscription_id, then I look for the invoices array in the response and then take the latest invoice in the array (which appears to be the first one i.e. [0]th index in the array), then I check the status of that invoice and if it is not PAID, I act accordingly, is it the right flow, I am currently listening for subcription.updated and invoice.updated webhook events for the payment confirmation. I am looking for the invoice arrays as it appears there can be versions of a single invoice so I am looking for the latest version (that should be the one associated in the array, right?)