#coachleyton

1 messages ยท Page 1 of 1 (latest)

subtle valveBOT
ember swan
#

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

hazy pebble
#

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"?

ember swan
#

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

hazy pebble
#

oh haha I left that bit out

#

I do infact always_invoice

ember swan
#

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

hazy pebble
#

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"

ember swan
#

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

subtle valveBOT
hazy pebble
#

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

ember swan
#

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

hazy pebble
#

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?

wooden rampart
#

๐Ÿ‘‹ taking over here

hazy pebble
#

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

wooden rampart
#

Yes what you described sounds aligned to what my colleague suggested. The Refund can be tighted with the PaymentIntent of the previous Invoice #1

hazy pebble
#

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)

#1133907395186274356 message

#

Not sure what they mean by "so it's not pulled into the next invoice"

wooden rampart
#

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

hazy pebble
#

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

wooden rampart
#

Yes! It's nice btw

hazy pebble
#

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 ๐Ÿ™‚