Overview #
The Pay by Token API allows merchants to execute a payment using a previously registered customer and card token. This allows a transaction to be processed without sending the customer’s card details again.
The transaction is executed using the customerId and customerTokenId returned by the Execute API when tokenization is enabled.
Environment #
| Environment | Base URL |
|---|---|
| UAT | https://test.amwalpg.com:14443/ |
| Production | https://webhook.amwalpg.com/ |
Endpoint #
POST
Execute/PayByToken
Content Type #
application/json
Request #
Request Headers #
| Header | Required | Value |
|---|---|---|
Content-Type | Yes | application/json |
Request Method #
POST
Sample Request #
{
"amount": 1,
"terminalId": 380024,
"merchantId": 74417,
"customerId": "fe60f286-b67e-47b2-81db-168d27f97288",
"customerTokenId": "73b76aca-3876-4db9-859c-f56872c779c2",
"requestDateTime": "2023-07-24T15:48:26.101Z",
"clientMail": "client-email@test.com",
"currencyCode": "512",
"transactionId": "fa4d322e-55f6-41db-8b9b-7acf8fcc1390",
"secureHashValue": "84EB3BF8F62EF25717D1E9E13C3CFB719A890980BBF2631AFD8965182ADE1754"
}
Token Information #
The customerId and customerTokenId are obtained from the Execute API response when IsTokenized is true.
These values can subsequently be used to execute a payment without requiring the customer to provide their full card details again.
Request Parameters #
| Field | Required | Type | Constraints | Description | Example |
|---|---|---|---|---|---|
customerId | Yes | GUID | Maximum 32 characters | Customer ID associated with a registered payment token. | 5ee9205ab53d45638b07f90507c2866d |
customerTokenId | Yes | GUID | Maximum 32 characters | Customer token ID that identifies the saved card token used for the payment. | ea0a60d2e9be4c35b15a2a7f031a821f |
amount | Yes | Numeric | Length: 1–9 | Purchase transaction amount. | 1 |
terminalId | Yes | Numeric | Maximum 30 characters | Terminal ID initiating the transaction. | 140052 |
merchantId | Yes | Numeric | Maximum 30 characters | Merchant ID initiating the transaction. | 1345 |
merchantReference | No | String | Length: 4 | Merchant reference code. | 1234 |
requestDateTime | Yes | String | Valid UTC date/time | Date and time when the transaction request was created. | 2023-03-08T20:51:38.401Z |
clientMail | No | String | Maximum 256 characters | Customer email address. | demoemail@mail.com |
currencyCode | Yes | Numeric | Length: 2–4 | Currency code used for the transaction. | 512 |
transactionId | Yes | String | Maximum 256 characters | Unique identifier used to identify the transaction. | 5ee9205ab53d45638b07f90507c2866d |
secureHashValue | Yes | String | Maximum 256 characters | Secure hash value used to validate the integrity and authenticity of the request. | 3DB2F9CB975DADB533A2068F5C2911F9CCFF8AA0DFF3F92 |
Response #
Successful Response #
A successful transaction returns success: true and a response code of 00.
Sample Success Response #
{
"success": true,
"responseCode": "00",
"message": "Success",
"data": {
"systemTraceNr": null,
"message": "CAPTURED - ",
"transactionId": "b81e7509-6ca0-4ab2-89c1-f373bbd4d91b",
"isOtpRequired": false,
"hostResponseData": {
"TransactionId": "202431897300287",
"Rrn": "431880000100",
"TrackId": "b81e75096ca04ab289c1f373bbd4d91b",
"PaymentId": null,
"Auth": "490908"
},
"terminalId": 221143,
"transactionTypeId": 2,
"transactionTypeDisplayName": "Purchase",
"customerId": null,
"merchantId": 7921,
"currency": null,
"amount": 1,
"currencyId": 512
},
"errorList": []
}
Success Response Parameters #
| Field | Type | Description | Example |
|---|---|---|---|
success | Boolean | Indicates whether the transaction was successful. | true |
responseCode | String | Response code returned by the API. | 00 |
message | String | General response message. | Success |
data | Object | Contains the transaction details. | Object |
data.systemTraceNr | String | System trace number associated with the transaction. | null |
data.message | String | Message describing the transaction result. | CAPTURED |
data.transactionId | String | Transaction identifier returned by the API. | b81e7509-6ca0-4ab2-89c1-f373bbd4d91b |
data.isOtpRequired | Boolean | Indicates whether OTP verification is required. | false |
data.hostResponseData | Object | Contains transaction information returned by the payment host. | Object |
data.hostResponseData.TransactionId | String | Transaction identifier provided by the payment host. | 202431897300287 |
data.hostResponseData.Rrn | String | Retrieval Reference Number associated with the transaction. | 431880000100 |
data.hostResponseData.TrackId | String | Track identifier associated with the transaction. | b81e75096ca04ab289c1f373bbd4d91b |
data.hostResponseData.PaymentId | String | Payment identifier provided by the payment host. | null |
data.hostResponseData.Auth | String | Authorization code returned by the payment host. | 490908 |
data.terminalId | Numeric | Unique identifier of the terminal used for the transaction. | 380024 |
data.transactionTypeId | Numeric | Transaction type identifier. | 2 |
data.transactionTypeDisplayName | String | Display name of the transaction type based on the Accept-Language header. | Purchase |
data.merchantId | Numeric | Merchant identifier associated with the transaction. | 7921 |
data.currency | String | Currency name used for the transaction. | OMR |
data.amount | Numeric | Amount processed for the transaction. | 1 |
data.currencyId | Numeric | Currency identifier used for the transaction. | 512 |
data.customerId | GUID | Customer ID returned when tokenization is enabled and recurring payments are supported. | 89217ad0-872d-45c3-a6b3-6cba7967d836 |
data.customerTokenId | GUID | Customer token ID associated with the saved card token. | 89217ad0-872d-45c3-a6b3-6cba7967d836 |
errorList | String Array | List of errors. This should be empty for a successful response. | [] |
Tokenized Payment Details #
When the Execute API returns IsTokenized as true, the response can contain:
customerIdcustomerTokenId
These identifiers can be securely stored by the merchant and used for subsequent Pay by Token transactions.
The merchant can execute a subsequent transaction by providing:
customerId
customerTokenId
This eliminates the need to send the customer’s full card information for subsequent tokenized payments.
Important: Token identifiers should be treated as sensitive payment-related data and must be stored and transmitted securely.
Failure Response #
If the transaction cannot be processed, the API returns success: false along with a response code and an errorList describing the failure.
Sample Failure Response #
{
"success": false,
"responseCode": "61",
"message": "APGEX: 62cfc42bff3b",
"data": null,
"errorList": [
"Token Not Found"
]
}
Failure Response Parameters #
| Field | Type | Description | Example |
|---|---|---|---|
success | Boolean | Indicates whether the transaction was successful. | false |
responseCode | String | Response code returned by the API. | 61 |
message | String | General response or error message. | APGEX: 62cfc42bff3b |
data | Object | Transaction data. This may be null when the transaction fails. | null |
errorList | String Array | List containing one or more errors explaining the failure. | ["Token Not Found"] |
Common Failure Example #
Token Not Found #
{
"success": false,
"responseCode": "61",
"message": "APGEX: 62cfc42bff3b",
"data": null,
"errorList": [
"Token Not Found"
]
}
This response indicates that the supplied customerId and/or customerTokenId could not be found or could not be used to process the transaction.
Transaction Flow #
The Pay by Token process follows these general steps:
- The customer completes an initial payment transaction.
- If tokenization is enabled, the Execute API returns
customerIdandcustomerTokenId. - The merchant securely stores the token identifiers.
- For a subsequent payment, the merchant sends the
customerIdandcustomerTokenIdto theExecute/PayByTokenendpoint. - The payment is processed without sending the customer’s full card details.
- The API returns the transaction result and payment host information.
Note: Ensure that the correct merchant credentials, terminal ID, and environment-specific configuration are used when switching between UAT and Production.
