Reverse a card sale or a pre-authorization

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

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 (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

processingTerminalIdstringOptional>=4 characters<=50 characters
Filter by terminal ID.
orderIdstringOptional>=1 character<=24 characters
Filter payments by order ID.
operatorstringOptional>=1 character<=50 characters
Filter payments by operator.
cardholderNamestringOptional>=1 character<=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.
tenderenumOptional
Filter by tender type.
Allowed values:
tipModelist of enumsOptional
Filter payments by tip.
typelist of enumsOptional
Filter payments by transaction type.
statuslist of enumsOptional
Filter payments by the status of the transaction.
dateFromstringOptionalformat: "date-time"
Filter by payments that the processor processed after a specific date. The date format follows the ISO 8601 standard.
dateTostringOptionalformat: "date-time"
Filter by payments that the processer processed before a specific date. The date format follows the ISO 8601 standard.
settlementStateenumOptional
Filter payments by the settlement status of the transaction.
Allowed values:
settlementDatestringOptionalformat: "date"
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
Points to the resource identifier that you want to receive your results before. Typically, this is the first resource on the previous page.
afterstringOptional
Points to the resource identifier that you want to receive your results after. Typically, this is the last resource on the previous page.
limitintegerOptional<=100Defaults to 10
States the total amount of results the response is limited to.

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

operatorstringOptional>=0 characters<=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/ \
2 -H "Idempotency-Key: 8e03978e-40d5-43e8-bc93-6894a57f9324" \
3 -H "Authorization: Bearer <token>" \
4 -H "Content-Type: application/json" \
5 -d '{}'

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.
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": "reversal",
24 "responseCode": "A",
25 "responseMessage": "OK2",
26 "approvalCode": "OK2",
27 "authorizedAmount": 100,
28 "currency": "USD"
29 },
30 "customer": {
31 "firstName": "Sarah",
32 "lastName": "Hopper",
33 "billingAddress": {
34 "address1": "1 Example Ave.",
35 "city": "Chicago",
36 "state": "Illinois",
37 "country": "USA",
38 "postalCode": "60056",
39 "address2": "Example Address Line 2",
40 "address3": "Example Address Line 3"
41 },
42 "shippingAddress": {
43 "recipientName": "Sarah Hopper",
44 "address": {
45 "address1": "1 Example Ave.",
46 "city": "Chicago",
47 "state": "Illinois",
48 "country": "IT",
49 "postalCode": "60056",
50 "address2": "Example Address Line 2",
51 "address3": "Example Address Line 3"
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}