Integrating Stripe sdk with React Native - part III -Refunding

Krishan Madushanka
4 min readSep 27, 2022

--

Stripe Refunding React Native Node

This is the part III of article series on integrating Stripe sdk with React Native.Before reading this article I kindly invite you to read my previous articles on integrating Stripe sdk with React Native.

These 2 articles will guide you on how to accept a payment and how to handle multiparty payments with stripe. To discuss about refunding you should have the prior knowledge about Stripe’s,

  • Payment intents
  • Accepting payments
  • Connected account types
  • Charge types

We’ll be using a node backend and react native front end. To know how to setup those environments refer my first article on accept a payment.

Refunds can be issued using the API or the Dashboard and are processed immediately. When issued, refunds can’t be canceled.

To refund a payment using the API, create a refund and provide the ID of the charge or payment intent to be refunded.

When you use a payment intent to collect payment from a customer, Stripe creates a charge behind the scenes. To refund the customer’s payment after the payment intent has succeeded, create a refund using the payment intent, which is equivalent to refunding the underlying charge. You can also optionally refund part of their payment by specifying an amount.

Refund using payment intent

We should expose a rest api for this and we’ll be using previuos node codebase for this.

You should keep track of payment intent ids you created in your db to issue a refund using payment intent id.Optionally you can specify an amount also.

const refund = await stripe.refunds.create({
payment_intent: 'pi_Aabcxyz01aDfoo',
amount: 1000,
});

You can issue more than one refund against a charge, but you can’t refund a total greater than the original charge amount.

We should call the exposed API from frontend to complete the refund.

Refund using dashboard

  • Find the payment to be refunded in the payments tab of the dashboard.
  • Click the ••• icon to the right of the charge. From the resulting menu, select Refund payment.
Stripe Refunding React Native Node
  • By default, you’ll issue a full refund. For a partial refund, enter a different amount to be refunded.
  • Select a reason for the refund. If you select Other, you must provide an explanatory note that is attached to the refund.
Stripe Refunding React Native Node
  • Click Refund.

You can go to the specific payment from Dashboard and and click Refund there also.

Stripe Refunding React Native Node

Refunding multiparty payments

For multiparty payments refunding differs from each other on the charge type.To get an understanding about multiparty payments and charge types read previous article.

Refunding a direct charge

To refund a direct charge on a connected account, perform a create refund request using your platform’s secret key while authenticated as the connected account.

We can get above charge id by calling list all charges API with payment_intent specified.The API will return all the charges made on that payment intent(For testing purposes you can directly go to dashboard and click on specific payment->copy charge id from there).If we want to refund the application fee also, we can set that parameter true. Refunded amount will be deducted from connected accoun’s balance.

Refunding a destination charge

Let’s write an API in backend side for that.

Here also we can get the charge id using the API that we discussed in refunding a direct charge.By default the destination account keeps the funds that were transferred to it, leaving the platform account to cover the negative balance from the refund. To pull back the funds from the connected account to cover the refund, set the reverse_transfer parameter to true when creating the refund. If we want to refund the application fee also, we can set refund_application_fee parameter true.

Refunding separate charges and transfers

Charges created on your platform can be refunded with charge id. However, refunding a charge has no impact on any associated transfers. It is up to your platform to reconcile any amount owed back to your platform by reducing subsequent transfer amounts or by reversing transfers.

Here also we can get the charge id using the API that we discussed in refunding a direct charge.

For all 3 types of charges you can do refunding through dashboard also.

Thanks for reading. 😊 Your feedback is appreciated.

--

--

Krishan Madushanka

Software Engineer | Android | iOS | Flutter | React Native | IoT | aws certified