Run a referenced refund for a card payment

A merchant can use the payment details of a card payment to run a referenced refund. To run a referenced refund, the merchant should first retrieve the payment information in one of the following ways:

  • Use the paymentId.
  • Search for the payment using payment information such as the card number.

Note: If the merchant runs a refund on a payment that is in an open batch, our gateway automatically cancels the payment.

Integration steps

Step 1. Retrieve information about the original payment.
(Optional) Step 1a. Retrieve information about the payment using the paymentId.
(Optional) Step 1b. Retrieve information about the payment without the paymentId.
Step 2. Refund the payment.

Before you begin

Bearer tokens

Use our Identity Service to generate a Bearer token to include in the header of your requests. To generate your Bearer token, complete the following steps:

  1. Include your API key in the x-api-key parameter in the header of a POST request.
  2. Send your request to https://identity.payroc.com/authorize.

Note: You need to generate a new Bearer token before the previous Bearer token expires.

Example request

$curl --location --request POST 'https://identity.payroc.com/authorize' --header 'x-api-key: <api key>'

Example response

If your request is successful, we return a response that contains your Bearer token, information about its scope, and when it expires.

1{
2 "access_token": "eyJhbGc....adQssw5c",
3 "expires_in": 3600,
4 "scope": "service_a service_b",
5 "token_type": "Bearer"
6}

Headers

To create the header of each POST request, you must include the following parameters:

  • Content-Type: Include application/json as the value for this parameter.
  • Authorization: Include your Bearer token in this parameter.
  • Idempotency-Key: Include a UUID v4 to make the request idempotent.
$curl
>-H "Content-Type: application/json"
>-H "Authorization: <Bearer token>"
>-H "Idempotency-Key: <UUID v4>"

Errors

If your request is unsuccessful, we return an error. For more information about errors, see Errors.

Step 1. Retrieve information about the original payment

1a – (Optional) Retrieve information with the paymentId

Send a GET request with the paymentID to the Payments endpoint.

Path parameters

paymentIdstringRequired=10 characters
Unique identifier of the payment that the merchant wants to retrieve.

Example request

GET
/v1/payments/:paymentId
1curl https://api.payroc.com/v1/payments/ \
2 -H "Authorization: Bearer <token>"

Response fields

If your request is successful, we retrieve the card payment information and return a response. The response contains the following fields:

Example response

Response
1{
2 "paymentId": "M2MJOG6O2Y",
3 "processingTerminalId": "1234001",
4 "order": {
5 "amount": 4999,
6 "currency": "USD",
7 "orderId": "OrderRef6543",
8 "dateTime": "2024-07-02T15:30:00Z",
9 "description": "Large Pepperoni Pizza"
10 },
11 "card": {
12 "type": "MasterCard",
13 "entryMethod": "keyed",
14 "cardNumber": "453985******7062",
15 "expiryDate": "1225",
16 "securityChecks": {
17 "cvvResult": "M",
18 "avsResult": "Y"
19 }
20 },
21 "transactionResult": {
22 "type": "sale",
23 "status": "ready",
24 "responseCode": "A",
25 "responseMessage": "OK3",
26 "approvalCode": "OK3",
27 "authorizedAmount": 4999,
28 "currency": "USD"
29 },
30 "operator": "Postman",
31 "customer": {
32 "firstName": "Sarah",
33 "lastName": "Hopper",
34 "billingAddress": {
35 "address1": "1 Example Ave.",
36 "city": "Chicago",
37 "state": "Illinois",
38 "country": "US",
39 "postalCode": "60056",
40 "address2": "Example Address Line 2",
41 "address3": "Example Address Line 3"
42 },
43 "shippingAddress": {
44 "recipientName": "Sarah Hopper",
45 "address": {
46 "address1": "1 Example Ave.",
47 "city": "Chicago",
48 "state": "Illinois",
49 "country": "US",
50 "postalCode": "60056",
51 "address2": "Example Address Line 2",
52 "address3": "Example Address Line 3"
53 }
54 }
55 },
56 "supportedOperations": [
57 "capture",
58 "fullyReverse",
59 "partiallyReverse",
60 "incrementAuthorization",
61 "adjustTip",
62 "setAsPending"
63 ],
64 "customFields": [
65 {
66 "name": "yourCustomField",
67 "value": "abc123"
68 }
69 ]
70}

1b (Optional) – Retrieve information without the payment ID

Send a GET request to the Payments endpoint.

Request parameters

To create the body of your request, use the following parameters:

Example request

GET
/v1/payments
1curl -G https://api.payroc.com/v1/payments \
2 -H "Authorization: Bearer <token>" \
3 -d orderId=OrderRef6543 \
4 -d operator=Jane \
5 --data-urlencode cardholderName=Sarah%20Hazel%20Hopper \
6 -d first6=453985 \
7 -d last4=7062 \
8 -d tender=ebt \
9 -d tipMode=noTip \
10 -d tipMode=prompted \
11 -d type=sale \
12 -d type=preAuthorization \
13 -d status=accepted \
14 -d status=ready \
15 -d status=complete \
16 --data-urlencode dateFrom=2024-07-01T15:30:00Z \
17 --data-urlencode dateTo=2024-07-03T15:30:00Z \
18 -d settlementState=settled \
19 -d settlementDate=2024-07-02 \
20 -d before=2571 \
21 -d after=8516 \
22 -d limit=25

Response fields

If your request is successful, we retrieve a list of card payments and return a response. The response contains the following fields:

Response

datalist of objectsRequired
Array of transactions.
countintegerOptional
Number of results that we returned.
hasMorebooleanOptional
Indicates that further results are available.
limitintegerOptional
Maximum number of results that we return for each page.

Example response

Response
1{
2 "data": [
3 {
4 "paymentId": "M2MJOG6O2Y",
5 "processingTerminalId": "1234001",
6 "order": {
7 "amount": 4999,
8 "currency": "USD",
9 "orderId": "OrderRef6543",
10 "dateTime": "2024-07-02T15:30:00Z",
11 "description": "Monthly Premium Club subscription"
12 },
13 "card": {
14 "type": "Visa Credit",
15 "entryMethod": "icc",
16 "cardNumber": "453985******7062",
17 "expiryDate": "1225",
18 "cardholderName": "Sarah Hopper",
19 "secureToken": {
20 "secureTokenId": "MREF_abc1de23-f4a5-6789-bcd0-12e345678901fa",
21 "customerName": "Sarah Hopper",
22 "token": "296753123456",
23 "status": "notValidated",
24 "link": {
25 "rel": "self",
26 "method": "GET",
27 "href": "https://api.payroc.com/v1/processing-terminals/1234001/secure-tokens/MREF_abc1de23-f4a5-6789-bcd0-12e345678901fa"
28 }
29 },
30 "securityChecks": {
31 "cvvResult": "M",
32 "avsResult": "X"
33 }
34 },
35 "transactionResult": {
36 "type": "sale",
37 "status": "ready",
38 "responseCode": "A",
39 "responseMessage": "APPROVAL",
40 "approvalCode": "OK3",
41 "authorizedAmount": 4999,
42 "currency": "USD"
43 },
44 "operator": "Automatic Payment",
45 "supportedOperations": [
46 "fullyReverse",
47 "setAsPending"
48 ]
49 },
50 {
51 "paymentId": "E29U8OU8Q4",
52 "processingTerminalId": "1234001",
53 "order": {
54 "amount": 4999,
55 "currency": "USD",
56 "orderId": "OrderRef7654",
57 "dateTime": "2024-07-02T15:30:00Z",
58 "description": "Monthly Premium Club subscription"
59 },
60 "card": {
61 "type": "Visa Debit",
62 "entryMethod": "icc",
63 "cardNumber": "453985******7062",
64 "expiryDate": "1225",
65 "cardholderName": "Sarah Hopper",
66 "secureToken": {
67 "secureTokenId": "MREF_abc1de23-f4a5-6789-bcd0-12e345678901fa",
68 "customerName": "Sarah Hopper",
69 "token": "296753123456",
70 "status": "notValidated",
71 "link": {
72 "rel": "self",
73 "method": "GET",
74 "href": "https://api.payroc.com/v1/processing-terminals/1234001/secure-tokens/MREF_abc1de23-f4a5-6789-bcd0-12e345678901fa"
75 }
76 },
77 "securityChecks": {
78 "cvvResult": "M",
79 "avsResult": "X"
80 }
81 },
82 "transactionResult": {
83 "type": "sale",
84 "status": "ready",
85 "responseCode": "A",
86 "responseMessage": "APPROVAL",
87 "approvalCode": "475318",
88 "authorizedAmount": 1000,
89 "currency": "EUR"
90 },
91 "operator": "Automatic Payment",
92 "supportedOperations": [
93 "fullyReverse",
94 "setAsPending"
95 ],
96 "customFields": [
97 {
98 "name": "yourCustomField",
99 "value": "abc123"
100 }
101 ]
102 }
103 ],
104 "count": 2,
105 "hasMore": true,
106 "limit": 2,
107 "links": [
108 {
109 "rel": "next",
110 "method": "get",
111 "href": "https://api.payroc.com/v1/payments?processingTerminalId=1234001&limit=2&after=E29U8OU8Q4"
112 },
113 {
114 "rel": "previous",
115 "method": "get",
116 "href": "https://api.payroc.com/v1/payments?processingTerminalId=1234001&limit=2&before=M2MJOG6O2Y"
117 }
118 ]
119}

Step 2. Refund the payment

To refund a card transfer payment, send a POST request to the Payments endpoint.

Request parameters

To create the body of your request, use the following parameters:

Request

amountlongRequired
Amount of the payment that the merchant wants to refund. The value is in the currency’s lowest denomination, for example, cents.
descriptionstringRequired>=1 character<=100 characters
Reason for the refund.
operatorstringOptional>=0 characters<=50 characters
Operator who refunded the payment.

Example request

POST
/v1/payments/:paymentId/refund
1curl -X POST https://api.payroc.com/v1/payments/ \
2 -H "Idempotency-Key: 8e03978e-40d5-43e8-bc93-6894a57f9324" \
3 -H "Authorization: Bearer <token>" \
4 -H "Content-Type: application/json" \
5 -d '{
6 "amount": 4999,
7 "description": "Customer requested a refund due to a wrong order."
8}'

Response fields

If your request is successful, we refund the card payment and return a response. The response contains the following fields:

Response

paymentIdstringRequired=10 characters
Unique identifier that our gateway assigned to the transaction.
processingTerminalIdstringRequired>=4 characters<=50 characters
Unique identifier of the terminal that initiated the transaction.
orderobjectRequired
Object that contains information about the payment.
cardobjectRequired
Object that contains information about the card.
transactionResultobjectRequired
Object that contains information about the transaction response details.
operatorstringOptional>=0 characters<=50 characters
Operator who initiated the request.
customerobjectOptional
Customer contact and address details.
refundslist of objectsOptional
Array of refundSummary objects. Each object contains information about refunds linked to the transaction.
supportedOperationslist of enumsOptional
Array of operations that you can perform on the transaction. - `capture` - Capture the payment. - `refund` - Refund the payment. - `fullyReverse` - Fully reverse the transaction. - `partiallyReverse` - Partially reverse the payment. - `incrementAuthorization` - Increase the amount of the authorization. - `adjustTip` - Adjust the tip post-payment. - `addSignature` - Add a signature to the payment. - `setAsReady` - Set the transaction’s status to `ready`. - `setAsPending` - Set the transaction’s status to `pending`. - `setAsDeclined` - Set the transaction’s status to `declined`.
customFieldslist of objectsOptional
Array of customField objects.

Example response

Response
1{
2 "paymentId": "M2MJOG6O2Y",
3 "processingTerminalId": "1234001",
4 "order": {
5 "amount": 4999,
6 "currency": "USD",
7 "orderId": "OrderRef6543",
8 "dateTime": "2024-07-02T15:30:00Z",
9 "description": "Large Pepperoni Pizza"
10 },
11 "card": {
12 "type": "MasterCard",
13 "entryMethod": "keyed",
14 "cardNumber": "453985******7062",
15 "expiryDate": "1225",
16 "securityChecks": {
17 "cvvResult": "M",
18 "avsResult": "Y"
19 }
20 },
21 "transactionResult": {
22 "type": "sale",
23 "status": "complete",
24 "responseCode": "A",
25 "responseMessage": "OK13",
26 "approvalCode": "OK3",
27 "authorizedAmount": 4999,
28 "currency": "USD"
29 },
30 "operator": "Jane",
31 "customer": {
32 "firstName": "Sarah",
33 "lastName": "Hopper",
34 "billingAddress": {
35 "address1": "1 Example Ave.",
36 "city": "Chicago",
37 "state": "Illinois",
38 "country": "US",
39 "postalCode": "60056",
40 "address2": "Example Address Line 2",
41 "address3": "Example Address Line 3"
42 },
43 "shippingAddress": {
44 "recipientName": "Sarah Hopper",
45 "address": {
46 "address1": "1 Example Ave.",
47 "city": "Chicago",
48 "state": "Illinois",
49 "country": "US",
50 "postalCode": "60056",
51 "address2": "Example Address Line 2",
52 "address3": "Example Address Line 3"
53 }
54 }
55 },
56 "refunds": [
57 {
58 "refundId": "CD3HN88U9F",
59 "dateTime": "2024-07-02T15:30:00Z",
60 "currency": "USD",
61 "amount": -4999,
62 "status": "ready",
63 "responseCode": "A",
64 "responseMessage": "Transaction refunded",
65 "link": {
66 "rel": "self",
67 "method": "GET",
68 "href": "https://api.payroc.com/v1/refunds/BI77XQFQ05"
69 }
70 }
71 ],
72 "supportedOperations": [
73 "refund"
74 ],
75 "customFields": [
76 {
77 "name": "yourCustomField",
78 "value": "acb123"
79 }
80 ]
81}

Test cases

Before you run test cases, read the Payments page in Test Your Integration.

Refund a card payment

Send a POST request to the following endpoint:

POST https://api.uat.payroc.com/v1/payments/{paymentId}/refund

Note: To settle a payment, the terminal must first close the batch and then our gateway settles the payments within an hour. To adjust when the terminal closes a batch, use the terminal settings in the Merchant Portal.

Example response

1{
2 "paymentId": "C8Y177VHWR",
3 "processingTerminalId": "3204001",
4 "order": {
5 "orderId": "Test_006",
6 "dateTime": "2023-05-24T15:21:01+01:00",
7 "amount": 4000,
8 "currency": "USD",
9 "standingInstructions": {
10 "sequence": "subsequent",
11 "processingModel": "recurring"
12 }
13 },
14 "card": {
15 "type": "Visa Credit",
16 "entryMethod": "keyed",
17 "cardNumber": "444433******1111",
18 "expiryDate": "1226",
19 "secureToken": {
20 "secureTokenId": "MREF_1a93f3a6-9029-419f-9e87-3e2db6f0ae85uA",
21 "customerName": "",
22 "token": "2967538502417872",
23 "status": "cvv_validated",
24 "link": {
25 "rel": "self",
26 "method": "GET",
27 "href": "https://api.uat.payroc.com/v1/processing-terminals/3204001/secure-tokens/MREF_1a93f3a6-9029-419f-9e87-3e2db6f0ae85uA"
28 }
29 },
30 "securityChecks": {
31 "cvvResult": "M",
32 "avsResult": "Y"
33 }
34 },
35 "refunds": [
36 {
37 "refundId": "G6T6S6KF74",
38 "dateTime": "2023-05-25T11:12:55+01:00",
39 "amount": -4000,
40 "currency": "USD",
41 "status": "ready",
42 "link": {
43 "rel": "self",
44 "method": "GET",
45 "href": "https://api.uat.payroc.com/v1/refunds/G6T6S6KF74"
46 }
47 }
48 ],
49 "transactionResult": {
50 "type": "sale",
51 "status": "ready",
52 "approvalCode": "OK14486",
53 "authorizedAmount": 4000,
54 "currency": "USD",
55 "responseCode": "A",
56 "responseMessage": "OK14486",
57 "cardSchemeReferenceId": "JxDfFMHyOE2lyQJ2MnFp"
58 }
59}