跳到主要内容

同一终端内应用集成(V2)

公共说明

本文根据以下约定每个参数字段的必要性。

  • M:必要参数
  • C:在满足某些条件时,是必要参数
  • O:可选参数
  • -:不存在 常见参数如下:
参数 类型 请求 响应 说明
topicstringMMMessage topic identifier. Please refer to the topic Example: ecrhub.pay.order
request_idstringCCTransaction Request ID, used to receive the corresponding response. The caller needs to remain unique.This parameter must be present when using terminal confirmation mode.
timestampstringOOTimestamp Example: 1698302992263
versionstringOOThe API version. fixed value:1.0
app_idstringMMThe payment app id registered in Codepay Gateway, Please refer to the Payment gateway integration guide
biz_dataJSONObjectOOBusiness Data. each transaction type has own business data
response_codestring-MThe 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_msgString-CFailed transaction error message returned by CodePay Register

每种交易类型都有一个消息主题:

Key Name
ecrhub.pay.order提交交易请求
ecrhub.pay.query查询交易信息
ecrhub.pay.reprint重打印
ecrhub.pay.batch.close批结算
ecrhub.pay.tip.adjustment小费调整

API列表

1. 提交交易请求

消息主题

ecrhub.pay.order

参数列表

参数 Type 请求s 响应 说明
trans_typeStringMMTransaction type. Please refer to Transaction type

Example: 1
merchant_order_noStringMMMerchant 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_noStringCCOriginal merchant order number. If the transaction type is Void, Refund, Completion, it must be required. (trans_type = 2,3,6)

Example: 121775014073233368018
price_currencyStringOOPrice Currency, compliant with ISO-4217 standard, described with a three-character code

Example:USD
order_amountStringMMOrder amount. This field represents the transaction ordered amount, For example, one USD stands for one dollar, not one cent.

Example: 34.50
tip_amountStringOOTip amount. This field represents the transaction tip amount. For example, 1 USD stands for one dollar, not one cent.

Example: 34.50
on_screen_tipbooleanOOWhether 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_amountStringOOCashback amount. Expressed in the quoted currency, for example, One USD stands for one dollar, not one cent

Example: 10.00
pay_method_idStringOOPayment method id. Please Refer to Payment method

If the TransType is 3, this parameter will not required

Example:Visa
pay_scenarioStringOOPayment scene, please refer to PayScenario

Example: SWIPE_CARD
card_network_typeStringOOBank 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
attachStringOOAdditional data.Allows merchants to submit additional data, which will be returned as is.

Example: abc123
descriptionStringOODescription of ordered goods or services.A brief description of the goods or services purchased by the customer.

Example: IPhone White X2
notify_urlStringOOCallback 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
expiresStringOOOrder expires time, after the expires time is not allowed to be paid, unit: seconds

Example: 180
required_terminal_authenticationbooleanOOWhen refund or void a transaction, does the store manager role need to authorize this operation on the terminal? default value: false
on_screen_signaturebooleanOOThis parameter controls the display logic of electronic signatures:
  • true: Display the electronic signature page and print the signature information on the purchase order
  • false: The electronic signature page will not be displayed, but the signature area needs to be printed on the purchase order
But even if this parameter is set, CodePay Register still processes electronic signatures according to the following logic in the following situations:
  • Credit card network, APP does not display signature page, fixed on receipt to print signature column

  • Pin debit transactions do not require a signature, the APP does not display a signature page, and the receipt is not printed either
trans_noString-MTransaction number of Codepay. which uniquely identifies a transaction.

Example: 5021000010210602000003
trans_statusString-MTransaction status, please refer to Transaction status
pay_channel_trans_noString-OPayment 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_bmopcstring-OPayment 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_bpcstring-OPayment 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
cashierstringOOThe cashier's id number or name, the transaction will record this field for easy tip counting

示例代码

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. 查询交易

消息主题

ecrhub.pay.query

参数列表

参数 Type 请求s 响应 说明
merchant_order_noStringMMMerchant 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_typeString-MTransaction type. Please refer to Transaction type

Example: 1
price_currencyString-MPrice Currency, compliant with ISO-4217 standard, described with a three-character code

Example:USD
order_amountString-MOrder amount. This field represents the transaction ordered amount, For example, one USD stands for one dollar, not one cent.

Example: 34.50
tip_amountString-OTip amount. This field represents the transaction tip amount. For example, 1 USD stands for one dollar, not one cent.

Example: 34.50
cashback_amountString-OCashback amount. Expressed in the quoted currency, for example, One USD stands for one dollar, not one cent

Example: 10.00
attachString-OAdditional data.Allows merchants to submit additional data, which will be returned as is.

Example: abc123
trans_noString-MTransaction number of Codepay. which uniquely identifies a transaction.

Example: 5021000010210602000003
trans_statusString-MTransaction status, please refer to Transaction status
pay_scenarioString-OPayment 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_idString-OPayment 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_noString-OPayment 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_bmopcstring-OPayment 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_bpcstring-OPayment 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_timestring-OTransaction 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
cashierstring-OThe cashier's id number or name, the transaction will record this field for easy tip counting

示例代码

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. 重打印

消息主题

ecrhub.pay.reprint

参数列表

参数 Type 请求s 响应 说明
merchant_order_noStringM-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.

示例代码

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. 批结算

消息主题

ecrhub.pay.batch.close

示例代码

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. 小费调整

消息主题

ecrhub.pay.tip.adjustment

参数列表

参数 Type 请求s 响应 说明
merchant_order_noStringM-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_amountStringM-Tip adjustment amount. For example, 1 USD stands for one dollar, not one cent.

Example: 34.50

示例代码

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");
}

集成Demo

example projects