#Mickey
1 messages ยท Page 1 of 1 (latest)
I can help you out! What's your question?
Hi karbi. I was asking with this #dev-help message
but then I gotta out for a while
how to get that?
You can usually find that in the dashboard https://dashboard.stripe.com/test/logs
I think this one: req_IU6XBLdEhTrY4i
I was trying to create that credit notes then cancel the subscription after that
Per requirements, We would not allow to use credit balance for cancelling or downgrading
And how'd you get the value for 56.27 that you passed in for the credit note?
I use stripe.invoices.retrieveUpcoming()
With which values? and can you share the full response you get back from that request?
And which attribute are you looking at to get the 56.27?
// Calculate the partial refund amount
let remainCents = 0;
for (let i = 0; i < invoices.lines.data.length; i++) {
const invoiceItem = invoices.lines.data[i];
if (invoiceItem.period.start == prorationDate) {
currentProrations.push(invoiceItem);
remainCents += invoiceItem.amount;
if (invoiceItem.tax_amounts)
remainCents += invoiceItem.tax_amounts[0].amount;
}
}
const refundAmount = (remainCents < 0) ? remainCents * -1 : remainCents;
I got them from the lines items with the prorated moment
Gotcha - just to make sure I have this right, you're trying to generate a credit note to refund some amount for an immediate cancellation?
got it
so I believe the issue here is with how you're creating the credit note - you're passing in an invoice_line_item , which we interpret as you want to credit the ENTIRE invoice line item amount (which is 56.44 in the request that you sent over).
You need to be creating a custom_line_item credit note instead
says: I have to items that make up the total refund
How should it be for this case?
const creditNote = await stripe.creditNotes.create({
invoice: paidInvoices.data[0].id,
lines: [
{ type: 'custom_line_item', description: "Unused times for item A", quantity: 1, amount: 4965 }
{ type: 'custom_line_item', description: "Taxes for Unused times for item A", quantity: 1, amount: 645}
]
})
Do you think this will work?
Will it create a corresponding refund and will the invoice includes the tax as a separated line as well?
I don't think you'd need the separate line item for the tax - what you'd want to do is tweak your code calculating the refund amount to not include tax like this
// Calculate the partial refund amount
let remainCents = 0;
for (let i = 0; i < invoices.lines.data.length; i++) {
const invoiceItem = invoices.lines.data[i];
if (invoiceItem.period.start == prorationDate) {
currentProrations.push(invoiceItem);
remainCents += invoiceItem.amount;
}
}
const refundAmount = (remainCents < 0) ? remainCents * -1 : remainCents;
and then generate the credit note for that amount
The credit note should automatically incorporate the tax for you
OK, I'll try right now
Unluckily I got this error: message:
'Custom line items are not supported for invoices with automatic_tax.enabled = true.'
const line1 = paidInvoices.data[0].lines.data[0];
const creditNote = await stripe.creditNotes.create({
invoice: paidInvoices.data[0].id,
lines: [
{ type: 'custom_line_item', description: "Unused times for item A", quantity: 1, unit_amount: 4965 }
],
});
req_r6W3lV2kjE7Wko
Sure, Thanks karbi
Sorry that took a while - had to try a few things out
So I'd go back to using invoice_line_item (not custom line items) but set amount instead of quantity. And the amount that you set for the line item should be equal to the amount you calculate w/o tax
Ok
Thanks for your finding.
Will it still require the refund_amount param or just within the line item?
const line1 = paidInvoices.data[0].lines.data[0];
const creditNote = await stripe.creditNotes.create({
invoice: paidInvoices.data[0].id,
lines: [
{ type: 'invoice_line_item', invoice_line_item: line1.id, quantity: line1.quantity, unit_amount: line1.amount }
],
});
Yeah you should still set the refund_amount param (which you'll want to set to the amount WITH tax)
Ok
req_Cgy4dY3XoftYke
I went back to the original error unfortunately
const line1 = paidInvoices.data[0].lines.data[0];
const creditNote = await stripe.creditNotes.create({
invoice: paidInvoices.data[0].id,
lines: [
{ type: 'invoice_line_item', invoice_line_item: line1.id, amount: line1.amount } //quantity: line1.quantity,
],
refund_amount: refundWTax
});
This is confusing
Is there any other way to use refund API for this requirements of partial refund with tax?
This line is the issue:
{ type: 'invoice_line_item', invoice_line_item: line1.id, amount: line1.amount } //quantity: line1.quantity,
],
Are you pulling line1.amount from the latest Invoice or the upcoming Invoice? Your request passed in 4995 (which is the cost of the original line item) instead of 4559 (which would be the refund w/o tax)
oh my bad. Let's me check it again
req_wKiKzg4Wp7SFCw
I tried the amount:4954 (total refund without tax) but still error
Response body
{
"error": {
"message": "The sum of credit amount, refund amount and out of band amount ($55.98) must equal the credit note amount ($55.97).",
"request_log_url": "https://dashboard.stripe.com/test/logs/req_42V8t8F3x6htdt?t=1680289528",
"type": "invalid_request_error"
}
}
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
It was because of 1 cent different
They are all in integer of number of cents. Do you how to avoid this?
Yeah it's a rounding issue at this point - give me a bit to type this all out:
So if you really wanted to solve this I'd do something like this:
- Use the upcoming Invoices API to sum up all the prorations (Without tax) you want to refund for
- Use the preview credit note API (https://stripe.com/docs/api/credit_notes/preview) with that proration amount as an invoice line item which will calculate the automatic tax and do the rounding for you so you know the exact total amount
- Generate the real credit note using the same proration amount and the calculated total you got from previewing the credit note
Thanks karbi. I will try right now
It seems working now
const creditNotePreview = await stripe.creditNotes.preview({
invoice: paidInvoices.data[0].id,
lines: [
{ type: 'invoice_line_item', invoice_line_item: line1.id, amount: refundAmount } //quantity: line1.quantity,
],
});
const creditNote = await stripe.creditNotes.create({
invoice: paidInvoices.data[0].id,
lines: [
{ type: 'invoice_line_item', invoice_line_item: line1.id, amount: refundAmount } //quantity: line1.quantity,
],
refund_amount: creditNotePreview.amount
});
awesome! (and sorry this was so difficult to get working)
cool. I really appreciate your help
pi_3MrhkeJxyI1MWs2T1cMW7aBQ
I will need to check for the refund invoice now
I could not find the corresponding refund invoice for this transaction
Will it send the receipt in production mode without manually send it from the Dashboard?
Yes in production as long as the "email finalized invoices" setting is enabled in the dashboard (https://dashboard.stripe.com/settings/billing/automatic) the credit note will be automatically emailed to the customer
Ok. Got it
I deleted that last message since it has your email in it and this is a public channel
but what questions do you have?
Thanks for that. What does Adjusted invoice total of $0.50 means?
That's just the original invoice total - the credited amount
yes, got it now
the used cost ๐
I've got two emails: 1 for the credit notes, 1 for the receipt the I manually did
So to confirm, Is credit notes the only way to handle refund with tax?
You're welcome to refund the Payment Intent directly without a credit note, but the only way to link the refund directly to the Invoice and get a new PDF is with the credit note
Do you mean the new PDF is the Refund file or the credit note file?
What we want to achieve is to refund (partially most of the cases) and clearly mentioned the tax amount for reporting liability
When using the refund API it only do a fixed total refund amount
If you need the tax amount to be clearly separated like that then definitely use credit notes
Please hang on with me for couple minutes as I will discuss this with our accountant as well
@earnest bramble I need to head out, but if you have any other questions codename_ducchess is around and can help
I am back. Thanks for holding on with me
๐ Did you need anything else?
I think we are OK now. Great thanks for your help and patient. ๐
I hope you have a great weekend
๐ glad I could help!