Ecommerce Web API Integration Document v1 - 4
Ecommerce Web API Integration Document v1 - 4
Integration Document
(26 Mar 2024)
Table of Contents
1 Revision History.................................................................. 4
2 Introduction ........................................................................ 5
2.1 Overview ...................................................................................................5
2.1.1 Sequence Diagram .......................................................................................................6
2.1.2 Environment ..................................................................................................................7
3 API Authentication ............................................................. 8
4 Create Order API................................................................. 9
4.1 Request .....................................................................................................9
4.1.1 Parameters....................................................................................................................9
4.1.2 CreateOrderRequest .................................................................................................. 12
4.2 Response................................................................................................. 16
4.3 Sample Code...........................................................................................20
4.4 Notify - Callback.....................................................................................22
4.4.1 Callback mechanism ................................................................................................. 22
4.4.2 Callback validation .................................................................................................... 22
4.4.3 Online tool to verify signature.................................................................................. 23
4.4.4 Sample code for HmacSHA256 ............................................................................... 23
[Link] Java ........................................................................................................................................................ 23
[Link] JavaScript with CryptoJS ..................................................................................................................... 23
4.4.5 Request Body............................................................................................................. 23
5 Get Order API .................................................................... 26
5.1 Request ...................................................................................................26
5.1.1 Parameters................................................................................................................. 26
5.2 Response.................................................................................................27
5.3 Sample Code........................................................................................... 31
6 Create Card Tokenization API.......................................... 32
6.1 Overview .................................................................................................32
6.2 Request ...................................................................................................32
6.2.1 Parameters................................................................................................................. 32
6.2.2 CreateOrderRequest ................................................................................................. 36
6.3 Response................................................................................................. 41
6.4 Sample Code.......................................................................................... 46
1 Revision History
Version Date Summary of changes By
2 Introduction
2.1 Overview
Prior to any integration, merchant should first contact SPECTRA for initialization: account
registration, shop creation, e-commerce API token registration. It is essential for
merchant to keep the API token and user ID secret and safe since they are required for
authentication whenever the API is called.
The organizeId which is required in the Create Order API (see page 9) will be
provided to merchant together with the API token and user ID. (Please refer to
the Create Order API (see page 9) section)
For Create Order, (see page 9) once the customer checkout on the merchant’s website,
the Create Order API (see page 9) should be called. The order information should be
passed to SPECTRA with the API. For example, the total amount of the order, the
preferred currency, the products in the sale, etc. After that, SPECTRA will return a URL
of the Hosted Payment Page (Please refer to the Hosted Payment Page (see page 48) in
appendix) together with other information in JSON format. The merchant should redirect
the customer to the Hosted Payment Page with the URL. The Hosted Payment Page will
collect the customer’s payment information such as the billing address, the card data,
e.t.c. to process the transaction. Once the customer submits the information on the
Hosted Payment Page, a transaction request will be sent to SPECTRA Gateway. Then
the transaction result will be returned and displayed on the Hosted Payment Page.
For Get Order Info, (see page 26) the merchant can call the Get Order Info API (see page
26) to get the information order. For example, the order status, the billing address of the
customer, and the contact email/ phone of the customer (If the customer has submitted
the information).
2.1.2 Environment
The API use different BASE_URL for different environment.
Environment BASE_URL
DEMO [Link]
PROD [Link]
3 API Authentication
The API token and user ID are required for the authentication of every API call. Merchant
should contact Spectra operator to obtain these credentials.
x-soepay-api-token 80ed0e668f65156129261c1bc0f84791fd66c3201eb919bd48c743
0764d4c134
x-soepay-api-userid cb55607718473ae45d701ab7bb06aeacd95e61ba
4.1.1 Parameters
body createOrderRequest
There is 4 types of request body can be
REQUIRED
like:
{
"currency": "HKD",
"products": [
{
"name": "test product",
"price": 10,
"quantity": 1
}
],
"total": 10
}
{
"currency": "HKD",
"products": [
{
"name": "test product",
"price": 10,
"quantity": 1
}
],
"total": 10,
"notify": {
"url": "[Link]
}
}
{
"contactEmail": "spectra@[Link]",
"contactName": "spectra",
"contactTel": "98765432",
"currency": "HKD",
"products": [
{
"name": "test product 2",
"price": 10,
"quantity": 1
}
],
"sendPaymentMail": true,
"shippingInfo": {
"address1": "string",
"address2": "string",
"address3": "string",
"city": "string",
"company": "string",
"country": "HK",
"email": "spectra@[Link]",
"name": "payer",
"postalCode": "string",
"remark": "string",
"state": "string"
},
"total": 10
}
{
"billingInfo": {
"address1": "aaa",
"address2": "aaa",
"address3": "aaa",
"city": "string",
"company": "string",
"country": "HK",
"email": "spectra@[Link]",
"name": "payer",
"postalCode": "string",
"remark": "string",
"state": "string"
},
"contactEmail": "spectra@[Link]",
"contactName": "spectra",
"contactTel": "98765432",
"currency": "HKD",
"products": [
{
"name": "test product 2",
"price": 10,
"quantity": 1
}
],
"sendPaymentMail": true,
"shippingInfo": {
"address1": "bbb",
"address2": "bbb",
"address3": "bbb",
"city": "string",
"company": "string",
"country": "HK",
"email": "spectra@[Link]",
"name": "payer",
"postalCode": "string",
"remark": "string",
"state": "string"
},
"total": 10
}
4.1.2 CreateOrderRequest
Field Type (length) Description Example
products List<Product>
notify Notify
contactEmail String
contactName String
contactTel String
sendPaymentMail Boolean
shippingInfo PaymentInfo
billingInfo PaymentInfo
Product
uuid String
description String
Notify
PaymentInfo
address1 String
address2 String
address3 String
city String
company String
country String HK
email String
name String
postalCode String
remark String
state String
4.2 Response
Code Message Data (example value)
200 OK
{
"checksum": "string",
"data": {
"active": true,
"configData": {
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
},
"currency": "string",
"expiry_duration": "string",
"expiry_time": "2022-11-22T[Link].298Z",
"id": "string",
"identity": {
"active": true,
"id": "string",
"identityType": "DEVICE",
"name": "string",
"status": "ACTIVE"
},
"identity_lite": {
"id": "string",
"name": "string"
},
"instrumentType": "CARD",
"invoice": {
"billingInfo": {
"address1": "string",
"address2": "string",
"address3": "string",
"company": "string",
"country": "AD",
"email": "string",
"id": "string",
"name": "string",
"postalCode": "string",
"state": "string"
},
"contactEmail": "string",
"contactName": "string",
"contactTel": "string",
"id": "string",
"invoiceNumber": "string",
"paid": true,
"paidDate": "2022-11-22T[Link].298Z",
"payerAccount": "string",
"paymentLinkUrl": "string",
"paymentMethod": "ALIPAY",
"shippingInfo": {
"address1": "string",
"address2": "string",
"address3": "string",
"company": "string",
"country": "AD",
"email": "string",
"id": "string",
"name": "string",
"postalCode": "string",
"state": "string"
}
},
"line_item": {
"id": "string",
"products": [
{
"currency": "string",
"description": "string",
"id": "string",
"name": "string",
"price": 0,
"quantity": 0,
"total": 0
}
]
},
"on_behalf_of": "MERCHANT",
"organize": {
"active": true,
"address": "string",
"country": "AD",
"currency": "string",
"email": "string",
"id": "string",
"name": "string",
"noticeConfig": {
"emailConfigList": {
"additionalProp1": {
"receiveCompleteOrder": true,
"receiveExpiredOrder": true,
"receivePendingOrder": true,
"receiveStatusChangeOrder": true
},
"additionalProp2": {
"receiveCompleteOrder": true,
"receiveExpiredOrder": true,
"receivePendingOrder": true,
"receiveStatusChangeOrder": true
},
"additionalProp3": {
"receiveCompleteOrder": true,
"receiveExpiredOrder": true,
"receivePendingOrder": true,
"receiveStatusChangeOrder": true
}
},
"hash": "string"
},
"phone": "string",
"status": "ACTIVE",
"type": "AGENT"
},
"organize_lite": {
"autoSettlement": true,
"id": "string",
"name": "string",
"plan": "ENTERPRISE",
"settlementTime": "HH:mm:ss",
"type": "AGENT"
},
"payment_id": "string",
"remark": "string",
"source": "ECOMMERCE",
"status": "CANCELLED",
"total": 0
},
"message": "string",
"result": "ACCEPTED_ATC_SYNC"
}
201 Created
401 Unauthorized
403 Forbidden
• The hpp url is returned in the response under "data" -> "invoice" ->
"paymentLinkUrl" .
{
"checksum": "string",
"data": {
...
"invoice": {
...
"paymentLinkUrl": "I am hpp url",
...
},
...
},
"message": "string",
"result": "ACCEPTED_ATC_SYNC"
}
Order ID
{
"checksum": "string",
"data": {
...
"expiry_time": "I am the order expiry time"
"id": "I am order ID"
...
},
"message": "string",
"result": "ACCEPTED_ATC_SYNC"
}
Java - OkHttp
JavaScript - XHR
[Link]("readystatechange", function() {
if([Link] === 4) {
[Link]([Link]);
}
});
[Link]("POST", "$BASE_URL/ecommerce/order/public/create");
[Link]("x-soepay-api-token", $your_api_token);
[Link]("x-soepay-api-userid", $your_user_id);
[Link]("Content-Type", "application/json");
[Link](data);
Python - Requests
import requests
import json
url = "$BASE_URL/ecommerce/order/public/create"
payload = [Link]({
"currency": "HKD",
"products": [
{
"name": "test product",
"price": 10,
"quantity": 1
}
],
"total": 10
})
headers = {
'x-soepay-api-token': $your_api_token,
'x-soepay-api-userid': $your_user_id,
'Content-Type': 'application/json'
}
UAT
yEDByWMJ3kgVZtuEcpcgPbswkKEqQBFf242WEj6hexrAghd2ByJXJ9qtuJDq7cFWVQCPMaKEj35VQS8
k8mTy5QRmA5KEuuDa2K3TXfcP79npdcHPrayHSB5bTdaAJhBTvgDNNeH67jRLFYAE8qrNhHe6pkbLvp
Ubhd5NYZeZvwAkjFjhndyJznrAFThNA6cG6Y9AZwKnGrWqhKyPDaSnYprLDHU6W93ECGpcpqUJzsqkT
JBGPpawvu7nNYYYfpvsMJkN7rRpzWTTmmADtEf68UTN33rSpvdRmsCmCe6KS3uQbNVGmBsULGANAFDQ
vhce67srnuSawA9fHv6X5HWbxNx5kRQBbpMDMB2sAZRv2qdUTbEHgv5xgcgHSpTYX8CDbtCCjkTUtFa
zgsMXrUPYhcLw26ATcW34njej9dLHEdurctyB9LwC2CsLFJvsBZpmswuS8nHSDaGJdZVpTD39J4jTqx
hW4ccvwyAwWcN6RYDJfEXtep6p7NqU5fV33q6B
The signature will be included in the request header with key named “sign“.
Since amount handling for json may be different, please make sure there are no trailing
zeros.
Please test signature with different decimal places (such as $10, $10.01, $10.1
etc…)
{
"checksum": "string",
"data": {
"active": true,
"configData": {
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
},
"currency": "string",
"expiry_duration": "string",
"expiry_time": "2022-11-22T[Link].298Z",
"id": "string",
"identity": {
"active": true,
"id": "string",
"identityType": "DEVICE",
"name": "string",
"status": "ACTIVE"
},
"identity_lite": {
"id": "string",
"name": "string"
},
"instrumentType": "CARD",
"invoice": {
"billingInfo": {
"address1": "string",
"address2": "string",
"address3": "string",
"company": "string",
"country": "AD",
"email": "string",
"id": "string",
"name": "string",
"postalCode": "string",
"state": "string"
},
"contactEmail": "string",
"contactName": "string",
"contactTel": "string",
"id": "string",
"invoiceNumber": "string",
"paid": true,
"paidDate": "2022-11-22T[Link].298Z",
"payerAccount": "string",
"paymentLinkUrl": "string",
"paymentMethod": "ALIPAY",
"shippingInfo": {
"address1": "string",
"address2": "string",
"address3": "string",
"company": "string",
"country": "AD",
"email": "string",
"id": "string",
"name": "string",
"postalCode": "string",
"state": "string"
}
},
"line_item": {
"id": "string",
"products": [
{
"currency": "string",
"description": "string",
"id": "string",
"name": "string",
"price": 0,
"quantity": 0,
"total": 0
}
]
},
"on_behalf_of": "MERCHANT",
"organize": {
"active": true,
"address": "string",
"country": "AD",
"currency": "string",
"email": "string",
"id": "string",
"name": "string",
"noticeConfig": {
"emailConfigList": {
"additionalProp1": {
"receiveCompleteOrder": true,
"receiveExpiredOrder": true,
"receivePendingOrder": true,
"receiveStatusChangeOrder": true
},
"additionalProp2": {
"receiveCompleteOrder": true,
"receiveExpiredOrder": true,
"receivePendingOrder": true,
"receiveStatusChangeOrder": true
},
"additionalProp3": {
"receiveCompleteOrder": true,
"receiveExpiredOrder": true,
"receivePendingOrder": true,
"receiveStatusChangeOrder": true
}
},
"hash": "string"
},
"phone": "string",
"status": "ACTIVE",
"type": "AGENT"
},
"organize_lite": {
"autoSettlement": true,
"id": "string",
"name": "string",
"plan": "ENTERPRISE",
"settlementTime": "HH:mm:ss",
"type": "AGENT"
},
"payment_id": "string",
"remark": "string",
"source": "ECOMMERCE",
"status": "CANCELLED",
"total": 0
},
"message": "string",
"result": "ACCEPTED_ATC_SYNC"
}
5.1.1 Parameters
5.2 Response
Code Message Data (example value)
200 OK
{
"checksum": "string",
"data": {
"active": true,
"configData": {
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
},
"currency": "string",
"expiry_duration": "string",
"expiry_time": "2022-11-22T[Link].298Z",
"id": "string",
"identity": {
"active": true,
"id": "string",
"identityType": "DEVICE",
"name": "string",
"status": "ACTIVE"
},
"identity_lite": {
"id": "string",
"name": "string"
},
"instrumentType": "CARD",
"invoice": {
"billingInfo": {
"address1": "string",
"address2": "string",
"address3": "string",
"company": "string",
"country": "AD",
"email": "string",
"id": "string",
"name": "string",
"postalCode": "string",
"state": "string"
},
"contactEmail": "string",
"contactName": "string",
"contactTel": "string",
"id": "string",
"invoiceNumber": "string",
"paid": true,
"paidDate": "2022-11-22T[Link].298Z",
"payerAccount": "string",
"paymentLinkUrl": "string",
"paymentMethod": "ALIPAY",
"shippingInfo": {
"address1": "string",
"address2": "string",
"address3": "string",
"company": "string",
"country": "AD",
"email": "string",
"id": "string",
"name": "string",
"postalCode": "string",
"state": "string"
}
},
"line_item": {
"id": "string",
"products": [
{
"currency": "string",
"description": "string",
"id": "string",
"name": "string",
"price": 0,
"quantity": 0,
"total": 0
}
]
},
"on_behalf_of": "MERCHANT",
"organize": {
"active": true,
"address": "string",
"country": "AD",
"currency": "string",
"email": "string",
"id": "string",
"name": "string",
"noticeConfig": {
"emailConfigList": {
"additionalProp1": {
"receiveCompleteOrder": true,
"receiveExpiredOrder": true,
"receivePendingOrder": true,
"receiveStatusChangeOrder": true
},
"additionalProp2": {
"receiveCompleteOrder": true,
"receiveExpiredOrder": true,
"receivePendingOrder": true,
"receiveStatusChangeOrder": true
},
"additionalProp3": {
"receiveCompleteOrder": true,
"receiveExpiredOrder": true,
"receivePendingOrder": true,
"receiveStatusChangeOrder": true
}
},
"hash": "string"
},
"phone": "string",
"status": "ACTIVE",
"type": "AGENT"
},
"organize_lite": {
"autoSettlement": true,
"id": "string",
"name": "string",
"plan": "ENTERPRISE",
"settlementTime": "HH:mm:ss",
"type": "AGENT"
},
"payment_id": "string",
"remark": "string",
"source": "ECOMMERCE",
"status": "CANCELLED",
"total": 0
},
"message": "string",
"result": "ACCEPTED_ATC_SYNC"
}
401 Unauthorized
403 Forbidden
Order info
• The order status is returned in the response under "data" -> "status" .
• The order total amount is returned in the response under "data" -> "total" .
{
"checksum": "string",
"data": {
...
"status": "I am order status",
"total": "I am order total amount",
...
},
"message": "string",
"result": "ACCEPTED_ATC_SYNC"
}
Java - OkHttp
JavaScript - XHR
[Link]("readystatechange", function() {
if([Link] === 4) {
[Link]([Link]);
}
});
[Link]("GET", "$BASE_URL/ecommerce/order/public/info/$your_order_id");
[Link]("x-soepay-api-token", $your_api_token);
[Link]("x-soepay-api-userid", $your_user_id);
[Link]();
Python - Requests
import requests
url = "$BASE_URL/ecommerce/order/public/info/$your_order_id"
payload={}
headers = {
'x-soepay-api-token': $your_api_token,
'x-soepay-api-userid': $your_user_id
}
6.2 Request
Method POST
6.2.1 Parameters
body createOrderRequest
There is 5 types of request body can be
REQUIRED
like:
{
"currency": "HKD",
"products": [
{
"name": "test product",
"price": 10,
"quantity": 1
}
],
"total": 10
}
{
"currency": "HKD",
"products": [
{
"name": "test product",
"price": 10,
"quantity": 1
}
],
"total": 10,
"notify": {
"url": "[Link]
}
}
{
"currency": "HKD",
"hppConfig": {
"lang": "en",
"quickPay": "true",
"redirect": "[Link]",
"shopper": "customer12345"
},
"products": [
{
"name": "test product",
"price": 10,
"quantity": 1
}
],
"total": 10,
"notify": {
"url": "[Link]
}
}
{
"contactEmail": "spectra@[Link]",
"contactName": "spectra",
"contactTel": "98765432",
"currency": "HKD",
"products": [
{
"name": "test product 2",
"price": 10,
"quantity": 1
}
],
"sendPaymentMail": true,
"shippingInfo": {
"address1": "string",
"address2": "string",
"address3": "string",
"city": "string",
"company": "string",
"country": "HK",
"email": "spectra@[Link]",
"name": "payer",
"postalCode": "string",
"remark": "string",
"state": "string"
},
"total": 10
}
{
"billingInfo": {
"address1": "aaa",
"address2": "aaa",
"address3": "aaa",
"city": "string",
"company": "string",
"country": "HK",
"email": "spectra@[Link]",
"name": "payer",
"postalCode": "string",
"remark": "string",
"state": "string"
},
"contactEmail": "spectra@[Link]",
"contactName": "spectra",
"contactTel": "98765432",
"currency": "HKD",
"products": [
{
"name": "test product 2",
"price": 10,
"quantity": 1
}
],
"sendPaymentMail": true,
"shippingInfo": {
"address1": "bbb",
"address2": "bbb",
"address3": "bbb",
"city": "string",
"company": "string",
"country": "HK",
"email": "spectra@[Link]",
"name": "payer",
"postalCode": "string",
"remark": "string",
"state": "string"
},
"total": 10
}
6.2.2 CreateOrderRequest
Field Type (length) Description Example
products List<Product>
notify Notify
contactEmail String
contactName String
contactTel String
sendPaymentMail Boolean
shippingInfo PaymentInfo
billingInfo PaymentInfo
hppConfig HppConfig
Product
uuid String
description String
Notify
HppConfig
PaymentInfo
address1 String
address2 String
address3 String
city String
company String
country String HK
email String
name String
postalCode String
remark String
state String
6.3 Response
Code Message Data (example value)
200 OK
{
"checksum": "string",
"data": {
"active": true,
"configData": {
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
},
"currency": "string",
"expiry_duration": "string",
"expiry_time": "2022-11-22T[Link].298Z",
"id": "string",
"identity": {
"active": true,
"id": "string",
"identityType": "DEVICE",
"name": "string",
"status": "ACTIVE"
},
"identity_lite": {
"id": "string",
"name": "string"
},
"instrumentType": "CARD",
"invoice": {
"billingInfo": {
"address1": "string",
"address2": "string",
"address3": "string",
"company": "string",
"country": "AD",
"email": "string",
"id": "string",
"name": "string",
"postalCode": "string",
"state": "string"
},
"contactEmail": "string",
"contactName": "string",
"contactTel": "string",
"id": "string",
"invoiceNumber": "string",
"paid": true,
"paidDate": "2022-11-22T[Link].298Z",
"payerAccount": "string",
"paymentLinkUrl": "string",
"paymentMethod": "ALIPAY",
"shippingInfo": {
"address1": "string",
"address2": "string",
"address3": "string",
"company": "string",
"country": "AD",
"email": "string",
"id": "string",
"name": "string",
"postalCode": "string",
"state": "string"
}
},
"line_item": {
"id": "string",
"products": [
{
"currency": "string",
"description": "string",
"id": "string",
"name": "string",
"price": 0,
"quantity": 0,
"total": 0
}
]
},
"on_behalf_of": "MERCHANT",
"organize": {
"active": true,
"address": "string",
"country": "AD",
"currency": "string",
"email": "string",
"id": "string",
"name": "string",
"noticeConfig": {
"emailConfigList": {
"additionalProp1": {
"receiveCompleteOrder": true,
"receiveExpiredOrder": true,
"receivePendingOrder": true,
"receiveStatusChangeOrder": true
},
"additionalProp2": {
"receiveCompleteOrder": true,
"receiveExpiredOrder": true,
"receivePendingOrder": true,
"receiveStatusChangeOrder": true
},
"additionalProp3": {
"receiveCompleteOrder": true,
"receiveExpiredOrder": true,
"receivePendingOrder": true,
"receiveStatusChangeOrder": true
}
},
"hash": "string"
},
"phone": "string",
"status": "ACTIVE",
"type": "AGENT"
},
"organize_lite": {
"autoSettlement": true,
"id": "string",
"name": "string",
"plan": "ENTERPRISE",
"settlementTime": "HH:mm:ss",
"type": "AGENT"
},
"payment_id": "string",
"remark": "string",
"source": "ECOMMERCE",
"status": "CANCELLED",
"total": 0
},
"message": "string",
"result": "ACCEPTED_ATC_SYNC"
}
201 Created
401 Unauthorized
403 Forbidden
• The hpp url is returned in the response under "data" -> "invoice" ->
"paymentLinkUrl" .
{
"checksum": "string",
"data": {
...
"invoice": {
...
"paymentLinkUrl": "I am hpp url",
...
},
...
},
"message": "string",
"result": "ACCEPTED_ATC_SYNC"
}
Card Token
• The Card Token is returned in the Notify Callback under "remark" item.
• The response is in the format “tokenMsg: THE_CARD_TOKEN”
• If the tokenization fails, the tokenMsg content is the failure reason.
(e.g. tokenMsg: Token is failed to create.)
{
"createTime": "2024-03-26T[Link]+0000",
...
"remark": "tokenMsg: THE_CARD_TOKEN",
"hppConfig": {
...
}
...
"source": "ECOMMERCE"
}
Order ID
{
"checksum": "string",
"data": {
...
"expiry_time": "I am the order expiry time"
"id": "I am order ID"
...
},
"message": "string",
"result": "ACCEPTED_ATC_SYNC"
}
Java - OkHttp
JavaScript - XHR
[Link]("readystatechange", function() {
if([Link] === 4) {
[Link]([Link]);
}
});
[Link]("POST", "$BASE_URL/ecommerce/order/public/create");
[Link]("x-soepay-api-token", $your_api_token);
[Link]("x-soepay-api-userid", $your_user_id);
[Link]("Content-Type", "application/json");
[Link](data);
Python - Requests
import requests
import json
url = "$BASE_URL/ecommerce/order/public/create"
payload = [Link]({
"currency": "HKD",
"products": [
{
"name": "test product",
"price": 10,
"quantity": 1
}
],
"total": 10
})
headers = {
'x-soepay-api-token': $your_api_token,
'x-soepay-api-userid': $your_user_id,
'Content-Type': 'application/json'
}
7 Appendix
7.1 Hosted Payment Page
Collect Payment Info
Transaction Result