Token Exchange

The Token Exchange API allows you to obtain a token from a third-party payment processor by providing a PayEngine Token.

Exchange tokens

Request

POST https://<PayEngine-host>/api/token-exchange

Body Parameters

Name
Type
Description

gateway_id

UUID

PayEngine gateway ID if required. Not required if gateway type is provided.

payengine_token *

string

Card token generated by PayEngine.

merchant_id

UUID

PayEngine merchant ID if required.

third_party_name (deprecated)

string

Deprecated. Use gateway property instead.

gateway

string

3rd party gateway type. Can be used along with merchant_id, if you don't know the gateway_id.

Example:

nmi | sierra | viaconex | stripe | elavon | payrix | etc. List Available Gateways

third_party_required_data

object

Required data (if any) like authentication details for the 3rd party processor.

third_party_additional_data

object

Any optional values to be sent to the third-party processor for token creation. Ensure that you adhere to the schema defined by the third-party processor and maintain precise naming conventions. For example, one of the optional field in the 3rd party processor is firstName, then it can be specified as third_party_additional_data.firstName in this API request.

metadata

object

Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format and it will be returned in the response

Response

Field Name
Type
Description

data.id

string

Unique identified for the card object.

data.third_party_name (deprecated)

string

Deprecated. Use gateway instead.

data.gateway

string

Name of the 3rd party processor, provided in the request. Example:

nmi | sierra | viaconex | stripe | elavon | payrix | etc. List Available Gateways

data.payengine_token

string

Card token generated by PayEngine provided in the request.

data.third_party_token

string

Card token generated by the 3rd party processor for the information provided in the PayEngine token.

data.third_party_additional_data

object

Return the third_party_additional_data from the request.

data.third_party_response

object

Contains the exact response from the third party processor.

metadata

object

Return the metadata object provided in the request.

error

boolean

true | false. True when there is an error

errors

object

Return the error response from the third party processor.

Sample Request and Response

curl --location 'https://console.payengine.co/api/token-exchange' \
--header 'Authorization: Basic YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
        "third_party_name": "payrix",
        "payengine_token": "card_test_D01CXZR5g7rLQNCXjwewiH",
        "third_party_required_data": { // Example - Payrix API key
                "apikey": "YOUR_3RD_PARTY_API_KEY"
        },
        "third_party_additional_data": {
                "firstName": "test"
         },
            "metadata": {
                "external_id": "ABC123"
         },
}'

Third Party Requirements

For token exchange with a specific third-party, if you have already configured a corresponding gateway for a merchant (either in our partner portal or with our Gateway Management API), then you can provide the PayEngine gateway ID or merchant ID in the token exchange request in order to map the entities in the third-party to the merchant.

Payrix

Payload with specific gateway ID

--header 'Authorization: Basic YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "third_party_name": "payrix",
  "payengine_token": "card_sandbox_D01CXZR5g7rLQNCXjwewiH",
  "gateway_id": "0c49b17e-9a88-411a-9eda-7e54879055af"
}'

Payload with merchant ID

If merchant ID is provided, the system will choose the gateway based on the default enabled gateway for the merchant.

--header 'Authorization: Basic YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "third_party_name": "payrix",
  "payengine_token": "card_sandbox_D01CXZR5g7rLQNCXjwewiH",
  "merchant_id": "70c799bd-db73-41c3-96af-62b367359b7e"
}'

Braintree

Payload with specific gateway ID

--header 'Authorization: Basic YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "third_party_name": "braintree",
  "payengine_token": "card_sandbox_D01CXZR5g7rLQNCXjwewiH",
  "gateway_id": "0c49b17e-9a88-411a-9eda-7e54879055af"
}'

Payload with merchant ID

If merchant ID is provided, the system will choose the gateway based on the default enabled gateway for the merchant.

--header 'Authorization: Basic YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "third_party_name": "braintree",
  "payengine_token": "card_sandbox_D01CXZR5g7rLQNCXjwewiH",
  "merchant_id": "70c799bd-db73-41c3-96af-62b367359b7e"
}'

NMI

Payload with specific gateway ID

--header 'Authorization: Basic YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "payengine_token": "card_sandbox_D01CXZR5g7rLQNCXjwewiH",
  "gateway_id": "0c49b17e-9a88-411a-9eda-7e54879055af"
}'

Payload with merchant ID

If merchant ID is provided, the system will choose the gateway based on the default enabled gateway for the merchant.

--header 'Authorization: Basic YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "gateway": "nmi",
  "payengine_token": "card_sandbox_D01CXZR5g7rLQNCXjwewiH",
  "merchant_id": "70c799bd-db73-41c3-96af-62b367359b7e"

Payload for passing gateway credentials

Sample payload for passing gateway credentials directly without requiring merchant gateway configuration.

curl --location 'http://<PayEngine_Host>/api/token-exchange' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic PAYENGINE_SECRET_KEY' \
--data '{
    "gateway": "nmi",
    "merchantId": "PAYENGINE_MERCHANT_ID",
    "payengineToken": "PAYENGINE_CARD_TOKEN",
    "thirdPartyRequiredData": {
      "username": "SECURITY_KEY",
      "password": "PASSWORD"
    }
}'

Last updated