#coachleyton
1 messages ยท Page 1 of 1 (latest)
It would be something you have to manually handle - when downgrading we should be genrating an InvoiceItem representing the credit back to the user. You could check that, generate a refund for the correct amount, and then delete that Invoice Item so it's not pulled into the next invoice
Is this new "InvoiceItem" something I can immediately access? For example, I'm using the .NET Stripe client. Is it that "latest_invoice" that I specify in the "Expand"?
No, the Invoice Item isn't something you'd get from the latest_invoice (it would be there if you did proration_behavior: always_invoice , but because you're not immediately invoicing we just create the invoice items so they get pulled in automatically for the next invoice)
You'd have to listen for invoiceitem.created event and get the invoice item like that
Or
An alternative would be that you use the upcoming invoices API to calculate what the prorations would be, create the refund, and update the subcrpition with proraration_behavior: none
Ah, so you are still doing always_invoice for downgrades
is this bad? Using "always_invoice" for downgrades?
Also, above you said the following: "and then delete that Invoice Item so it's not pulled into the next invoice". I'm not sure what you mean by "pulled into the next invoice"
No, it's not bad - it's just not what you mentioned initially so what I mentioned about looking at the invoice items isn't really valid in this case
If you're using always_invoice then you should just check to see what was added to your credit balance (you can compare starting_balance and ending_balance to know the exact amount) and then create a refund for the payment intent tied to the previous invoice of the subcription
Once the invoice is successful you should create a debit credit balance (https://stripe.com/docs/api/customer_balance_transactions/create) to account for the refund
So refunds have to be tied to a particular invoice, okay. So when I programmatically create this refund, I should attach it to the last invoice (the one that was generated during the downgrade). And then that'll just be processed and the money will return to the Customer?
My apologies for my misunderstanding btw
no worries!
and just to clarify - it's not really that the refund has to be tied to a particular invoice. It's more that we need a PaymentIntent ID to be able to actually create the refund
You'd want to use the PaymentIntent for the previous invoice - the one that was generated before the downgrade that had a postitive amount charged
Hmmm okay. I must admit, I'm confused. Not really sure precisely how all of these entities tie together (PaymentIntent, Invoice, etc).
So, a refund can't be created without a payment intent. Lets say a user does the following:
- Pays for ยฃ10 subscription (generates invoice #1)
- Downgrades to ยฃ5 subscription (generates invoice #2?)
I need to get invoice #2, calculate the correct refund amount, then get the payment intent ID associated with invoice #1, THEN create a refund request, with that payment intent ID, and the amount that I just calculated?
๐ taking over here
Hello ๐ Just trying to understand how refunds work. I've been trying to find a decent schema diagram to understand how all these entities fit together (PaymentIntent, Invoice, etc). Not sure if there's an official diagram for this
Yes what you described sounds aligned to what my colleague suggested. The Refund can be tighted with the PaymentIntent of the previous Invoice #1
In the following message, your colleague mentions that I should delete the invoice item that would be generated as a result of the refund (I presume this would be invoice #3)
Not sure what they mean by "so it's not pulled into the next invoice"
Yes there will be a new Invoice Item to be generated, and normally any Invoice Item will be automatically collected when the Customer has the next Invoice
So they meant to delete that Invoice Item, to avoid you credit your customer twice, both via it and via the Refund you are doing
I see. Alrighty. That makes sense
also, regarding my desire for some DB diagram, would you say that the relationships described here are accurate?
I just used "DiagramGPT" to generate it
Yes! It's nice btw
It is indeed a nice app. Does magical AI stuff. Anyway, thanks lot to you and your colleague for the help. I'm happy for you to close this thread ๐