Partial Refunds
Your customer requests a refund for part of a purchase.
Rapyd provides a quick and easy method for processing partial refunds of a purchase.
You can make partial refunds multiple times for the same purchase until the refunds equal the full amount of the original transaction.
Refunds are made to the payment method used in the original payment transaction. In this use case, the customer paid by card so the refund is returned to that card.
PCI Certification
Only clients with PCI-DSS certification can handle personal identifying information for cards. This method is available to merchants who have signed a special agreement with Rapyd.
The customer used a card to buy two copies of an eBook on your website. Now the customer wants a refund for one eBook. The price of each copy of the eBook was 5.99 USD (U.S. Dollars).
Your website back end asks Rapyd to process the refund. When the money is returned to the card, Rapyd notifies you that the refund was completed successfully.
The customer previously paid for the eBooks. The customer has now filled in all the fields required by your website's Refund Request page. You have the ID of the transaction and the amount that needs to be refunded.
The website back end asks Rapyd to process the customer's refund.
Rapyd processes the refund transaction and notifies you that it was successful.
You send confirmation of the refund to the customer.
The message sequence diagrams below describe how information is exchanged between Rapyd, the merchant, and the card issuer.
Partial Refund - Success
Partial Refund - Rejected
Prerequisites
To run the examples of this use case, you must create the following ID in your own sandbox:
payment
- Run Create Payment. Use the 'id' you get in the response.
When the customer requests a partial refund on your website, you ask Rapyd to process the refund.
For that, you'll use Create Refund with the following parameters:
Description of Body Parameters
Body Parameter | Description |
---|---|
payment | Enter the payment 'id' that you received when you created the payment in your sandbox. For purposes of this use case lesson, we are using payment_52b4cb2ba10338e274c689cb759a5043, which is the payment ID we created in our sandbox. |
amount | Enter 5.99 as the amount of the refund. |
Create Refund Request
You ask Rapyd to process the refund of the earlier transaction.
Request
// Request URL: POST https://sandboxapi.rapyd.net/v1/refunds // Message body: { "payment": "payment_52b4cb2ba10338e274c689cb759a5043", "amount": 5.99 }
.NET Core
using System; using System.Text.Json; namespace RapydApiRequestSample { class Program { static void Main(string[] args) { try { var requestObj = new { payment = "payment_52b4cb2ba10338e274c689cb759a5043", amount = "5.99", }; string request = JsonSerializer.Serialize(requestObj); string result = RapydApiRequestSample.Utilities.MakeRequest("POST", "/v1/refunds", request); Console.WriteLine(result); } catch (Exception e) { Console.WriteLine("Error completing request: " + e.Message); } } } }
JavaScript
const makeRequest = require('../../../../../Utilities/JS/utilities').makeRequest; async function main() { try { const body = { payment: 'payment_52b4cb2ba10338e274c689cb759a5043', amount: 5.99 }; const result = await makeRequest('POST', '/v1/refunds', body); console.log(result); } catch (error) { console.error('Error completing request', error); } }
PHP
<?php $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/code_race_2020/Utilities/PHP/utilities.php"; include($path); $body = [ "payment" => "payment_29816514741fe7e4cdee75f7093ccbe1", "amount" => 5.99 ]; try { $object = make_request('post', '/v1/refunds', $body); var_dump($object); } catch (Exception $e) { echo "Error: $e"; } ?>
Python
from pprint import pprint from utilities import make_request refund_body = { "payment": "payment_52b4cb2ba10338e274c689cb759a5043", "amount": 5.99 } create_refund_results = make_request(method='post', path='/v1/refunds', body=refund_body) pprint(create_refund_results)
Create Refund Response
Let's take a look at the response.
Response
{ "status": { "error_code": "", "status": "SUCCESS", "message": "", "response_code": "", "operation_id": "b79147b4-a919-4ad0-9942-8134ed1dad95" }, "data": { "id": "refund_80cfd3f26326164a54bdc42535dc8bf3", "amount": 5.99, "payment": "payment_52b4cb2ba10338e274c689cb759a5043", "currency": "USD", // ... "status": "Pending", "receipt_number": 0, "created_at": 1581005810, "updated_at": 1581005810, "merchant_reference_id": "", "payment_created_at": 1581005363, "payment_method_type": "mx_banamex_cash", "ewallets": [ { "ewallet": "ewallet_090e1ef18c3aa754fd43cce9ee454858", "amount": 5.99 } ], "proportional_refund": true } }
The data
section of this response shows:
The
amount
is 5.99.The
currency
is USD.The
status
is Pending. This means that completing the refund process requires additional steps.
Note
If the payment was made by cash or a bank redirect, completing the refund process requires the same extra steps as the original payment method. To simulate the action of the customer, run Complete Refund.
Rapyd sends a webhook to notify you that the refund transaction is complete.
After all additional steps have been made, your website shows John Doe a confirmation that the refund is complete.
To view the details of the payment and the refund, use Retrieve Payment.
Looking for More In-Depth Technical Information?
Want to see the Rapyd API methods and objects that you'll use? Visit the API Reference for more technical details.