#abradolflincler_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1275191547222032477
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello, thank you for the detail. So the tracking of the unpaid amount is the big thing that you are trying to figure out?
yes, along with an automated way to apply the new payment method to previous unpaid invoices.
You can call the invoice.pay endpoint and pass in the payment method's ID to try to pay them with the new PM
https://docs.stripe.com/api/invoices/pay#pay_invoice-payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Okay, but how can I determine when to call this? is there a stripe webhook event or automation that makes the most sense for my behavior?
Oh I thought you were saying you already had a place to do that when you mentioned
We have a webhook that auto-updates a customer's default payment method whenever they add a new one
We haven't implemented this yet, I guess we can though
๐ Stepping in for my teammate, give me a minute to catch up
Currently this is what happens:
- Customer orders $1200 worth of product on October 5th, 2024
- Customer selects a 12 month payment plan
- Stripe creates a $100/month subscription and sets "canceled_at" to October 5th, 2025
- Customer's card is declined on December 5th, 2024, invoice is marked as past due, smart retry starts (8 attempts over the next 2 months)
- Same card still declined on Jan 5th, smart retry policy started for that invoice as well
- Smart retry policy ends for Dec 5th invoice
- Customer updates card on Feb 4th
- Customer card successful for Feb 5th invoice payment, unsuccessful for smart retry for Jan 5th invoice, Dec 5th invoice stays "past due"
This logic doesn't allow us to collect the full amount, and this could lead to a huge loss in revenue for us
The December and January Invoices in this scenario are still in a state where you can attempt to pay them. So if the customer has added a card and you know that card was successfully used to charge them for the February Invoice, you can do as Pompey mentioned and use the /pay endpoint to manually pay the December and January Invoices with the new card: https://docs.stripe.com/api/invoices/pay#pay_invoice-payment_method
Okay so to clarify, I would need the following behavior (automated):
- When a payment method is added, look up all the unpaid invoices for that customer, and attempt to pay for them using the new card, one at a time.
Let me confirm with my billing manager if this is okay before you close the thread
Got it. Yep, the best way to do this is to use webhooks and listen for a few events
You can listen for payment_method.attached to know when a customer has added new payment details and/or listen for invoice.paid to know when an Invoice has been paid successfully. You can then use the customer from that Invoice to look at your database to see if that customer has any open/unpaid Invoices and then loop through these to pay them with the PaymentMethod used to successfully pay the Invoice for which you received the webhook event
@dusty leaf Let me know if you need any more help!