Run a referenced refund for a card payment

An AI skill is available for this guide, get it on the Skills Marketplace (GitHub).

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

Authenticate your requests before making API calls. If your request fails, 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/M2MJOG6O2Y \
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:

Response

paymentIdstringRequired=10 characters
Unique identifier that our gateway assigned to the transaction.
processingTerminalIdstringRequired4-50 characters
Unique identifier of the terminal that initiated the transaction.
orderobjectRequired
Object that contains information about the payment.
cardobjectRequired
Object that contains the details of the payment card.
transactionResultobjectRequired
Object that contains information about the transaction response details.
operatorstringOptional0-50 characters
Operator who initiated the request.
customerobjectOptional
Object that contains the customer's contact details and address information.
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`.
customFieldslist of objectsOptional
Array of customField objects.

Example response

Response
1{
2 "paymentId": "M2MJOG6O2Y",
3 "processingTerminalId": "1234001",
4 "order": {
5 "orderId": "OrderRef6543",
6 "amount": 4999,
7 "currency": "USD",
8 "dateTime": "2024-07-02T15:30:00Z",
9 "description": "Large Pepperoni Pizza"
10 },
11 "card": {
12 "type": "MasterCard",
13 "cardNumber": "453985******7062",
14 "expiryDate": "1230",
15 "entryMethod": "keyed",
16 "securityChecks": {
17 "cvvResult": "M",
18 "avsResult": "Y"
19 }
20 },
21 "transactionResult": {
22 "status": "ready",
23 "responseCode": "A",
24 "type": "sale",
25 "approvalCode": "OK3",
26 "authorizedAmount": 4999,
27 "currency": "USD",
28 "responseMessage": "OK3"
29 },
30 "operator": "Jane",
31 "customer": {
32 "firstName": "Sarah",
33 "lastName": "Hopper",
34 "billingAddress": {
35 "address1": "1 Example Ave.",
36 "address2": "Example Address Line 2",
37 "address3": "Example Address Line 3",
38 "city": "Chicago",
39 "state": "Illinois",
40 "country": "US",
41 "postalCode": "60056"
42 },
43 "shippingAddress": {
44 "recipientName": "Sarah Hopper",
45 "address": {
46 "address1": "1 Example Ave.",
47 "address2": "Example Address Line 2",
48 "address3": "Example Address Line 3",
49 "city": "Chicago",
50 "state": "Illinois",
51 "country": "US",
52 "postalCode": "60056"
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 after=8516 \
4 -d before=2571 \
5 --data-urlencode cardholderName=Sarah%20Hazel%20Hopper \
6 --data-urlencode dateFrom=2024-07-01T15:30:00Z \
7 --data-urlencode dateTo=2024-07-03T15:30:00Z \
8 -d first6=453985 \
9 -d last4=7062 \
10 -d limit=25 \
11 -d operator=Jane \
12 -d orderId=OrderRef6543 \
13 -d paymentLinkId=JZURRJBUPS \
14 -d processingTerminalId=1234001 \
15 -d settlementDate=2024-07-02 \
16 -d settlementState=settled \
17 -d status=accepted \
18 -d status=ready \
19 -d status=complete \
20 -d tender=ebt \
21 -d tipMode=noTip \
22 -d tipMode=prompted \
23 -d type=sale \
24 -d type=preAuthorization

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

Example response

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

Example request

POST
/v1/payments/:paymentId/refund
1curl -X POST https://api.payroc.com/v1/payments/M2MJOG6O2Y/refund \
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": "Refund for order OrderRef6543"
8}'

Response fields

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

Response

Example response

Response
1{
2 "paymentId": "M2MJOG6O2Y",
3 "processingTerminalId": "1234001",
4 "order": {
5 "orderId": "OrderRef6543",
6 "amount": 4999,
7 "currency": "USD",
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": "1230",
16 "securityChecks": {
17 "cvvResult": "M",
18 "avsResult": "Y"
19 }
20 },
21 "transactionResult": {
22 "status": "complete",
23 "responseCode": "A",
24 "type": "sale",
25 "approvalCode": "OK3",
26 "authorizedAmount": 4999,
27 "currency": "USD",
28 "responseMessage": "OK13"
29 },
30 "operator": "Jane",
31 "customer": {
32 "firstName": "Sarah",
33 "lastName": "Hopper",
34 "billingAddress": {
35 "address1": "1 Example Ave.",
36 "address2": "Example Address Line 2",
37 "address3": "Example Address Line 3",
38 "city": "Chicago",
39 "state": "Illinois",
40 "country": "US",
41 "postalCode": "60056"
42 },
43 "shippingAddress": {
44 "recipientName": "Sarah Hopper",
45 "address": {
46 "address1": "1 Example Ave.",
47 "address2": "Example Address Line 2",
48 "address3": "Example Address Line 3",
49 "city": "Chicago",
50 "state": "Illinois",
51 "country": "US",
52 "postalCode": "60056"
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}