Reverse a card sale or a pre-authorization

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

If a customer requests a refund and the payment is still in an open batch, the merchant can use their POS to look up the card payment and cancel the transaction. To find the paymentId of the card payment that the merchant wants to reverse, they can retrieve a list of all the card payments that meet the search criteria that the merchant provides. They can then find the transaction that they want in the list of returned results.

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

Integration steps

Step 1. (Optional) List card payments.
Step 2. Reverse a card payment.

Before you begin

Authenticate your requests before making API calls. If your request fails, see Errors.

Step 1 (Optional) List payments

To retrieve a list of card payments, send a GET request to our Payments endpoint.

Use our filters to narrow down the search results.

Request parameters

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

Query parameters

processingTerminalIdstringOptional4-50 characters
Filter by terminal ID.
orderIdstringOptional1-24 characters
Filter payments by order ID.
operatorstringOptional1-50 characters
Filter payments by operator.
cardholderNamestringOptional1-50 characters
Filter payments by the cardholder’s name.
first6stringOptionalformat: "[0-9]{6}"
Filter payments by the first six digits of the card number that the customer used in the transaction.
last4stringOptionalformat: "[0-9]{4}"
Filter payments by the last four digits of the card number that the customer used in the transaction.
tenderanyOptional
Filter by tender type.
tipModelist of anyOptional
Filter payments by tip.
typelist of anyOptional
Filter payments by transaction type.
statuslist of anyOptional
Filter payments by the status of the transaction.
dateFromdatetimeOptional
Filter by payments that the processor processed after a specific date. The date format follows the ISO 8601 standard.
dateTodatetimeOptional
Filter by payments that the processer processed before a specific date. The date format follows the ISO 8601 standard.
settlementStateanyOptional
Filter payments by the settlement status of the transaction.
settlementDatedateOptional
Filter by payments that the processor settled on a specific date in the format **YYYY-MM-DD**.
paymentLinkIdstringOptional=10 characters
Unique identifier that our gateway assigned to the payment link.
beforestringOptional
Return the previous page of results before the value that you specify. You can’t send the before parameter in the same request as the after parameter.
afterstringOptional
Return the next page of results after the value that you specify. You can’t send the after parameter in the same request as the before parameter.
limitintegerOptional<=100Defaults to 10
Limit the maximum number of results that we return for each page.

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 the card payment information 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. Reverse a payment

To reverse a card payment, send a POST request to our Reverse endpoint.

If the merchant wants to reverse only part of the transaction, send the amount that they want to reverse in the amount parameter.

Request parameters

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

Request

operatorstringOptional0-50 characters
Operator who reversed the payment.
amountlongOptional
Amount of the payment that the merchant wants to reverse. The value is in the currency’s lowest denomination, for example, cents. **Note:** If the merchant doesn’t send an amount, we reverse the total amount of the transaction.

Example request

POST
/v1/payments/:paymentId/reverse
1curl -X POST https://api.payroc.com/v1/payments/M2MJOG6O2Y/reverse \
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}'

Response fields

If your request is successful, we reverse 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.
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 "entryMethod": "keyed",
14 "cardNumber": "453985******7062",
15 "expiryDate": "1230",
16 "securityChecks": {
17 "cvvResult": "M",
18 "avsResult": "Y"
19 }
20 },
21 "transactionResult": {
22 "status": "reversal",
23 "responseCode": "A",
24 "type": "sale",
25 "approvalCode": "OK2",
26 "authorizedAmount": 100,
27 "currency": "USD",
28 "responseMessage": "OK2"
29 },
30 "customer": {
31 "firstName": "Sarah",
32 "lastName": "Hopper",
33 "billingAddress": {
34 "address1": "1 Example Ave.",
35 "address2": "Example Address Line 2",
36 "address3": "Example Address Line 3",
37 "city": "Chicago",
38 "state": "Illinois",
39 "country": "US",
40 "postalCode": "60056"
41 },
42 "shippingAddress": {
43 "recipientName": "Sarah Hopper",
44 "address": {
45 "address1": "1 Example Ave.",
46 "address2": "Example Address Line 2",
47 "address3": "Example Address Line 3",
48 "city": "Chicago",
49 "state": "Illinois",
50 "country": "IT",
51 "postalCode": "60056"
52 }
53 }
54 },
55 "supportedOperations": [
56 "capture",
57 "fullyReverse",
58 "partiallyReverse",
59 "incrementAuthorization",
60 "adjustTip",
61 "setAsPending"
62 ],
63 "customFields": [
64 {
65 "name": "yourCustomField",
66 "value": "abc123"
67 }
68 ]
69}

Test cases

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

Reverse a card payment

Send a POST request to the following endpoint:

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

Note: The previous payment must be in the open batch and not settled.

Example response

1{
2 "paymentId": "LRJ1QWEFRN",
3 "processingTerminalId": "3204001",
4 "operator": "notRequired",
5 "order": {
6 "orderId": "Test_007",
7 "dateTime": "2023-05-25T10:39:10+01:00",
8 "amount": 4000,
9 "currency": "USD",
10 "standingInstructions": {
11 "sequence": "subsequent",
12 "processingModel": "recurring"
13 }
14 },
15 "card": {
16 "type": "Visa Credit",
17 "entryMethod": "keyed",
18 "cardNumber": "444433******1111",
19 "expiryDate": "1226",
20 "secureToken": {
21 "secureTokenId": "MREF_1a93f3a6-9029-419f-9e87-3e2db6f0ae85uA",
22 "customerName": "",
23 "token": "2967538502417872",
24 "status": "cvv_validated",
25 "link": {
26 "rel": "self",
27 "method": "GET",
28 "href": "https://api.uat.payroc.com/v1/processing-terminals/3204001/secure-tokens/MREF_1a93f3a6-9029-419f-9e87-3e2db6f0ae85uA"
29 }
30 },
31 "securityChecks": {
32 "cvvResult": "M",
33 "avsResult": "Y"
34 }
35 },
36 "transactionResult": {
37 "type": "sale",
38 "status": "reversal",
39 "approvalCode": "OK14866",
40 "authorizedAmount": 4000,
41 "currency": "USD",
42 "responseCode": "A",
43 "responseMessage": "OK14866",
44 "cardSchemeReferenceId": "zz67WbxsEwMkvbSNcxz9"
45 }
46}