Request refund

1. Get payment token

Start by generating a payment token. Make a HTTP POST request to the relevant endpoint + /api/oauth/token/ using the access token you generated.

Request

curl --location --request POST 'https://uat.app.payvyne.com/api/oauth/token' 
--header 'Content-Type: application/x-www-form-urlencoded' 
--data-urlencode 'grant_type=client_credentials' 
--data-urlencode 'client_id=<payment_key>'
--data-urlencode 'client_secret=<payment_secret>’

👍

Try it out

If your request was successful you will receive a payment token like this in the response eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjaGFudElkIjoxLCJzY29wZSI6WyJwYXkiXSwiaXNzIjoiaHR0cDovL2FwcC5kZXYucGF5dnluZS5zeXN0ZW1zIiwiZXhwIjoxNTg2MzY5NzExLCJpYXQiOjE1ODYzNjYxMTEsImF1dGhvcml0aWVzIjpbIlJPTEVfUEFZIl0sImp0aSI6ImExY2UzZjdmLTE3MzItNDhmNC04NTI3LTA5NWQ5NjlhNjkzNSIsImNsaWVudF9pZCI6IllNUFE2aDZQYTNaYmpEMXplbkQ0eXcifQ.g3XSXftyHvlCL1z1tlW6khboY7hzbiZVZgIzKHF2Rdc

2. Create refund request

Then, create a RRRR - Refund Request. Send an HTTP POST request to the relevant endpoint + /api/v1/refunds/init including the headers Authorization: Bearer <payment_token>. The RRRR - Refund Request body should contain the list of payment IDs to be refunded and the refund amounts.

Request

curl --location --request POST 'https://uat.app.payvyne.com/api/v1/refunds/init' \
--header 'Authorization: Bearer <payment_token>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "payments": [
        {
            "paymentId": "1ac613c7ca3eca52",
            "amount": 2.4
        },
        {
            "paymentId": "4d6fb61dd6eb0c7b",
            "amount": 9
        },
        {
            "paymentId": "2178e53c08b1f3f5",
            "amount": 0.1
        },
        {
            "paymentId": "1ac613c7ca3eca52",
            "amount": 1.00
        },
        {
            "paymentId": "1a17fe039cd34777",
            "amount": 99999.99
        },
        {
            "paymentId": "4de89355d8fc67b0",
            "amount": 1
        }
    ]
}'

Response

{
    "refunds": [
        {
            "id": "REFUND-1bd7805da16df89e",
            "status": "NEW",
            "amount": 2.4,
            "currency": "GBP",
            "paymentId": "1ac613c7ca3eca52"
        },
        {
            "id": "REFUND-46713c3a44ad27f0",
            "status": "NEW",
            "amount": 0.1,
            "currency": "GBP",
            "paymentId": "2178e53c08b1f3f5"
        }
    ],
    "errors": [
        {
            "paymentId": "4d6fb61dd6eb0c7b",
            "errorMessage": "Payment is not in SETTLED or PART_REFUNDED status!"
        },
        {
            "paymentId": "1ac613c7ca3eca52",
            "errorMessage": "Multiple refunds cannot be made at the same time"
        },
        {
            "paymentId": "1a17fe039cd34777",
            "errorMessage": "The refund amount cannot be greater than the payment amount"
        },
        {
            "paymentId": "4de89355d8fc67b0",
            "errorMessage": "Could not find payment with ID=4de89355d8fc67b0"
        }
    ]
}

Response

Description

Success

A successful RRRR - Refund Request returns a 202 response code with refunds and/or errors lists.

Failure

If the RRRR - Refund Request failed, an HTTP status code and a JSON response are returned that contain detailed information about the error.

Parameter

Description

refunds

A list of payment IDs that have initiated refunds successfully.

errors

A list of error details for payments that could not be refunded. The error object contains the payment ID and a short description explaining why the refund request failed.


What’s Next

Now you've successfully requested a refund, learn how to get refund status updates.

Did this page help you?