- Getting Started
- Tutorials
- Reference
- API Reference
- Basic Payment
- Forex
- Authentication
- Card Account
- Apple Pay
- Virtual Account
- Bank Account
- Token Account
- Customer
- Billing Address
- Merchant Billing Address
- Shipping Address
- Merchant Shipping Address
- Corporate
- Recipient
- Merchant
- Marketplace & Cart
- Airline
- Lodging
- Passenger
- Tokenization
- Recurring Migration
- 3D Secure
- Custom Parameters
- Async Payments
- Webhook notifications
- Risk
- Point of Sale
- Response Parameters
- Card On File
- Chargeback
- Result Codes
- Brands Reference
- API Reference
- FAQ
Alipay
This guide explains how to process Alipay payments with our SDK.
Configuration
In order to use Alipay your should register merchant account. You can find detailed instructions in the Alipay guide.
Adding Alipay to your app must be done in one of two ways, depending on whether you are using the Ready-to-Use UI or the SDK & Your Own UI. These two ways are covered in the sections below. Please follow the instructions relevant to the approach you have chosen.
iOS
Ready-to-Use UI
If you are using our ready-to-use checkout screens- Drap and drop
OPPWAMobile-Alipay.xcframework
to the "Frameworks" folder of your project.
Make sure "Copy items if needed" is checked. - Check "Frameworks, Libraries, and Embedded Content" section under the general settings tab of your application's target. Ensure the Embed dropdown has Embed and Sign selected for the framework.
- Configure Alipay in
OPPCheckoutSettings
along with other customizations. - Make sure Alipay is included to the payment brand list:
Make sure you set shopper result URL, it's mandatory to support Alipay:
OPPCheckoutSettings *checkoutSettings = [[OPPCheckoutSettings alloc] init];
checkoutSettings.shopperResultURL = @"com.companyname.appname.payments://result";
let checkoutSettings = OPPCheckoutSettings()
checkoutSettings.shopperResultURL = "com.companyname.appname.payments://result"
checkoutSettings.paymentBrands = @[@"ALIPAY", ... ];
checkoutSettings.paymentBrands = ["ALIPAY", ...]
SDK & Your Own UI
If you are using our SDK & Your Own UI then there is a little more work to be done, but it is still easy to add. There are two options for accepting Alipay payments:
- Accept Alipay payment as usual asynchronous transaction. For this reason, please see this guide.
- Accept Alipay payment using their native SDK. This case will be describe bellow.
Create OPPPaymentParams
with the checkout id and submit a transaction. See below the full Alipay flow.
NSError *error = nil;
OPPPaymentParams *paymentParams = [OPPPaymentParams paymentParamsWithCheckoutID:checkoutID paymentBrand:@"ALIPAY" error:&error];
if (error) {
// See error.code (OPPErrorCode) and error.localizedDescription to identify the reason of failure.
} else {
OPPTransaction *transaction = [OPPTransaction transactionWithPaymentParams:paymentParams];
[self.provider submitTransaction:transaction completionHandler:^(OPPTransaction * _Nonnull transaction, NSError * _Nullable error) {
if (error) {
// Handle the error.
} else {
// Use transaction.brandSpecificInfo[OPPTransactionAlipaySignedOrderInfoKey] for authorization transaction through Alipay SDK
}
}];
}
do {
let paymentParams = try OPPPaymentParams(checkoutID: checkoutID, paymentBrand: "ALIPAY")
let transaction = OPPTransaction(paymentParams: paymentParams)
provider.submitTransaction(transaction) { (transaction, error) in
if (error != nil) {
// Handle the error.
} else {
// Use transaction.brandSpecificInfo[OPPTransactionAlipaySignedOrderInfoKey] for authorization transaction through Alipay SDK
}
} catch let error as NSError {
// See error.code (OPPErrorCode) and error.localizedDescription to identify the reason of failure.
}
Call the native method from Alipay SDK with the value alipaySignedOrderInfo
property from the transaction which your received in the callback:
NSString *alipaySignedOrderInfo = transaction.brandSpecificInfo[OPPTransactionAlipaySignedOrderInfoKey];
[[AlipaySDK defaultService] payOrder:alipaySignedOrderInfo fromScheme:@"com.companyname.appname.payments" callback:^(NSDictionary *resultDic) {
// Sent request to your server to obtain transaction status
}];
let alipaySignedOrderInfo = transaction.brandSpecificInfo?[OPPTransactionAlipaySignedOrderInfoKey]
AlipaySDK.defaultService().payOrder(alipaySignedOrderInfo, fromScheme: "com.companyname.appname.payments") { (result) in
// Sent request to your server to obtain transaction status
}
Alipay may return the result of the transaction directly in the completion block or as Asynchronous notification to App delegate.
Android
Import alipaySdk-15.5.9.aar
into your project (File > New > New Module > Import .JAR/.AAR Package).
Then, add the module dependency to the build.gradle
:
// this name must match the library name defined with an include: in your settings.gradle file
implementation project(":alipaySdk")
Migrating to version 2.34.0: If you have previously used the Alipay module, please remove it and add new module again as described above.
Ready-to-Use UI
If you are using our ready-to-use checkout screens, configure Alipay in CheckoutSettings
along with other customizations.
Simple add the Alipay to the payment brands:
Set<String> paymentBrands = new LinkedHashSet<String>();
paymentBrands.add("ALIPAY");
CheckoutSettings checkoutSettings = new CheckoutSettings(checkoutId, paymentBrands);
val paymentBrands = hashSetOf("ALIPAY")
val checkoutSettings = CheckoutSettings(checkoutId, paymentBrands)
And you are done!
SDK & Your Own UI
If you are using our SDK & Your Own UI then there is a little more work to be done, but it is still easy to add. There are two options for accepting Alipay payments.
Create PaymentParams
with the checkout id and submit a transaction:
PaymentParams paymentParams = new PaymentParams(checkoutId, "ALIPAY");
Transaction transaction = new Transaction(paymentParams);
/* use IProviderBinder to interact with service and submit transaction */
binder.submitTransaction(transaction);
val paymentParams = PaymentParams(checkoutId, "ALIPAY")
val transaction = Transaction(paymentParams)
/* use IProviderBinder to interact with service and submit transaction */
providerBinder.submitTransaction(transaction)
Call the native method from Alipay SDK with the value alipaySignedOrderInfo from the transaction which your received in the callback:
PayTask payTask = new PayTask(YourActivity.this, true);
String alipaySignedInfo = transaction.getBrandSpecificInfo().get(Transaction.ALIPAY_SIGNED_ORDER_INFO_KEY);
String result = payTask.pay(alipaySignedInfo);
/* process the result */
val payTask = PayTask(this@YourActivity, true)
val alipaySignedInfo = transaction.brandSpecificInfo[Transaction.ALIPAY_SIGNED_ORDER_INFO_KEY]
val result = payTask.pay(alipaySignedInfo)
/* process the result */
NOTE: This method must be called from a different thread.