Same-terminal application integration(V2)
Constraints
Different aspects of each field are defined in this document according to the following conventions.
- M: Required parameters
- C: Required parameters when some conditions are met
- O: Optional parameters
- -: Not Present The common parameters is as follows:
Key | Parameter type | Request | Response | Description |
---|---|---|---|---|
topic | string | M | M | Message topic identifier. Please refer to the topic Example: ecrhub.pay.order |
version | string | M | O | The API version. fixed value:2.0 |
app_id | string | M | O | The payment app id registered in Codepay Gateway, Please refer to the Payment gateway integration guide |
biz_data | JSONObject | O | O | Business Data. each transaction type has own business data |
response_code | string | - | O | The order payment status code returned by CodePay Register, 000 means the transaction was successful, other means the transaction failed.Please refer to Response code |
response_msg | String | - | C | Failed transaction error message returned by CodePay Register |
Each transaction type has a message topic:
Key | Name |
---|---|
ecrhub.pay.order | Submit transaction |
ecrhub.pay.query | Query transaction |
ecrhub.pay.reprint | Re-print transaction |
ecrhub.pay.batch.close | Batch close |
ecrhub.pay.tip.adjustment | Tip adjustment |
API List
1. Submit transaction
Message Topic
ecrhub.pay.order
Parameter list
Name | Type | Request | Response | Description |
---|---|---|---|---|
trans_type | String | M | M | Transaction type. Please refer to Transaction type Example: 1 |
merchant_order_no | String | M | M | Merchant order number.This field represents the order number for the refund request when refunded, different from the order number of the original consumer transaction. No more than 32 alphanumeric characters. Example: 121775014073233018 |
orig_merchant_order_no | String | C | C | Original merchant order number. If the transaction type is Void, Refund, Completion, it must be required. (trans_type = 2,3,6) Example: 121775014073233368018 |
price_currency | String | O | O | Price Currency, compliant with ISO-4217 standard, described with a three-character code Example:USD |
order_amount | String | M | M | Order amount. This field represents the transaction ordered amount, For example, one USD stands for one dollar, not one cent. Example: 34.50 |
tip_amount | String | O | O | Tip amount. This field represents the transaction tip amount. For example, 1 USD stands for one dollar, not one cent. Example: 34.50 |
on_screen_tip | boolean | O | O | Whether or not to enter tips on the CodePay Register page, default is false, when "trans_type=1, 3, 4", this parameter can be set Example: true |
cashback_amount | String | O | O | Cashback amount. Expressed in the quoted currency, for example, One USD stands for one dollar, not one cent Example: 10.00 |
pay_method_id | String | O | O | Payment method id. Please Refer to Payment method If the TransType is 3, this parameter will not required Example:Visa |
pay_scenario | String | O | O | Payment scene, please refer to PayScenario Example: SWIPE_CARD |
card_network_type | String | O | O | Bank card network, when this parameter is not required, the bank card transaction selects the network based on the type of card being read,please refer to Card Network Type |
attach | String | O | O | Additional data.Allows merchants to submit additional data, which will be returned as is. Example: abc123 |
description | String | O | O | Description of ordered goods or services.A brief description of the goods or services purchased by the customer. Example: IPhone White X2 |
notify_url | String | O | O | Callback address for payment notification.Receive payment notifications from the CodePay gateway to call back the server address, and only when the transaction goes through the Codepay payment gateway will there be a callback. Example: http://www.abc.com/callback?id=12345 |
expires | String | O | O | Order expires time, after the expires time is not allowed to be paid, unit: seconds Example: 180 |
required_terminal_authentication | boolean | O | O | When refund or void a transaction, does the store manager role need to authorize this operation on the terminal? default value: false |
on_screen_signature | boolean | O | O | This parameter controls the display logic of electronic signatures:
|
trans_no | String | - | M | Transaction number of Codepay. which uniquely identifies a transaction. Example: 5021000010210602000003 |
trans_status | String | - | M | Transaction status, please refer to Transaction status |
pay_channel_trans_no | String | - | O | Payment channel transaction serial number, If trans_status is 2, the returned data will include this parameters, such as Visa, Mastercard and other payment platforms. Example: 000000123 |
discount_bmopc | string | - | O | Payment channel merchant discount amount, If trans_status is 2, the returned data will include this parameters, The merchant gives the customer a preferential amount through the payment channel, and this part of the payment channel will not be settled to the merchant. Example: 3.00 |
discount_bpc | string | - | O | Payment channel discount amount,If trans_status is 2, the returned data will include this parameters. Discount the amount of the payment channel to the customer, and this part of the funds will be settled into the merchant account. Example: 5.00 |
trans_end_time | string | - | O | Transaction completed time. If trans_status is 2, the returned data will include this parameters. Timezone: Local time zone, the time zone set by the payment terminal, Format: YYYY-MM-DD HH:mm:ss Example: 2021-06-03 12:48:51 |
cashier | string | O | O | The cashier's id number or name, the transaction will record this field for easy tip counting |
Sample code
Intent intent = new Intent();
intent.setAction("com.codepay.transaction.call");
intent.putExtra("version", "2.0");
intent.putExtra("topic", "ecrhub.pay.order");
intent.putExtra("app_id", "{YOUR_APP_ID}");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("trans_type", "1"); // Sale transaction
jsonObject.put("merchant_order_no","202202222222");
jsonObject.put("pay_scenario","SWIPE_CARD"); //Card payment
jsonObject.put("card_type", "1") //Debit
jsonObject.put("order_amount","2.15");
intent.putExtra("biz_data", jsonObject.toString());
} catch (JSONException e) {
e.printStackTrace();
}
startActivityForResult(intent, 1);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String responseCode = data.getStringExtra("response_code");
String responseMsg = data.getStringExtra("response_msg");
String bizData = data.getStringExtra("biz_data");
if (responseCode.equals("000")){
try {
JSONObject jsonObject = new JSONObject(bizData);
String amount = jsonObject.getString("order_amount");
}catch(JSONException e){
e.printStackTrace();
}
}
}
2. Query transaction
Message Topic
ecrhub.pay.query
Parameter list
Name | Type | Request | Response | Description |
---|---|---|---|---|
merchant_order_no | String | M | M | Merchant order number.This field represents the order number for the refund request when refunded, different from the order number of the original consumer transaction. No more than 32 alphanumeric characters. Example: 121775014073233018 |
trans_type | String | - | M | Transaction type. Please refer to Transaction type Example: 1 |
price_currency | String | - | M | Price Currency, compliant with ISO-4217 standard, described with a three-character code Example:USD |
order_amount | String | - | M | Order amount. This field represents the transaction ordered amount, For example, one USD stands for one dollar, not one cent. Example: 34.50 |
tip_amount | String | - | O | Tip amount. This field represents the transaction tip amount. For example, 1 USD stands for one dollar, not one cent. Example: 34.50 |
cashback_amount | String | - | O | Cashback amount. Expressed in the quoted currency, for example, One USD stands for one dollar, not one cent Example: 10.00 |
attach | String | - | O | Additional data.Allows merchants to submit additional data, which will be returned as is. Example: abc123 |
trans_no | String | - | M | Transaction number of Codepay. which uniquely identifies a transaction. Example: 5021000010210602000003 |
trans_status | String | - | M | Transaction status, please refer to Transaction status |
pay_scenario | String | - | O | Payment scene, If trans_status is 2, the returned data will include the following parameters, please refer to Please Refer to PayScenario Example: SWIPE_CARD |
pay_method_id | String | - | O | Payment method id. If trans_status is 2, the returned data will include the following parameters. Please Refer to Payment method If the TransType is 3, this parameter will not required Example:Visa |
pay_channel_trans_no | String | - | O | Payment channel transaction serial number, If trans_status is 2, the returned data will include the following parameters, such as Visa, Mastercard and other payment platforms. Example: 000000123 |
discount_bmopc | string | - | O | Payment channel merchant discount amount,If trans_status is 2, the returned data will include the following parameters. The merchant gives the customer a preferential amount through the payment channel, and this part of the payment channel will not be settled to the merchant. Example: 3.00 |
discount_bpc | string | - | O | Payment channel discount amount, If trans_status is 2, the returned data will include the following parameters. Discount the amount of the payment channel to the customer, and this part of the funds will be settled into the merchant account. Example: 5.00 |
trans_end_time | string | - | O | Transaction completed time. If trans_status is 2, the returned data will include the following parameters. Timezone: Local time zone, the time zone set by the payment terminal, Format: YYYY-MM-DD HH:mm:ss Example: 2021-06-03 12:48:51 |
cashier | string | - | O | The cashier's id number or name, the transaction will record this field for easy tip counting |
Sample code
Intent intent = new Intent();
intent.setAction("com.codepay.transaction.call");
intent.putExtra("version", "2.0");
intent.putExtra("topic", "ecrhub.pay.query");
intent.putExtra("app_id", "{YOUR_APP_ID}");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("merchant_order_no","202202222222");
intent.putExtra("biz_data", jsonObject.toString());
} catch (JSONException e) {
e.printStackTrace();
}
startActivityForResult(intent, 1);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String responseCode = data.getStringExtra("response_code");
String responseMsg = data.getStringExtra("response_msg");
String bizData = data.getStringExtra("biz_data");
if (responseCode.equals("000")){
try {
JSONObject jsonObject = new JSONObject(bizData);
String amount = jsonObject.getString("order_amount");
}catch(JSONException e){
e.printStackTrace();
}
}
}
3. Re-print transaction
Message Topic
ecrhub.pay.reprint
Parameter list
Name | Type | Request | Response | Description |
---|---|---|---|---|
merchant_order_no | String | M | - | Merchant order number.This field represents the order number for the refund request when refunded, different from the order number of the original consumer transaction. No more than 32 alphanumeric characters. Example: 121775014073233018 .This parameter must be present when using terminal confirmation mode. |
Sample code
Intent intent = new Intent();
intent.setAction("com.codepay.transaction.call");
intent.putExtra("version", "2.0");
intent.putExtra("topic", "ecrhub.pay.reprint");
intent.putExtra("app_id", "{YOUR_APP_ID}");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("trans_type", "22");
jsonObject.put("merchant_order_no","202202222222");
intent.putExtra("biz_data", jsonObject.toString());
} catch (JSONException e) {
e.printStackTrace();
}
startActivityForResult(intent, 1);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String responseCode = data.getStringExtra("response_code");
String responseMsg = data.getStringExtra("response_msg");
}
4. Batch Close
Message Topic
ecrhub.pay.batch.close
Sample code
Intent intent = new Intent();
intent.setAction("com.codepay.transaction.call");
intent.putExtra("version", "2.0");
intent.putExtra("topic", "ecrhub.pay.batch.close");
intent.putExtra("app_id", "{YOUR_APP_ID}");
startActivityForResult(intent, 1);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String responseCode = data.getStringExtra("response_code");
String responseMsg = data.getStringExtra("response_msg");
}
5. Tip Adjustment
Message Topic
ecrhub.pay.tip.adjustment
Parameter list
Name | Type | Request | Response | Description |
---|---|---|---|---|
merchant_order_no | String | M | - | Merchant order number.This field represents the order number for the refund request when refunded, different from the order number of the original consumer transaction. No more than 32 alphanumeric characters. Example: 121775014073233018 .This parameter must be present when using terminal confirmation mode. |
tip_adjustment_amount | String | M | - | Tip adjustment amount. For example, 1 USD stands for one dollar, not one cent. Example: 34.50 |
Sample code
Intent intent = new Intent();
intent.setAction("com.codepay.transaction.call");
intent.putExtra("version", "2.0");
intent.putExtra("topic", "ecrhub.pay.tip.adjustment");
intent.putExtra("app_id", "{YOUR_APP_ID}");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("merchant_order_no", "202202222222");
jsonObject.put("tip_adjustment_amount", "10.00");
intent.putExtra("biz_data", jsonObject.toString());
} catch (JSONException e) {
e.printStackTrace();
}
startActivityForResult(intent, 1);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String responseCode = data.getStringExtra("response_code");
String responseMsg = data.getStringExtra("response_msg");
}
Integration Demo
Get started with our example projects