The following Python code executes the POST request described earlier and, with the obtained session_token, redirects to the URL that starts the customer’s session.

import requests
import webbrowser

'''
Simple request to the API,
which redirects to the payment page.
'''

#Global variables provided by ETpay
API_URL = r'valid_url'
PTM_URL = r'valid_url'
INIT_API = r'/session/initialize'
MERCHANT_CODE = "valid_code"
MERCHANT_API_TOKEN = "valid_api_key"

request_data = {
    "merchant_code": MERCHANT_CODE,
    "merchant_api_token": MERCHANT_API_TOKEN,
    "merchant_order_id": "order-1992", #merchant's own purchase order id
    "order_amount": 1,
    "user_bank_code": "cl_tapp_pay"
}

#Get session token
resp = [requests.post](<http://requests.post>)(API_URL+INIT_API, json=request_data)
token = resp.json()['token']

#Launch customer session
[webbrowser.open](<http://webbrowser.open>)(PTM_URL+'/session/'+token)

#Note: this example does not store the signature_token value

Back to TNB integration with REST API