# Sessions
Session objects are used to create secure sessions for accepting payments with XanPay. Each session can be used exactly once.
# Create a session
Returns a payment session identifier based on parameters sent. You can use this ID to direct customers to XanPay's payment interface.
If the session cannot be created, then you will receive a HTTP 400 error.
Endpoint POST /sessions
Response Session object
Payload attributes
Parameter | Required | Description |
---|---|---|
amount | Required | Amount to be charged |
currency | Required | Currency in which you set the amount. |
orders | Optional | A list of orders |
methods | Optional | A list of methods |
notifyUrl | Optional | HTTP endpoint that receives notifications with notifyPayload when charges is completed |
notifyPayload | Optional | Custom string to be saved as a part of the charge object |
redirectUrl | Optional | Enables a button that takes the customer back to the specified url |
customer | Optional | Can be used to autofill customer details |
# Example
Request example
curl
-X POST https://api.xanpay.com/sessions/
-u {API_KEY}:{API_SECRET}
-d '{
"amount": "35",
"currency": "SGD",
"redirectUrl": "https://google.com",
"notifyUrl": "https://google.com/api/notify",
"notifyPayload": "eyJvcmRlcklkIjogIjI1MSJ9",
"orders": [{
"id": "58109ds9a01",
"name": "iPhone case",
"quantity": 1,
"amount": 35
}],
"customer": {
"email": "customer@gmail.com",
"phone": {
"code": "+65",
"phone": "12345678901"
}
}
}'
Response example
{
"id": "62b586f2313ba00012c75e7d",
"amount": 35,
"currency": "SGD",
"orders": [
{
"id": "58109ds9a01",
"name": "iPhone case",
"quantity": 1,
"amount": 35
}
],
"notifyUrl": "https://google.com/api/notify",
"notifyPayload": "eyJvcmRlcklkIjogIjI1MSJ9",
"status": "created",
"methods": ["paynow", "duit-now", "fps"],
"redirectUrl": "https://google.com",
"customer": {
"email": "customer@gmail.com",
"phone": {
"phone": "12345678901",
"code": "+65"
}
},
"createdAt": "2022-06-20T09:42:10.906Z",
"updatedAt": "2022-06-20T09:42:10.906Z"
}
# Using a session
To accept a payment using sessions, pass the session as a query parameter to URL checkout.xanpay.com
.
For sandbox charges, send an additional parameter isSandbox=true
.
If the session is expired,
Production URL:
https://checkout.xanpay.com/?sessionId=62b586f2313ba00012c75e7d
Sandbox URL:
https://checkout.xanpay.com/?sessionId=62b586f2313ba00012c75e7d&isSandbox=true
# Get a session
Returns session object
Endpoint GET /sessions/{id}
# Get charge
Returns the unique Charge object for the session, if one exists
Endpoint GET /sessions/{id}/charge
# Example
Request example
curl
https://api.xanpay.com/sessions/62b586f2313ba00012c75e7d/charge
-u {API_KEY}:{API_SECRET}
Response example
{
"id": "62b58a41313ba00012c7740b",
"customer": {
"id": "61dd4a404b432c001196c1bc",
"email": "customer@gmail.com",
"phone": "+6512345678901"
},
"refunds": [],
"orders": [
{
"id": "58109ds9a01",
"name": "iPhone case",
"quantity": 1,
"amount": 35
}
],
"destination": {
"account": "+6585867834",
"nonce": "ztt1",
"qrCode": "00020101021126380009SG.PAYNOW010100211+658586783403010520400005303702540535.005802SG5902NA6009Singapore62080104ztt16304CE6D",
"accountName": "DN",
"bank": ""
},
"merchantAmount": 35,
"merchantCurrency": "SGD",
"method": "paynow",
"customerAmount": 35,
"customerCurrency": "SGD",
"status": "pending",
"notifyUrl": "https://google.com/api/notify",
"notifyPayload": "eyJvcmRlcklkIjogIjI1MSJ9",
"sessionId": "62b586f2313ba00012c75e7d",
"createdAt": "2022-06-24T09:56:17.522Z",
"updatedAt": "2022-06-24T09:56:17.854Z"
}
# Session object
Below you can find description for each session field.
Parameter | Description |
---|---|
id | Session ID |
status | Session status |
amount | Amount to be charged |
currency | Currency in which you set the amount |
orders | A list of orders |
methods | A list of methods |
notifyUrl | HTTP endpoint that receives notifications with notifyPayload when charges is completed |
notifyPayload | Custom string to be saved as a part of the charge object |
redirectUrl | Enables a button that takes the customer back to the specified url |
customer | Can be used to autofill customer details |
# Session status
Status | Description |
---|---|
created | New session object has been created, expire after 7 days if not initiated |
initiated | Session has been used, expire after 1 hour |
charged | Charge has been created |
cancelled | Customer has cancelled the session |
expired | Session has timed out, without creating a charge |
# Methods
Enum of supported payment methods
[
"fps",
"hk-bank-transfer",
"paynow",
"viettel-pay",
"duit-now",
"instapay",
"prompt-pay",
"in-bank-transfer",
"gojek-id",
"id-bank-transfer",
"au-bank-transfer",
"nz-bank-transfer",
"toss",
"xan-wallet",
"USDC",
"USDT",
];