Implementation with Android App SDK

Import the SDK aar into your Android project

In Android Studio, choose File→Project Structure→Dependencies • In “Modules”panel, choose “+”

• Choose “import .JAR/.AAR Package

• Browse to path of the file “sdk-alipay_release.aar”, select it by click “OK”, then“finish”

• The package will be imported to the project as dependency of your app in your Android project

Implement the SDK in your Android project

• In you payment activity, import com.ottpay.sdk.*

• implement the payment SDK as following the code sample


/**
call alipay sdk pay. 调用 SDK 支付
*/
public void pay(View v) {
 String server_url = //OTT Pay inApp API URL
 String merchant_id= //OTT PAY merchant id
 String shop_id= //OTT PAY store id,optional for future usage
 String operator_id= //OTT Pay operator Id
 String currency= //currency “CAD” or ”USD”
 String amount XXXXXXXXXXXXXXXXXX//pay amount in cents
 String call_back_url=XXXXXXXXXXXXXXXXXX//call back URL
 String biz_type = “ALIPAYONLINE” //if currency “USD”,using
“APUSDONLINE”
 order_id = XXXXXXXXXXXXXXXXXX // your own user id
 ConsumeStarter starter = new ConsumeStarter();
 
 starter.setOnCompleteListener(new OnCompleteListener() {
  @Override
  public void onComplete(String rspString) {
    Toast.makeText(MainActivity.this, rspString,
    Toast.LENGTH_SHORT).show();
  }
  });
  starter.consumeImp(MainActivity.this, server_url, merchant_id,
        shop_id, operator_id, currency, amount, order_id, call_back_url, biz_type);
}

☑️ Replace the server_url, merchant_id, operator_id with the values from OTT PAY. Create an instance of ConsumeStarter, set the OnCompleteListener, and then invoke the consumeImp method to activate the payment page in your mobile’s Alipay app.

👉 Here is the sdk for android app for download

Last updated