Android Integration

1.Download the SDK package and unzip it,what you get are:

    .
    |____alipaySdk-15.5.9-20181123210601.aar   // Dependency: Alipay SDK
    |____android-demo                          // Demo project
    |____scanforpay-sdk-0.1.0.aar              // scanforpay SDK

2.Put the two aar files into the libs directory in app module,and add code in your project build.gradle file.

    flatDir {
        dirs 'libs'
    }
  1. Add dependencies in build.gradle of the module which need to use this SDK. ScanForPay sdk depends on okhttp3.
    compile(name: 'scanforpay-sdk-1.0', ext: 'aar')
    compile(name: 'alipaySdk-15.5.9-20181123210601', ext: 'aar')
    implementation("com.squareup.okhttp3:okhttp:3.10.0")
  1. Add permissions that Alipay needs to 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" />
    
  2. Call SDK methods to create payment.

     // New a ScanForPayPayTask object
     mTask = new ScanForPayPayTask(MainActivity.this);
     // Set Listener to deal the payment result
     mTask.setListener(new ScanForPayResultListener() {
         @Override
             public void onSuccess(ScanForPayResult result) {
                 Log.d("MainActivity", "ScanForPayResult:" + result.toString());
    
                 int status = result.getStatus(); // Payment status,1 indicates pay success
                 String params = result.getParams(); // order information which should be passed to the server and used to check signature and query the order.
    
                 if(status == 1 && !params.isEmpty()){
                     // TODO pass params to server to check signature and query result.
    
                     // Operations after successed
                     showAlert(MainActivity.this, "Payment success!");
                 }
             }
    
             @Override
             public void onFail(ScanForPayResult result) {
                 // Something to do after failed
                 Log.d("MainActivity", "ScanForPayResult:" + result.toString());
                 if(result.getCode() < 0){
                     // Errorcodes from Alipay are transformed to nagative, and there's no need to deal. Generally speaking, it's cancelled by users.
                 }else{
                     // Fail
                     showAlert(MainActivity.this, "Fail:" + result.getMsg());
                 }
             }
     });
     // Set to sandbox environment
     mTask.setSandBox(true);
    
     // Generate payment request string, it's an example here. 
     // This must implemente on merchant's server
     String request = buildRequest(WALLET_ALIPAY, "Test item", 0.01f);
     // Call pay method
     mTask.pay(request);
    

results matching ""

    No results matching ""