Payments SDK Prerequisites and Environment Setup
This guide outlines the environment setup and configuration steps required before integrating the AppInChina Payments SDK into your Android application.
These steps are mandatory. The AppInChina SDK depends on the correct installation and configuration of the official WeChat Pay and Alipay SDKs.
Related docs
- Android SDK integration: Payments SDK Integration Guide for Android
- Login → Payments integration (identity mapping): Login → Payments integration (customer identity)
- Payments API reference (server-side): Payments API Reference
- Troubleshooting errors: Error Reference
1. Request your credentials
To begin integration, contact our operations team and provide the following details:
- App name
- App package name (e.g.,
com.example.myapp) - App signature (SHA1 and MD5 fingerprints of the release signing certificate)
Once reviewed, we will issue your API credentials:
APP_ID: [provided by AppInChina]
APP_SECRET: [provided by AppInChina]
2. Install the WeChat Pay Android SDK
2.1 Add the WeChat SDK to your build.gradle
dependencies {
compile 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:6.8.0'
}
2.2 Initialize IWXAPI in your app
private IWXAPI api;
private void initWechatPay(String appId) {
api = WXAPIFactory.createWXAPI(getApplicationContext(), appId);
}
You will need your WeChat Pay App ID from Tencent to initialize the SDK. Our operations team will help you register your app in WeChat Pay and get an App ID for you.
2.3 WeChat integration troubleshooting
- Error: WeChat app not responding to payment request
- Verify WeChat app is installed and up-to-date on the test device
- Confirm the
wxapipackage name exactly matches your app's package name - Ensure
WXPayEntryActivityis properly registered inAndroidManifest.xml
- Error: Payment initialization fails
- Double-check your WeChat App ID format
- Verify your app's signing certificate matches the one registered with AppInChina
- Ensure the device has a stable network connection
3. Install the Alipay Android SDK
3.1 Add the Alipay SDK via Maven Central
Add the following dependency to your app-level build.gradle file:
dependencies {
implementation 'com.alipay.sdk:alipaysdk-android:15.8.33'
}
3.2 Alipay integration troubleshooting
- Error: SDK initialization failure
- Verify your App ID and App Secret are correct
- Check your network connection
- Ensure all required permissions are properly declared in
AndroidManifest.xml
- Error: Payment callback not received
- Verify all required permissions are granted at runtime for Android 6.0+
- Check if the device has sufficient storage space
- Ensure Alipay app is installed and updated on the test device
4. Configure project repositories
Both the WeChat and Alipay SDKs are hosted on Maven Central. Be sure to include mavenCentral() in your root build.gradle file to ensure Gradle can resolve both dependencies correctly.
allprojects {
repositories {
google()
mavenCentral()
}
}
5. Declare required permissions
Add the following permissions to your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
If targetSdkVersion >= 23, request the following permissions at runtime:
WRITE_EXTERNAL_STORAGEREAD_PHONE_STATE
6. Add WeChat queries entry (Android 11+)
If targetSdkVersion >= 30, add this section to your AndroidManifest.xml:
<queries>
<package android:name="com.tencent.mm" />
</queries>
This ensures your app is allowed to query for the WeChat app when launching payment intents.
7. Implement the WeChat Pay callback activity
WeChat Pay requires your app to implement a callback receiver for payment results.
7.1 Create a wxapi package inside your app's base package
For example: com.yourcompany.yourapp.wxapi
7.2 Add WXPayEntryActivity class inside wxapi
public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
private IWXAPI api;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
api = com.mandou.acp.sdk.PayToolInfo.getApi();
api.handleIntent(getIntent(), this);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
api.handleIntent(intent, this);
}
@Override
public void onReq(BaseReq req) {
// Handle request from WeChat if needed
}
@Override
public void onResp(BaseResp resp) {
// Handle WeChat payment response
startActivity(new Intent(this, PayResultActivity.class));
finish();
}
}
The package name and class name must match exactly for WeChat to invoke it properly.
8. Notes and important reminders
- These configurations are mandatory for payments to function.
- Failure to set up the WeChat or Alipay SDKs correctly will cause
startPayment()calls to fail. - The AppInChina SDK depends on these lower-level SDKs to open payment apps and receive callbacks.
Next: continue with the Android SDK integration guide.