#mochihealth

1 messages · Page 1 of 1 (latest)

crude smeltBOT
balmy bobcat
#

Hi đŸ‘‹

This should be present on the invoice object. Do you have an example ID I can look at?

fluid dragon
#

in_1NTXplBPM36OC3gXsVdSKJHw

balmy bobcat
#

applied_balance -2000

#

THis is in USD so that would be in cents

#

or $20

fluid dragon
#

because we implemented our own referral system on top of stripe where we keep track of a customers credit balance on our end and listen to the invoice creation on subscription renewals to release the credits into stripe but I notice that if the credits are in stripe and the payment fails then unless the invoice is voided the credits dont go back to the customer so I want to listen to the payment failed event and check if their was any credit that was applied to a specific invoice and if there was credit it back in our system instead of voiding the invoice because that is currently not what we do. does this sound reasonable?

#

also I cannot find that field on the invoice object only starting and ending balance

crude smeltBOT
torn lantern
#

Hello! I'm taking over and catching up...

#

Gotcha, yeah, that approach makes sense. Let me figure out how you can determine this via the API...

#

Okay, I have an answer, but it's not a great answer. đŸ˜… We don't currently expose the applied Customer balance on an Invoice via the API, it's only available in the Dashboard. This is a known limitation that we're aware of, and I'm going to +1 it internally for you.

Setting that aside, there is technically a way to figure this out using the API, but it's pretty messy. What you can do is listen for invoice.payment_failed Events, then you can list the Customer Balance Transactions for the associated Customer: https://stripe.com/docs/api/customer_balance_transactions/list

You can look through those to determine if any of them have an invoice property that points the Invoice where payment failed and take appropriate action: https://stripe.com/docs/api/customer_balance_transactions/object#customer_balance_transaction_object-invoice

I recommend using auto-pagination when listing the Customer Balance Transactions: https://stripe.com/docs/api/pagination/auto

fluid dragon
#

oh god

#

lol

#

and would just taking the difference between the starging and ending balance not be sufficient?

torn lantern
#

That depends on how your integration works and how many things touch the Customer Balance, how frequently, if they could overlap, etc.

#

Really I recommend voiding the Invoice instead.

#

Can you tell me more about why you don't want to do that?

fluid dragon
#

well right now when we show a list of payments to the customers it would mess up the ones we showed as failed since those are payments where the invoice is open and the charge failed. and i only grab invoices that are either paid or open

torn lantern
#

In these cases (where you void) you would create a new Invoice though, right? Or no?

fluid dragon
#

no

#

well yes

#

what do you mean

#

the customer would need to create a new subscription

#

so yea a new invoice would eventually be created

torn lantern
#

So the voided Invoice would drop off the list you show, but the new one would appear. But you need both to show up?

fluid dragon
#

well I want to show a customers payment history

#

so if the payment failed I would want to show that

torn lantern
#

It sounds like you might want to list data from Payment Intents there instead of Invoices?

fluid dragon
#

cant i just grab voided invoices that have a charge status of failed

torn lantern
#

Yep, you could do that.

fluid dragon
#

last question

#

how do i void an invoice through the api

torn lantern
fluid dragon
#

thanks sorry one last one because I need to decide in which cases to void the invoice

#

when does the payment failed event actually trigger like if the card got declined when a customer was checking out I wouldnt want to void the invoice right

#

so does it get triggered for a case like that

torn lantern
#

It does, yeah. It will trigger on any failed payment attempt.

#

You only want to void when you've given up on that Invoice ever being paid.

fluid dragon
#

hmm if i just void the subscription update failures it seems like I'm leaving the door open for scenarios where there was a credit attached to a creation which wouldnt get credited back

torn lantern
#

You mean a Subscription creation?

#

Voiding the first Invoice for the Subscription doesn't return the applied balance?

fluid dragon
#

no it would im sure but If the customer is still in the portal trying to purchase a subscription I dont want to void it. it would really only be in asynchronous payment attempts

#

Im just saying there is technically an edge case where the customer tries to create a subscription an existing credit is applied, the subscription creation fails and then the customer gives up

#

so in that case the credit would be stuck in purgatory

torn lantern
#

Gotcha. Maybe you could run a nightly job or similar where you clean those up by voiding the Invoices and return the applied balance?

fluid dragon
#

yea that seems like the only option left

#

but I appreciate it