Alipay+ OfflinePay SDK
Alipay+ OfflinePay SDK is integrated with the Alipay+ MPP Client SDK to facilitate the Transport Code service.
This guide walks you through integrating, initializing, and utilizing the OfflinePay SDK to set up necessary services and generate transport codes in both Android and iOS applications.
For instructions on how to integrate the Alipay+ MPP Client SDK, see Alipay+ MPP Client SDK reference.
Android
The OfflinePay SDK for Android contains the following two sub-SDKs:
- aptrip: travel SDK, used for Shanghai Metro to interact with Bluetooth, trip information upload, and trip addendum.
- offlinepay: code generating SDK, used for generating Transport Codes using seeds or scripts.
Before you begin
Before you get started, ensure that the following requirements are met:
- Install or update Android Studio to a working version.
- Use target API level 15 (ICE_CREAM_SANDWICH_MR1) or later.
- Use Gradle 4.1 or later.
- Set up a physical device or use an emulator to run your app.
Step 1: Add the SDK to your project
Add the following dependencies to your project's build.gradle file:
dependencies {
implementation 'com.iap.ac.android:iapconnect:2.57.0'
implementation 'com.iap.ac.android:iapconnect-resource:2.45.0'
//Add the SDK
implementation 'com.iap.ac.android:iapconnect-offlinepay:1.1.0'
}OR
dependencies {
//Minimalist SDK
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
//Container
implementation 'com.iap.ac.android:iapminiprogram:2.57.0'
//Operatoion
implementation 'com.iap.ac.android:iapminiprogram-operation:2.57.0'
implementation 'com.iap.ac.android:iapconnect-offlinepay:1.1.0'
}Step 2: Initialize the SDK
After initializing the Alipay+ MPP Client SDK, initialize the OfflinePay SDK with the following code:
IAPConnect.init(MyApplication.get(), initConfig, new InitCallback() {
@Override
public onSuccess() {
// Initialize SDK
IAPOfflinePay.initialize(MyApplication.get());
}
@Override
// Handle error logic
public void onFailure(final InitErrorCode errorCode, final String errorMessage) {
}
});Step 3: Generate the Transport Code
Alipay+ Cross-border Transport mini program calls the generateTransitCode JSAPI to generate a Transport Code with the following code:
public class OfflinePayBridgeExtension extends SimpleBridgeExtension {
@ActionFilter
public void generateTransitCode(/* params */) {
// Get SDK instance
OfflinePaySDK offlinePaySDK = OfflinePaySDK.Companion.getInstance(apiContext.getAppContext(), null);
// Set listener for code generation result and callback JSAPI
offlinePaySDK.setListener(new OfflinePayGenerateCodeCallback() { ... });
// Prepare request
OfflinePayGencodeRequest offlinepayGencodeRequest = new OfflinePayGencodeRequest();
offlinePaySDK.startGenerateCode(offlinepayGencodeRequest);
}
}iOS
The OfflinePay SDK for iOS contains the following two sub-SDKs:
- aptrip: travel SDK, used for Shanghai Metro to interact with Bluetooth, trip information upload, and trip addendum.
- offlinepay: code generating SDK, used for generating Transport Codes using seeds or scripts.
Before you begin
Before you get started, ensure that the following requirements are met:
- Install Xcode 12.0 or later
- Ensure that the minimum deployment target is set to iOS 9 or later.
Step 1: Add the SDK to your project
Add the following pods to your project's Podfile:
target 'WALLET_DEMO' do
pod 'IAPConnect', 'x.y.z'
pod 'IAPConnectResourceAppStore', 'x.y.z'
//Add the SDK
pod 'IAPConnectOfflinePay', '1.0.0.250121142805'
endOR
target 'WALLET_DEMO' do
pod 'IAPMiniProgram', 'x.y.z'
pod 'IAPMiniProgramOperation', 'x.y.z'
pod 'IAPConnectOfflinePay', '1.0.0.250121142805'
endStep 2: Initialize the SDK
After initializing the Alipay+ MPP Client SDK, initialize the OfflinePay SDK with the following code:
IAPConnectClient.sharedInstance()?.initWithContext(config, success: {
IAPConnectOfflinePayManager.initService()
}, failure: { (error, errorMessage) in
// Handle error logic
});Step 3: Generate the Transport Code
Alipay+ Cross-border Transport mini program calls the generateTransitCode JSAPI to generate a Transport Code with the following code:
- (void)handle:(NSDictionary *)data context:(GRVInterceptorContext *)context callback:(GRVJSAPIInterceptorCallbackBlock)callback {
IAPGenerateTransitCodeParams *params = [[IAPGenerateTransitCodeParams alloc] init];
// Build params...
[IAPOfflinePayAPI generateTransitCodeWithParams:params completionHandler:^(IAPGenerateTransitCodeData * _Nullable codeData) {
if (callback) {
callback(@{
@"isSuccess": @(codeData.isSuccess),
@"result": codeData.result ?: @"",
@"errorIndicator": codeData.errorIndicator ?: @"",
@"autoRefreshMiliSec": @(codeData.autoRefreshMiliSec),
@"status": codeData.status ?: @"",
@"error": codeData.error ?: @""
});
}
}];
}