Concise documentation
Demo needs to be obtained from Commerce
Step 1: SDK client configuration
The latest version of SDK is 1.5.4.18. It is recommended to replace X.X.X.X in the sample code with the latest version number.
1、View Historical Versions Pay SDK Version
2、V1.5.4.7, V1.5.4.8, V1.5.4.9, V1.5.4.10, V1.5.4.11, V1.5.4.12,V1.5.4.15 are customized versions of internal mini programs, please consult business personnel before accessing
Add the maven configuration to the root build.gradle of the Android Studio project
buildscript {
repositories {
...
maven{ url 'https://mvn.shalltry.com/repository/maven-public'}
}
...
}
allprojects {
repositories {
...
maven{ url 'https://mvn.shalltry.com/repository/maven-public'}
}
}
Configured in the app's build.gradle file
dependencies {
...
api("com.transsion.pay:paysdk:X.X.X.X")
...
}
Dynamic permission application
It is recommended to dynamically apply for the following permissions when the application is opened, which can make the payment process more processful.
android.permission.READ_PHONE_STATE
android.permission.SEND_SMS
The payment SDK integrates the SMS sending function to support SMS payment. This method requires the application to obtain more sensitive permissions. If your business scenario does not require deduction from the user's mobile phone bill balance, you do not need to obtain the android.permission.SEND_SMS permission
During the initialization process, the initialization of a single payment method is supported. Mode-optional PaySDKManager.MODE_BOTH, PaySDKManager.MODE_PAYNICORN, PaySDKManager.MODE_SMS, if your business only needs online payment, you can pass PaySDKManager.MODE_PAYNICORN, which is not required at this time. User's android.permission.READ_PHONE_STATE permission
Step 2: Initialize the application when the program starts
ap_id, cp_id, api_key are obtained from business
code example:
PaySDKManager.getsInstance().initAriesPay(context, ap_id, cp_id,api_key,
new InitResultCallBack() {
@Override
public void onSuccess(List<SupportPayInfoEntity> list, boolean supportOnlinePay, CountryCurrencyData countryCurrencyData) {
//List<SupportPayInfoEntity> list SMS and online subscription product display amount collection (whatever is returned will be displayed, just pay attention to the amount price)
//for (SupportPayInfoEntity supportPayInfoEntity : list) {
//Online subscription amount collection subPriceList
//List subPriceList = supportPayInfoEntity.priceEntities.stream()
// .filter((PriceEntity priceEntity) -> priceEntity.isSupportSub())
// .collect(Collectors.toList());
//SMS payment amount collection smsPriceList
//List smsPriceList = supportPayInfoEntity.priceEntities.stream()
// .filter((PriceEntity priceEntity) -> priceEntity.isSupportNormal())
// .collect(Collectors.toList());
//}
// get the amount
//for (SupportPayInfoEntity supportPayInfoEntity : list) {
// for (PriceEntity priceEntity : supportPayInfoEntity.priceEntities) {
// showLog("Amount: " + priceEntity.price);
// }
//}
//-supportOnlinePay =true means support online payment function
//-countryCurrencyData represents country related information
// Only need to pay attention (parameters used for payment), country code: countryCurrencyData.countryCode, currency: countryCurrencyData.currency
// Minimum online payment amount: countryCurrencyData.minAmount, online payment maximum amount: countryCurrencyData.maxAmount
}
@Override
public void onFail(int code) {
}
});
}
Step 3: Initiate payment
Initiate online payment or SMS payment
code example:
private void startPay(){
//Non-required fields can be empty
StartPayEntity startPayEntity = new StartPayEntity();
startPayEntity.amount = 10;//SMS initialization return amount, any value between the minimum and maximum amount supported by online payment
startPayEntity.countryCode = countryCurrencyData.countryCode;//Initialization returns countryCurrencyData object
startPayEntity.currency = countryCurrencyData.currency;
startPayEntity.orderNum = "orderNum";//Merchant order (maintain by yourself)
//StartPayEntity.PAY_MODE_ONLINE: Online payment, StartPayEntity.PAY_MODE_SMS: SMS payment, StartPayEntity.PAY_MODE_ALL: All payment methods
startPayEntity.payMode = StartPayEntity.PAY_MODE_SMS;
startPayEntity.type = 0;
//AHA quick game add field
//startPayEntity.apiKey = "";
//startPayEntity.cpId = "";
try {
//payOrderNum: payment order number
String payOrderNum=PaySDKManager.getsInstance().startPay(activity, startPayEntity, new StartPayCallBack() {
@Override
public void onOrderCreated(OrderEntity orderEntity) {
//The order is successfully created, and the payment is started. If the result is not received due to crashes and other reasons, you can query the order result according to the order number here.
}
@Override
public void onPaySuccess(OrderEntity orderEntity) {
//payment successful
}
@Override
public void onPaying(OrderEntity orderEntity) {
//The query times out, and then go to the server to confirm
}
@Override
public void onPayFail(int code, OrderEntity orderEntity) {
//payment failed
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
Note: When the payment fails, the result code of the response will be returned to the merchant, and the merchant can prompt the user according to the return code
Initiate subscription payment
code example:
private void startOnLineSubPay(){
//Non-required fields can be empty
StartPayEntity startPayEntity = new StartPayEntity();
startPayEntity.amount = 10;//Returned from initialization
startPayEntity.countryCode = countryCurrencyData.countryCode;//Initialization returns countryCurrencyData object
startPayEntity.currency = countryCurrencyData.currency;
startPayEntity.orderNum = "orderNum";//Merchant order number (maintain by yourself)
startPayEntity.cycle = "";//empty
startPayEntity.email = "";//If there is no value - empty
startPayEntity.phone = "";//If there is no value - empty
startPayEntity.payMethod = "";//If there is no value - empty
startPayEntity.orderDescription = "order description";//Must upload, cannot be empty, merchants define their own content
startPayEntity.netPaySp = "";//empty
try {
String subOrderNum=PaySDKManager.getsInstance().startOnLineSubPay(activity, startPayEntity, new StartPayCallBack() {
@Override
public void onOrderCreated(OrderEntity orderEntity) {
//The order is successfully created, and the payment is started. If the result is not received due to crashes and other reasons, you can query the order result according to the order number here.
}
@Override
public void onPaySuccess(OrderEntity orderEntity) {
//payment successful
}
@Override
public void onPaying(OrderEntity orderEntity) {
//The query times out, and then go to the server to confirm
}
@Override
public void onPayFail(int code, OrderEntity orderEntity) {
//payment failed
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
Note: subOrderNum order number is saved by itself, and the order number is required for order query
Payment result code table
The error codes starting from 1 are all system types, which are the error codes returned when the system fails to send SMS messages.
result | Description |
---|---|
101 | The number of payments exceeds the daily or monthly limit |
102 | Invalid IMSI (invalid SIM card or no SIM card inserted, etc.) |
103 | Invalid ap_id (null) |
104 | Invalid cp_id (null) |
105 | Invalid api_key (null) |
106 | Could not match code (mcc, mnc mismatch) |
107 | Invalid amount (the amount is 0 or the current payment amount cannot match the code) |
108 | The last payment has not been completed |
110 | No permission to read phone information READ_PHONE_STATE |
111 | No permission to send SMS SEND_SMS |
112 | Payment Failed |
113 | AriesPayBroadcastReceiver broadcast not registered in manifest file (obsolete) |
114 | User canceled payment |
115 | SMS sending timeout |
116 | Payment configuration error |
117 | Paying too frequently |
118 | Requires initialization |
124 | No matching payment method |
125 | No suitable amount |
128 | In strict mode, the queried payment is regarded as a payment failure |
129 | No network in payment |
130 | Cancel payment when sending SMS |
888 | No local country information found |
1 | Error sending (such as number not received, etc.) |
2 | Radio has been explicitly turned off (eg airplane mode turned on) |
3 | No pdu provided (SMS system is abnormal) |
4 | Service is currently unavailable (SMS service unavailable) |
5 | The sending queue limit has been reached (for example, the message is too long) |
6 | Result error FDN check failed |
7 | Reject advanced short codes (for example, when the second verification SMS sending is rejected) |
8 | Reject advanced short codes (for example, when the second verification SMS sending is rejected) |
Other | Unknown error, less than 100 is the system sending SMS error |
Order query interface
Online subscription query interface
code example:
PaySDKManager.getsInstance().queryOnlineSubOrderStatus(orderNum, apiKey, cpid, new OrderQuery() {
@Override
public void onSuccess(OrderResultEntity orderQueryEntity){
//Subscribe successfully
}
@Override
public void orderError(OrderResultEntity orderQueryEntity, String code, String errorMessage) {
//caused by network error - subscription failed
}
@Override
public void onPaying(OrderResultEntity orderQueryEntity) {
//Subscribing - unconfirmed result
}
@Override
public void orderFail(OrderResultEntity orderQueryEntity) {
//Subscription failed
}
});
Note: The next subscription payment can be handled in the orderError()/onPaying()/orderFail() callback
Step 4 Integrate Firebase
1. Follow the Firebase official documentation - use the Firebase console to set up the workflow scheme to access Firebase official address
2, google-services.json file to find business acquisition
3. Payment SDK buried point data callback interface
code example:
PaySDKManager.getsInstance().setStatisticsSynchroListener(new StatisticsSynchroListener() {
@Override
public void track(String event, Bundle bundle) {
FirebaseAnalytics.getInstance(activity).logEvent(event, bundle);
if (event.equals(PaySDKStatistics.ARIES_EVENT_INIT_NAME)) {
FirebaseAnalytics.getInstance(context).setUserProperty("mccmnc", PayUtil.getSimOperator(context);
FirebaseAnalytics.getInstance(context).setUserProperty("AP_ID", bundle.getString("ap_id"));
FirebaseAnalytics.getInstance(context).setUserProperty("CP_ID", bundle.getString("cp_id"));
FirebaseAnalytics.getInstance(context).setUserProperty("API_KEY", bundle.getString("appkey"));
}
}
});
Test mode
SMS Payment Test
Mainly for the test design of the SMS payment function part, because there is no operator's SIM card during development, it can be simulated by the following method
SMSTestUtil.setTestMode(true)//Close by default, when set to true, it means the test mode is turned on, and it is a dual-card mode
SMSTestUtil.setTestMCCMNC("62160");// The mccmnc of the first card is set here
SMSTestUtil.setTestMCCMNC2("62120");// here is to set the mccmnc of the second card
//For example, if you want to simulate the operation of Airtel in Nigeria, then set 62120
//Then when simulating other operators, find the mccmnc of the corresponding operator and set it
Online Payment Test Mode
The application defaults to the test mode. When you need to go online, you need to contact the business and switch to the official mode.