Refunds
Refund a payment.
Rapyd provides a quick and easy method for processing refunds of a purchase made by a customer on your website. Refunds are made to the payment method used in the original payment transaction.
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.
A customer buys an item on your website for 10.99 USD (U.S. Dollars) with his card. Now the customer wants to return the item for a refund. In this use case, the customer paid by card so the refund is returned to that card.
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.
Finding the specific bank transfer payment methods you'll accept and the corresponding required fields that customers fill out is described under How it Works.
The customer has previously paid for the item. Now the customer fills 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 requests from 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.
Refund - Success
Refund - Rejected
The finite state diagram below summarizes the statuses for refunded payments.
Description of Statuses
Status | Description |
---|---|
Pending | The refund is not yet complete. For example, the refund might still require a customer action, such as withdrawing the refund in cash. |
Completed | The refund was completed. |
Rejected | The refund was not made because of an internal error. |
Error | The refund failed. |
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 refund on your website, you ask Rapyd to process the refund.
For that, you'll use Create Refund with the following parameter:
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_1b3e27edf2c43a0b5d1a7de69fbe7102, which is the payment ID we created in our sandbox. |
You do not need to specify the amount since this is a full 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_29816514741fe7e4cdee75f7093ccbe1" }
.NET Core
using System; using System.Text.Json; namespace RapydApiRequestSample { class Program { static void Main(string[] args) { try { var requestObj = new { payment = "payment_29816514741fe7e4cdee75f7093ccbe1", }; 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_29816514741fe7e4cdee75f7093ccbe1' }; 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" ]; 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_29816514741fe7e4cdee75f7093ccbe1" } create_refund_results = make_request(method='post', path='/v1/refunds', body=refund_body) pprint(create_refund_results)
Get Refund Response
Let's take a look at the response.
Response
{ "status": { "error_code": "", "status": "SUCCESS", "message": "", "response_code": "", "operation_id": "bc321df9-7bb4-47ce-907a-7bbc5a9b32f7" }, "data": { "id": "refund_dcdacdb591a117d3d5eb30e59011aadd", "amount": 15.65, "payment": "payment_29816514741fe7e4cdee75f7093ccbe1", "currency": "USD", "failure_reason": "", "metadata": {}, "reason": "", "status": "Completed", "receipt_number": 0, "created_at": 1589302965, "updated_at": 1589302965, "merchant_reference_id": "", "payment_created_at": 1589237080, "payment_method_type": "us_debit_visa_card", "ewallets": [ { "ewallet": "ewallet_be4ba8f13da40caa59a7e03022a8acfe", "amount": 15.65 } ], "proportional_refund": true } }
The data
section of this response shows:
The
amount
is 15.65.The
currency
is USD.The
status
is Completed.
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 the customer 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.