- 18 Sep 2024
- 21 Minutes to read
- Print
- DarkLight
Returning payments with Faster Payments (pacs.004 and pacs.002)
- Updated on 18 Sep 2024
- 21 Minutes to read
- Print
- DarkLight
This tutorial describes how you can return SEPA Credit Transfer (SCT) payments with the Payments Hub API.
For this tutorial, consider a scenario where you are a payment provider, and your merchant has a customer who purchases an item for which they accidently send a duplicate payment. The Payments Hub API can be used to return the money of the duplicate payment from the merchant to the customer’s account.
This tutorial describes, in 2 separate sections, how:
You can initiate a return for an SCT payment using the ISO pacs.004 message.
You can retrieve the return status using the ISO pacs.002 message.
Note
The instructions in this tutorial apply to the sandbox environment.
Prerequisites
Before obtaining the access token, make sure you have a public-private key pair that you can use to sign JWT Bearer tokens.
Click here to email your public key, along with the kid and iss claim values you will use in your JWT Bearer tokens.
Note
The public key must be created with RSA and sent in PEM format, without password encryption, and must have a length of at least 2048 bits. If these criteria are not met, the token will be rejected.
If you don't have a public-private key pair yet, you can use a predefined JWT Bearer token in the sandbox with no need to create or sign your own tokens for authentication:
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6InByb1BheW1lbnRzSHViU2IifQ.eyJzdWIiOiJxTWtaOTBxb0hBTjVJbkE2V2xNYVZBaE41dDhBQWVPeCIsImlzcyI6IlNhbnRhbmRlciIsImlhdCI6MTcxMDg0MjgwNCwibmJmIjoxNzEwODQyODA0LCJleHAiOjE3NDIzNzg4MDQsImp0aSI6ImM3YWY0Yzg0LTRkYzQtNDM2Mi05OTA2LWM5ZTg5N2YyNzUzOCJ9.LOaGmVUnQ6I0HYUQWA1y2vUhREaJrAasAxDlqAnxKbEYGmjP6AKeIViLdkBVVPTUWRETxmnlU6fBQRYU0BN8NEJ9dd_uJ20uiPGWp1ieTFvee27LbqqqS-4AbwD_oJluBUzb77cx4P_1o35gFskcFjbzdl5ert4xJvpbXNOQYa0C7f4YQ6wMLjCGkbdhimwRxeOEGVdYiRoVEizkPpNgUZi_H3o58gATIJ4rSSWqLmKvy9aBlK_YAT947klkJI-ej22KU8qgLCInBbBGdoW9gjg8Zpmizs7Xc7eAvNm7QRiAzd1NT6dgX3hAYDJz2m2dnZYS6zE_UPWOi5cbAyQggw
In the sandbox environment, you can use a predefined test SCA JWT Bearer token:
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6InByb1BheW1lbnRzSHViU2IifQ.eyJoZCI6IlAxNTduSUl5RW5Sa20xek13d1QvUlpxUkVsQUNlMDVFdURwakZuNjZ2akU9Iiwibm9uY2UiOiJhZTE2ODkwODY5ODEyYmFjY2Q3YiIsImFsZyI6IlNIQTI1NiIsImlzcyI6IlNhbnRhbmRlciIsImlhdCI6MTcxMjA1MTU4NSwibmJmIjoxNzEyMDUxNTg1LCJleHAiOjE3NDM1ODc1ODUsImp0aSI6ImQ2MDdhOWI2LTFhNTUtNDg2ZC04NGNjLWU4ZDA0Mzg3NWM1OCJ9.MhoFoBNeKnR6SnxcN3YzPQAUcAfwZav18RH5djnh7rdN7-f-P9kPqAtT8SE4S5LxB3zxI7cIhEA0AAqNQS-QW-vjB_ENaRXNmw-5ZgqmBmZ6NkwQPWeRO87TAo8qIKQ325p4GCrzTAAs2gkdKL-tRCIWk4frloXh1rquxPDQfMY-Vo0eWg3Gt6JozcQ_6DR_c28PZD13gwUyYVywitsWVftkoWoPvqEKYhBSCq6zfYyWFmAnWPXiS1HdTzVmMk2-kAudyZZlZDSbTByn0xxVn1vpTihDw-Cpioaxf5-rtvph_mB9w0mmYHpom_YDQra8D5ryHUMqyqz37LYlzkVF4g
1. Authenticate to get an access token
The Payments Hub API endpoints are protected with OAuth 2.0 JWT Bearer grant. To use the API, you must create a JWT Bearer token and use it to get an access token:
To create a JWT Bearer token, see the Appendix in Authentication guide . For a predefined token that you can use in the sandbox for testing purposes, see the Prerequisites in Authentication guide .
For detailed instructions on how to get the access token, see Authentication guide .
2. Return the payment
This section describes how to return a payment via a pacs.004 HTTP request to the Payments Hub API. It also illustrates a successful response.
Request
Create and send a request using the following operation:
POST https://sandbox.api.pagonxt.com/payments/pacs004/v09
Headers
The request must contain the headers shown in the following table.
Table: Return the payment - Required request headers.
Header name | Description | Required/ Optional | Values |
---|---|---|---|
Authorization | Authorization security header | Required | Bearer |
X-Client-Id | Client ID | Required | |
Content-Type | Format of the request body | Required | application/json |
sca-token | - In the sandbox environment, you can use a predefined test SCA JWT Bearer token (see the Prerequisites section). - In the live environment, you must create the token based on the message body (whose details are described below) and sign it with your private key. For more information on the token details, see the Appendix in Authentication guide . | Required | SCA token |
Accept | Format of the response body | Required | application/json |
Request body
The request must include a JSON payload object in the request body. The JSON payload is a pacs.004 ISO message with the pmtRtr root element, and it contains the request details for returning a payment.
The following table only provides information about some especially important fields. For details on all the required and optional message fields, see Message field definition for pacs.004.
Table: Return the payment - Relevant request body elements.
Message field | Description | Data type | Required/Optional |
---|---|---|---|
grpHdr.msgId | Message ID, which must uniquely identify each request you send. This ID is used internally for idempotency of the API. | String | Required |
grpHdr.creDtTm | Date and time of the payment return request | String | Required |
grpHdr.nbOfTxs | Number of transactions within the message. Value: 1 | Number | Required |
grpHdr.sttlmInf.sttlmMtd | Settlement method. Value: CLRG | String | Required |
txInf.rtrId | Unique payment return ID for the end customer | String | Required |
txInf.rtrdIntrBkSttlmAmt | Data structure containing the payment currency and the amount to be returned. The currency must be EUR and the amount must be a positive value. | Object | Required |
txInf.chrgBr | Charge bearer type. Value: SLEV | String | Required |
txInf.rtrRsnInf.rsn.cd | Code for the payment reversal | String | Required |
txInf.orgnlTxRef | Data structure containing the transaction reference used to identify the original transaction | Object | Required |
Example request body:
{
"pmtRtr": {
"grpHdr": {
"msgId": "MsgId-4268513950",
"creDtTm": "2022-03-09T16:30:22.868+01:00",
"nbOfTxs": "1",
"sttlmInf": {
"sttlmMtd": "CLRG"
}
},
"txInf": [
{
"rtrId": "transactionId-4268513950",
"rtrdIntrBkSttlmAmt": {
"value": 10.04,
"ccy": "EUR"
},
"intrBkSttlmDt": "2020-12-16",
"chrgBr": "SLEV",
"instgAgt": {
"finInstnId": {
"bicfi": "XXXXXXXX"
}
},
"instdAgt": {
"finInstnId": {
"bicfi": "XXXXXXXX"
}
},
"rtrRsnInf": [
{
"rsn": {
"cd": "AC01"
},
"addtlInf": [
"raw-code",
"raw-description"
]
}
],
"orgnlTxRef": {
"pmtTpInf": {
"svcLvl": [
{
"prtry": "SEPA"
}
],
"lclInstrm": {
"prtry": "TRF"
}
},
"dbtr": {
"pty": {
"nm": "Debtor",
"pstlAdr": {
"twnNm": "Madrid",
"ctry": "ES",
"adrLine": [
"Somewhere in Madrid"
]
},
"id": {
"prvtId": {
"othr": [
{
"id": "F99999"
}
]
}
}
}
},
"dbtrAcct": {
"id": {
"othr": {
"id": "12345678"
}
}
},
"dbtrAgt": {
"finInstnId": {
"bicfi": "XXXXXXXX",
"clrSysMmbId": {
"mmbId": "000000"
}
}
},
"cdtrAgt": {
"finInstnId": {
"bicfi": "XXXXXXXX",
"pstlAdr": {
"twnNm": "Lisbon",
"ctry": "PT",
"adrLine": [
"Somewhere in Lisbon"
]
}
}
},
"cdtrAcct": {
"id": {
"iban": "PT91BARC20032634945865"
},
"ccy": "EUR"
}
}
}
]
}
}
Request example
The following example illustrates the request using raw HTTP code:
POST /payments/pacs004/v09 HTTP/1.1
Host: sandbox.api.pagonxt.com
Content-Type: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN
X-Client-Id: YOUR_CLIENT_ID
sca-token: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6InByb1BheW1lbnRzSHViU2IifQ.eyJoZCI6IlAxNTduSUl5RW5Sa20xek13d1QvUlpxUkVsQUNlMDVFdURwakZuNjZ2akU9Iiwibm9uY2UiOiJhZTE2ODkwODY5ODEyYmFjY2Q3YiIsImFsZyI6IlNIQTI1NiIsImlzcyI6IlNhbnRhbmRlciIsImlhdCI6MTcxMjA1MTU4NSwibmJmIjoxNzEyMDUxNTg1LCJleHAiOjE3NDM1ODc1ODUsImp0aSI6ImQ2MDdhOWI2LTFhNTUtNDg2ZC04NGNjLWU4ZDA0Mzg3NWM1OCJ9.MhoFoBNeKnR6SnxcN3YzPQAUcAfwZav18RH5djnh7rdN7-f-P9kPqAtT8SE4S5LxB3zxI7cIhEA0AAqNQS-QW-vjB_ENaRXNmw-5ZgqmBmZ6NkwQPWeRO87TAo8qIKQ325p4GCrzTAAs2gkdKL-tRCIWk4frloXh1rquxPDQfMY-Vo0eWg3Gt6JozcQ_6DR_c28PZD13gwUyYVywitsWVftkoWoPvqEKYhBSCq6zfYyWFmAnWPXiS1HdTzVmMk2-kAudyZZlZDSbTByn0xxVn1vpTihDw-Cpioaxf5-rtvph_mB9w0mmYHpom_YDQra8D5ryHUMqyqz37LYlzkVF4g
Cookie: JSESSIONID=6140E4BBE303D40094D5667AB9558E2E; __VCAP_ID__=9a915939-dd8c-4fca-5914-283d
Content-Length: 3776
{
"pmtRtr": {
"grpHdr": {
"msgId": "MsgId-4268513950",
"creDtTm": "2022-03-09T16:30:22.868+01:00",
"nbOfTxs": "1",
"sttlmInf": {
"sttlmMtd": "CLRG"
}
},
"txInf": [
{
"rtrId": "transactionId-4268513950",
"rtrdIntrBkSttlmAmt": {
"value": 10.04,
"ccy": "EUR"
},
"intrBkSttlmDt": "2020-12-16",
"chrgBr": "SLEV",
"instgAgt": {
"finInstnId": {
"bicfi": "XXXXXXXX"
}
},
"instdAgt": {
"finInstnId": {
"bicfi": "XXXXXXXX"
}
},
"rtrRsnInf": [
{
"rsn": {
"cd": "AC01"
},
"addtlInf": [
"raw-code",
"raw-description"
]
}
],
"orgnlTxRef": {
"pmtTpInf": {
"svcLvl": [
{
"prtry": "SEPA"
}
],
"lclInstrm": {
"prtry": "TRF"
}
},
"dbtr": {
"pty": {
"nm": "Debtor",
"pstlAdr": {
"twnNm": "Madrid",
"ctry": "ES",
"adrLine": [
"Somewhere in Madrid"
]
},
"id": {
"prvtId": {
"othr": [
{
"id": "F99999"
}
]
}
}
}
},
"dbtrAcct": {
"id": {
"othr": {
"id": "12345678"
}
}
},
"dbtrAgt": {
"finInstnId": {
"bicfi": "XXXXXXXX",
"clrSysMmbId": {
"mmbId": "000000"
}
}
},
"cdtrAgt": {
"finInstnId": {
"bicfi": "XXXXXXXX",
"pstlAdr": {
"twnNm": "Lisbon",
"ctry": "PT",
"adrLine": [
"Somewhere in Lisbon"
]
}
}
},
"cdtrAcct": {
"id": {
"iban": "PT91BARC20032634945865"
},
"ccy": "EUR"
}
}
}
]
}
}
Response
If the request is valid, you receive an HTTP 201 Created response, which means that the payment return request was successfully submitted. In addition, the response body returns the data JSON object, which contains payment return details. If the request is submitted again with the same message ID, you receive an HTTP 200 OK response. For further details of HTTP response codes and instructions on how to handle errors, see HTTP codes and request error handling.
The following table shows the response body elements that are relevant for the current use case. For details on all the response body elements, see Message field definition for pacs.004 .
Table: Return the payment - Relevant response body elements.
Element | Description | Data type |
---|---|---|
paymentsHubId | Payments Hub ID, which uniquely identifies your payment return request in Payments Hub. You can use it if you later need to retrieve the payment return details. | String |
paymentId | Message ID you defined in the request as the grpHdr.msgId field value | String |
status | Current status of the payment return. Since Payments Hub stores all requests for a while before performing the transaction settlement, this value is returned as PENDING. | String |
Extract the value of the paymentsHubId key, as you'll need it in the next section.
Example response body:
{
"data": {
"paymentsHubId": "791c3914-a288-3c48-923a-0c4743219e9d",
"paymentId": "MsgId-4268513950",
"status": "PENDING",
"creationDateTime": "2022-06-09T10:41:19.464427"
}
}
3. Retrieve the payment return status
This section describes how to retrieve the payment return status via a pacs.002 HTTP request to the Payments Hub API. To send this request, you need to provide the Payments Hub ID that you received in the response to the pacs.004 HTTP request sent in the previous section, or that was provided in the notification (if you have it enabled for pacs.004 requests). For information, see Notifications . This section also illustrates a successful response.
Note
Notifications are not used in the sandbox environment.
Request
Create and send a request using the following operation:
GET https://sandbox.api.pagonxt.com/payments/pacs002/v10/{paymentsHubId}
Headers
The request must contain the headers shown in the following table.
Table: Retrieve the payment return status - Required request headers.
Header name | Description | Required/Optional | Values |
---|---|---|---|
Authorization | Authorization security header | Required | Bearer <Access token> |
X-Client-Id | Client ID | Required | <Client ID> |
Accept | Format of the response body | Required | application/json |
Parameters
The request must contain the path parameter shown in the following table.
Table: Retrieve the payment return status - Request parameter.
Parameter type| | Parameter name | Description | Data format | Required/Optional |
---|---|---|---|---|
Path | paymentsHubId | Payments Hub ID related to the payment return, received in the response to the pacs.004 request | String | Required |
Request example
The following example illustrates the request using raw HTTP code:
GET /payments/pacs002/v10/YOUR_PAYMENTS_HUB_ID HTTP/1.1
Host: sandbox.api.pagonxt.com
Authorization: Bearer YOUR_ACCESS_TOKEN
X-Client-Id: YOUR_CLIENT_ID
Response
If the request is valid, you receive an HTTP 200 OK response, which means that the payment return status was successfully retrieved. For further details of HTTP response codes and instructions on how to handle errors, see HTTP codes and request error handling .
In addition to the response code, the response body returns the fIToFIPmtStsRpt JSON object, which contains a pacs.002 ISO message.
The following table shows the response body elements that are relevant for the current use case. For details on all the response body elements, see Message field definition for pacs.002 .
Table: Retrieve the payment return status – Relevant response body elements.
Element | Description | Data type |
---|---|---|
txInfAndSts.txSts | Payment return status. The possible values are based on the ISO standard. For example: ACCC (accepted) or RJTC (rejected). For more information on the status and the related codes that provide the reason for the payment acceptance or rejection, see Payment status and codes . | String |
Extract the value of the txInfAndSts.txSts key to see the payment return status.
Example response body:
{
"fitoFIPmtStsRpt": {
"grpHdr": {
"msgId": "991fc8f228e741f4a628ac0904cf5c46",
"creDtTm": "2022-06-09T10:41:19.487Z"
},
"txInfAndSts": [
{
"orgnlGrpInf": {
"orgnlMsgId": "MsgId-4268513950",
"orgnlMsgNmId": "pacs.004.001.09"
},
"orgnlTxId": "transactionId-4268513950",
"txSts": "ACCC",
"stsRsnInf": [
{
"addtlInf": [
null,
null,
"SCT:transactionId-4268513950",
null
]
}
],
"orgnlTxRef": {
"pmtTpInf": {
"svcLvl": [
{
"prtry": "SCT"
}
]
},
"rmtInf": {
"strd": [
{
"addtlRmtInf": [
"transactionId-4268513950"
]
}
]
}
}
}
]
}
}