#alex_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/1478706644761186365
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Yep, we removed those properties in the Basil release. Worth noting though that you opt into the old version of a per request basis and those properties will be available again
So you're working with a ch_xxx ID and need to get the associated Invoice and any Credit Note(s) generated?
In fact I am redoing the old version of the app and I am rewriting the whole fetching process. So, just want to follow best practices you have for this. I could be fetching charges or invoice payments - whatever is best. What I need is to be able to trace it back to the original invoice. The same for creditNotes (I don't see refunds having a reference to credit notes - so it is a bit more confusing for me than with invoice payment).
opting in on a per-request basis is a good tip, but your sdk will throw a typescript error, like: Type '"2022-08-01"' is not assignable to type '"2026-02-25.clover"'
thanks for the context - so to confirm, you want to get the associated invoice (in_xxx), and credit note (cn_xxx) from the charge ID (ch_xxx)?
just hoping to confirm what object you're starting with, and what resources you need to get to
yes, but I am open to changes.
ideally it would be from the level of balanceTransaction - I will be summing them for the given period to ensure all transactions were processed. It seems I might be able to find a charge on the given transaction through the "source" property. Am I correct?
yep that's correct! the structure of objects, the flow from Charge to Credit Note would look like:
Charge > PaymentIntent > Invoice Payment > Invoice > Credit Note
so you'd want to:
-
Check the
payment_intentproperty on the Charge to get the PaymentIntent ID
https://docs.stripe.com/api/charges/object#charge_object-payment_intent -
List Invoice Payments, passing the PaymentIntent in
payment.payment_intent
https://docs.stripe.com/api/invoice-payment/list#list_invoice_payments-payment-payment_intent -
Get the Invoice ID from the
invoiceproperty on the Invoice Payment
https://docs.stripe.com/api/invoice-payment/object#invoice_payment_object-invoice -
List all Credit Notes for that Invoice
https://docs.stripe.com/api/credit_notes/list#list_credit_notes-invoice
SO it seems I could just fetch the list of invoice payments in the given period and there I would have charges (to get my balanceTransactions for final validation) and the invoice. Correct?
If so, is there a way to go directly from refund/balanceTransaction to the related CreditNote, or do I always have to retrieve the invoice first?
yeah you could fetch Invoice Payments - but the Charge ID wouldn't be included within the Invoice Payment object itself
you'd need to retrieve the associated PaymentIntent and expand the latest_charge property, to get the Balance Transaction ID from within the Charge
https://docs.stripe.com/api/payment_intents/object#payment_intent_object-latest_charge
^^ to be clear, I'm referring to the Balance Transaction for the Charge here, not the Refund (which will have a separate Balance Transaction)
and no, there's no way to get directly from Refund/BT to Credit Note I'm afraid - the Credit Note exists as essentially an 'adjustment' to an Invoice object, so it's only tied to the Invoice, rather than the underlying objects
So:
- Regarding the invoice: I see that invoicePayment has a payment.charge field (https://docs.stripe.com/api/invoice-payment/object#invoice_payment_object-payment-charge), but from what you are saying, I should not rely on it. correct?
- Regarding the creditNote: Refunds and associated creditNotes can potentially be created months after the original invoice. So, if I have to go through the original invoice to get to it, would would be the most efficient way to do that? From what I see, a refund has a charge, that would have a payment_intent, and then I follow the steps you listed. Is that the best way?
that depends on whether your integration uses legacy Charges directly, but since you're using invoices (which inherently use PaymentIntents), that property likely isn't relevant given your current setup
you can see this in the API reference:
ID of the successful charge for this payment when type is charge.Note: charge is only surfaced if the charge object is not associated with a payment intent. If the charge object does have a payment intent, the Invoice Payment surfaces the payment intent instead.
OK, and for the CreditNotes, the suggested path is also: charge->payment_intent->list invoice payments -> invoice Id -> list credit notes?
Can you confirm?
yes that's the right path to get from a charge to a credit note
of course, if you're starting from the refund or balance transaction, then you'd need to get from there to the charge first
thanks. I think I am good now. If I had some related questions can I comment in this thread or start a new one? I think you were automatically closing them after some time.
If you have questions now, you can ask them here
Otherwise, if the thread is idle for a while, it'll get closed. But you can always start a new thread, and it'll be linked to this one ๐
Cool. thanks a lot.