同一终端应用程序集成 V1 与 V2 版本的区别
1. 导言
同终端集成有两个版本,V1.1版本是第一个版本,V2.0在V1.1的基础上,统一了同终端集成和跨终端集成的功能。V2.0版本在V1.1的基础上,统一了同终端集成和跨终端集成的参数。
版本 | 发布时间 | 描述 |
---|---|---|
V1.1 | 2023-06-01 | Initial release with basic payment function interface |
V2.0 | 2024-09-20 | Added Batch Close and Tip Adjustment, and implemented and cross-terminal integration field field unification |
2. 详细变化说明
V1.1 参数
Name | Type | Length | Request | Response | Description |
---|---|---|---|---|---|
version | String | M | M | API version, fixed value "1.1" | |
transType | String | M | M | The type code of Sale transaction, Fixed value 01 | |
appId | String | 18 | M | - | The payment app id registered in Codepay Gateway, Please refer to the Payment gateway integration guide |
transData | JSON | M | C | ||
result | String | - | M | Refer to appendix - Transaction result code | |
resultMsg | String | - | C | Failure message |
V2.0 参数
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 |
版本字段不变,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();
}
}
}
```