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:

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:

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 "entryMethod": "icc",
19 "cardNumber": "453985******7062",
20 "expiryDate": "1225",
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 "type": "sale",
40 "status": "ready",
41 "responseCode": "A",
42 "responseMessage": "APPROVAL",
43 "approvalCode": "OK3",
44 "authorizedAmount": 4999,
45 "currency": "USD"
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 "entryMethod": "icc",
66 "cardNumber": "453985******7062",
67 "expiryDate": "1225",
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 "type": "sale",
87 "status": "ready",
88 "responseCode": "A",
89 "responseMessage": "APPROVAL",
90 "approvalCode": "475318",
91 "authorizedAmount": 1000,
92 "currency": "EUR"
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:

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:

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": "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}