Alipay, China's leading third-party online payment solutionAlipay, China's leading third-party online payment solution

1. Add Alipay+ SDK to your project

Before you start

Make sure you meet the following system requirements:

  • Android 4.1 (API level 16) or later for H5/PWA Mini Program
  • Android 6.0 (API level 23) or later for DSL Mini Program
  • Android Studio
  • Gradle 4.1 or later

Get started

To get started with IAPMiniProgram SDK, perform the following actions:

Step 1: Add the configuration file

After completed the settings in the Preparation stage,you will receive a file named iapconnect_config_full. Add the iapconnect_config_full file in the asset directory of your Android project.

image.png

Step 2: Add maven repo

Add the maven repo in your root build.gradle file:

copy
repositories {
  maven {
    url 'https://globaltech.alipay.com/api/v1/file/repository/minisdk/'
    credentials {
      username = USERNAME
      password = PASSWORD
    }
  }
}

Replace the values of USER_NAME and PASSWORD with access credentials provided by Ant team. It is recommended to keep the username and password in local.properties file instead of checking them into the version control system.

Step 3: Add dependencies

Add the following dependencies in the app-level build.gradle file:

copy
// in app build.gradle
// if there are some conflicts with existing sdk, please exclude them
dependencies {
    implementation "com.alipay.plus.android:iapminiprogram:${iapminiprogram_version}",
    implementation "com.alipay.plus.android:iapminiprogram-video:${iapminiprogram_version}"
    implementation "com.alipay.plus.android:iapminiprogram-operation:${iapminiprogram_version}"
}

Externalize the version number in the root build.gradle file so you can easily manage upgrades in the future.

copy
ext.versions = {
    iapminiprogram_version = 'IAPMINPROGRAM_VERSION'
}

Replace the value of IAPMINPROGRAM_VERSION with the latest version number that is provided in Android release notes.

Step 4: Initialize the SDK

We recommend you initialize the SDK in the application's onCreate event. Before initialization, implement the WalletServiceManager.getInstance().registerServices and register the four mandatory services as shown below. See Implement additional services via Wallet API for more details.

copy
public class YourApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ...

        if (ProcessUtils.isMainProcess()) {
            // Please implement the walletAPI and register them before calling IAPConnect.init()
            try {
                Class[] services = new Class[]{
                    CodeServiceImpl.class,
                    OAuthServiceImpl.class,
                    PaymentServiceImpl.class,
                    MemberServiceImpl.class,
                    DeeplinkServiceImpl.class
                };
                WalletServiceManager.getInstance().registerServices(services);
            } catch (BaseService.NoServiceMetaInfoException | BaseService.ServiceRegisterException e) {
                // failure
            }

            InitConfig initConfig = new InitConfig();
            IAPConnect.init(this, initConfig, new InitCallback() {
                @Override
                public void onSuccess() {
                    // success
                }

                @Override
                public void onFailure(String errorCode, String errorMessage) {
                    // failure
                }
            });
        }    
    }
}

Step 5: Implement services

Services are offered in the Mini Program Framework to provide seamless integration with the host apps. It allows the mini program to invoke existing functionality from the host app. For instance, when the mini program calls my.scan() JSAPI, you can launch the host app's existing QR code scanner to complete the flow.

The followings are the mandatory services you need to ensure that the host app implements:

  • OAuth service
  • Payment service
  • Code scanning service
  • DeepLink service

Refer to Implement additional services via Wallet API for more details.

Next steps

Implement mandatory services via Wallet API