#mangle8582
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- mangle8582, 5 days ago, 37 messages
- mangle8582, 6 days ago, 38 messages
When you say 'refund', what exactly do you mean? What are you refunded or what API call are you making then you see that error?
nextInvoice = await stripe.invoices.finalizeInvoice(
deletedSubscription?.latest_invoice
);
const refund = await stripe.refunds.create({
payment_intent: subscriptionToDeleteAndRefund?.payment_intent,
amount: nextInvoice.ending_balance ? Math.abs(nextInvoice.ending_balance) : 0,
});
await stripe.customers.createBalanceTransaction(
subscriptionToDeleteAndRefund?.dataValues?.customer_id,
{
amount: -nextInvoice.ending_balance,
currency: 'usd',
}
);
I make these three. I believe stripe.refunds.create throws that error
Can you share the ID (req_xxx) of the API request? https://support.stripe.com/questions/finding-the-id-for-an-api-request
Find help and support for Stripe. Our support site provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
req_UdYPpeXsF7SAu7 the req Id that failed
req_oOSNYz6SWkEZvP
This was the upgrade to Yearly from Monthly
Seems expected given that the pi_xxx you're trying to refund is for a lesser amount than you're stipulating. You can't refund beyond that payment amount
Yea, but i'm taking the refund amount from nextInvoice after i finalize it
nextInvoice = await stripe.invoices.finalizeInvoice(
deletedSubscription?.latest_invoice
);
I'm ok with it to refund the exact amount he did for the upgrade. But i need it to come on finalizeInvoice
Also the invoiceUpcoming is still higher than the amount he paid when upgraded
{
customer: 'cus_PZKpmcyiaCus0G',
subscription: 'sub_1OmOwjDmVlmqORBIPD2ybaYb',
subscription_proration_behavior: 'create_prorations',
subscription_cancel_now: true
}
Hi! I'm taking over from my colleague. Please, give me a moment to catch up.
Sure, thanks
What exactly do you want to refund? Because it seems like you want to refund for part of the monthly Invoice + part of the yearly Invoice, but it needs to be done separately.
Yea, but i'm fine to refund just the yearly amount for the upgrade and do the refund for monthly directly from dashboard
But the invoiceUpcoming and finalizeInvoice doesn't return the correct amount
it returns the value that i need to refund + the monthly subscription and Stripe throws error on refund
I don't really follow when do you request the upcoming invoice and then when do you refund.
Are you requesting the upcoming invoice for the proration?
Yes, user clicks on Remove & Refund Subscription, a modal comes up. I make the call to invoiceUpcoming with prorated amount and show to the user the amount on the UI. He then can press refund and makes an API call -> that does the above things with finalizeInvoice, createRefund etc
But does it happen after the upgrade of Subscription?
Yeah.
So my issue is only on upgrade.
- If user buys monthly directly and i show modal with invoiceUpcoming and do the refund, everything works correctly.
- If user buys yearly directly refund and invoiceUpcoming works fine.
- If user buys monthly, then upgrades and he then wants to refund. The invoiceUpcoming shows more than the amount for the upgrade and if i want to refund him the amount from finalizeInvoice , stripe throws error that the amount to refund is higher than the user paid for
For case 3, upcoming Invoice after the upgrader will show the next period's Invoice. You should instead use the amount paid for the last Invoice.
How can i do that? Because it needs to prorate from the amount paid for the last invoice
You can find the latest_invoice here: https://docs.stripe.com/api/subscriptions/object#subscription_object-latest_invoice
It will already contain the proration and the total amount.
On the current subscription right?
I need to take the id of that latest invoice and make a call to see the amount?
Yes, or you can expand the Subscription.latest_invoice field: https://docs.stripe.com/expand
And it really comes prorated? Like if 1 week passed it will be less than the amount paid so i can show to the user or refund?
It's best to check for yourself. It's the Invoice that was already paid so it won't change and is exactly the amount that was charged, therefore will be refundable.
Yea, but if i want to do prorated from that amount? User is using the application and we pay servers, by doing multiple full refunds users can use the app without paying ever. So that's why we use prorated
What do you mean by "prorated" here exactly?
You mean you want to issue a partial refund?
Yea, if user upgrades with 64$ let's say. If 10 days pass, they will get back 58$ or something. But if latest_invoice says 64$ how can i calculate that?
You will need to calculate it yourself and set the Refund amount: https://docs.stripe.com/api/refunds/object#refund_object-amount
Subscription prorations have nothing to do with this.
Uff.. if i have prorated amount from monthly i need to remember it then substract it, and substract it also on invoicePreview.
Is there a flag that i could know if the subscription was upgraded and not directly bought?
Hey! Taking over for my colleague.
Is there a flag that i could know if the subscription was upgraded and not directly bought?
You can track that in your integration
I strongly encourage you to start working on concrete similation using Stripe Test Clock:
https://docs.stripe.com/billing/testing/test-clocks
Yea, working with it.
So if i make the API call /upgrade-to-yearly that calls Stripe, i believe i can set the flag in my database that was upgraded.
And then on next webhook to make it false
Yes that's an option
but invoice.paid is also triggered on invoice.paid webhook
Maybe i can check the current subscription if it's monthly or smth and next one
and set this flag
What you mean by this ?
When you upgrade invoice.paid is still triggered.
When you wait one year and it automatically pays, the invoice.paid webhook still triggers.
So where i can set the flag or how?
Maybe on customer.subscription.updated
When you upgrade invoice.paid is still triggered.
When you wait one year and it automatically pays, the invoice.paid webhook still triggers.
Yes correct
So where i can set the flag or how?
You need to add some additional checks, not only when receiving a particular webhook event
You probably want to check the previous attribut in the event body:
https://docs.stripe.com/api/events/object#event_object-data-previous_attributes
and see if the priceId was changed for example or not...
can i check this in the webhook customer.subscription.updated? Or on upgrade route? Because i need the id of that event to make the GET
Yes any webhook event body, will have the previous_attributesif there is a change on an attribute
perfect! thanks