#mochihealth

1 messages · Page 1 of 1 (latest)

brisk vesselBOT
bronze pecan
#

also for refunds do i want to use the refunds api or the credit_note api

bronze current
#

When a subscription is cancelled, the balance will be credited to the customer's balance and not refunded by default: https://stripe.com/docs/billing/customer/balance

The steps for refunding the customer's credit will be:

  1. Look for amount on customer's credit
  2. Use List Invoice API with subscription set and expand charge field to find charges of invoices on the subscription: https://stripe.com/docs/api/invoices/list
  3. If there's any associated charge, create the refund on the charges up to amount of customer's balance
  4. Update customer's balance to 0: https://stripe.com/docs/api/customers/update#update_customer-balance
#

For above steps, cancelling subscription will be required in order to generate the customer's balance

bronze pecan
#

but when I cancel a subscription through the stripe dashboard it makes a delete request to the subscription id and a post request to credit notes

#

and it has a refund amount in it

#

?

bronze current
#

Could you share the request ID (req_xxx) of your screenshot?

bronze pecan
#

does it matter if its in test mode

#

req_woNZnIpqJdGkGB

bronze current
#

Ah yes! If the subscription is cancelled in dashboard and issuing credit card with refunding to customer's payment method, then remaining balance will be refunded

#

However, cancelling subscription in this flow will cancel the subscription first, then refund to the customer

#

It's not possible to have a successful refund first, then cancel the subscription

bronze pecan
#

so what happens if i cancel the subscription and then an error occurs with the refund

bronze current
#

When the refund fails, this is likely that the payment method is not applicable to refund or something goes wrong. In this case, your system has to refund to customer through other means such as issuing voucher or other forms of refund outside of Stripe

bronze pecan
#

so which refund flow should i follow

#

the one that you initially laid out or the one that i saw on the stripe dash

bronze current
#

Both ways work!

You can either refund manually on the charges of invoices or use credit notes on the subscription invoices.

bronze pecan
#

can you explain to me the lines field on the credit note

#

like if a subscription had a price where the quantity was 2 would i have to put quantity 2 here

#

how would i refund a custom amount

#

is the line item field and the refund amount linked in anyway

#

line field not line item

bronze current
#

You can use lines.type: 'custom_line_item' for custom amount. For example,

const creditNote = await stripe.creditNotes.create({
  invoice: "in_xxx", 
  lines: [{
    description: "Custom credit lalala", 
    quantity: 1,
    type: "custom_line_item",
    unit_amount: 7500,
  }],
  refund_amount: 7500,
});
bronze pecan
#

so what does the quantity and the unit_amount represent in that scenario

#

?

bronze current
#

Thanks for waiting! Quantity is the number that you would like to reflect in the invoice whereas unit_amount is the amount of that line items

#

the sum of unit_amount in lines should be the same as refund_amount

bronze pecan
#

the sum of unit_amount?

#

you mean like the product of unit_amount and quantity should be the same as refund_amount

#

still a bit confused on this

bronze current
#

For example, if you have multiple lines, the total unit_amount of each line should be the same as refund_amount

bronze pecan
#

like each individually or cumulatively

bronze current
#
  invoice: "in_xxxi",
  refund_amount: 250,  // integer 
  lines: [{
    description: "Refund A", 
    quantity: 1,  // integer 
    type: "custom_line_item",
    unit_amount: 100,  // integer 
  }, {
    description: "Refund B", 
    quantity: 1,  // integer 
    type: "custom_line_item",
    unit_amount: 150,  // integer 
  }],
}

In this example, the unit_amount (100) of Refund A + unit_amount (150) of Refund B must be equal to refund_amount (250)

#

100+150=250

bronze pecan
#

when would there be multiple lines on a refund

#

like if there were multiple subscription items?

bronze current
#

This is just an example. It's up to you how you would like to credit note to be a lump sum of total refund or breaking down into the individual items

#

Ultimately, it's on your business decision about how to show in as the lines in the invoice

bronze pecan
#

so is the lines field more of a meta data field or does it actually have an impact on the refund

bronze current
#

The lines field are for display purpose on the invoice

#

The total amount of lines have to tally the total amount of refunding, otherwise the API will fail

bronze pecan
#

gotcha

#

and where would i get the li_xxx object

#

and also what is the difference of the first two approaches and just calling charges/ch_3MbSVcBPM36OC3gX1aNwPKfD/refund

bronze current
#

Checking it how li_xxx was generated in req_woNZnIpqJdGkGB

#

also what is the difference of the first two approaches and just calling charges/ch_3MbSVcBPM36OC3gX1aNwPKfD/refund
The first approach I proposed is technically this charges/ch_3MbSVcBPM36OC3gX1aNwPKfD/refund (Step 3 more exact). With direct refunding, it won't show any refund entry on the invoice

bronze pecan
#

ah ok so if i plan on refund the full amount i should use the line item or is it ok to do custom_line item with the same amount

#

sorry for all the questions you are being very helpful!

#

for subscription upgrades i want the update to start on the next cycle and for subscription downgrades I also want it to start on the next cycle and not right away should I use subscription schedules for this?

bronze current
#

ah ok so if i plan on refund the full amount i should use the line item or is it ok to do custom_line item with the same amount
You can do either way!

for subscription upgrades i want the update to start on the next cycle and for subscription downgrades I also want it to start on the next cycle and not right away should I use subscription schedules for this?
Yes! Subscription schedule is the way to do it!

bronze pecan
#

if i wanted to increase or decrease the quantity of a price in a subscription would i just do that with a standard post request to subscription api or with the schedule api