跳到主要内容

同一终端应用程序集成 V1 与 V2 版本的区别

1. 导言

同终端集成有两个版本,V1.1版本是第一个版本,V2.0在V1.1的基础上,统一了同终端集成和跨终端集成的功能。V2.0版本在V1.1的基础上,统一了同终端集成和跨终端集成的参数。

版本 发布时间 描述
V1.12023-06-01Initial release with basic payment function interface
V2.02024-09-20Added Batch Close and Tip Adjustment, and implemented and cross-terminal integration field field unification

2. 详细变化说明

V1.1 参数

Name Type Length Request Response Description
versionStringMMAPI version, fixed value "1.1"
transTypeStringMMThe type code of Sale transaction, Fixed value 01
appIdString18M-The payment app id registered in Codepay Gateway, Please refer to the Payment gateway integration guide
transDataJSONMC
resultString-MRefer to appendix - Transaction result code
resultMsgString-CFailure message

V2.0 参数

Key Parameter type Request Response Description
topicstringMMMessage topic identifier. Please refer to the topic Example: ecrhub.pay.order
versionstringMOThe API version. fixed value:2.0
app_idstringMOThe 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-OThe 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

版本字段不变,V2 版本删除了 transData 字段,增加了一个新的 biz_data 字段,删除了 transType 字段,将 transType 字段放在 biz_data 内,V2 版本增加了一个新的主题字段,并用 response_code 和 response_msg 替换了 V1 版本的 result 和 resultMsg。

3.示例代码比较

 V1.1 Sale Code

```java
Intent intent = new Intent();
intent.setAction("com.codepay.transaction.call");
intent.putExtra("version", "1.0");
intent.putExtra("appId", "{YOUR_APP_ID}");
intent.putExtra("transType", "01"); // Sale transaction
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("businessOrderNo","202202222222");
jsonObject.put("paymentScenario","1"); //Card payment
jsonObject.put("cardType", "1") //Debit
jsonObject.put("amt","2.15");
intent.putExtra("transData", jsonObject.toString());
} catch (JSONException e) {
e.printStackTrace();
}
startActivityForResult(intent, 1);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String result = data.getStringExtra("result");
String resultMsg = data.getStringExtra("resultMsg");
String transData = data.getStringExtra("transData");
if (result.equals("00")){
try {
JSONObject jsonObject = new JSONObject(transData);
String amount = jsonObject.getString("amt");
}catch(JSONException e){
e.printStackTrace();
}
}
}
```
V2.0 Sale Code

```java
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();
}
}
}
```