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

SDK Overview

The client-side SDK can facilitate your integration with Alipay.

API name: AlipaySDK

Description: AlipaySDK provides payment function.

Alipay API provides sellers with order payment function. Methods provided by API are detailed in table 1 below:

Method nameMethod description
+(Alipay *)defaultService;Obtain payment service examples.
-(BOOL)isLogined;Check whether or not the seller is logged in locally.
-(void)payOrder:(NSString *)orderStr fromScheme:(NSString *)schemeStr callback:(CompletionBlock)completionBlock;Pay and get result via callback.

Express order payment iOS

Method name: Pay method

Method prototype: (void)payOrder:(NSString *)orderStr fromScheme:(NSString *)schemeStr callback:(CompletionBlock)completionBlock;

Method function: Pay method provides sellers with express order payment function.

Parameter NameParameter Description
NSString* schemeURL protocol registered by seller program is for the use of seller callback program after payment has been completed.
(CompletionBlock)completionBlockExpress pay SDK callback function returns with “no need to log in” and payment result. When the Alipay client side is not installed locally, or when the Alipay client side is not successfully called to make payment (via H5 cashier), it will return to payment result via completionBlock. Please refer to "synchronous response parameter" for more details on the relevant payment results.
NSString* orderStrApp payment request parameters contain seller’s order information, key=“value”form, and uses & to connect.

Payment parameters examples are shown below, see "Request Parameters Description" for parameters description:

partner="2088101568358171"&seller_id="xxx@alipay.com"&out_trade_no="0819145412-6177"&subject="test"&body="testtest"&total_fee="0.01"&currency="USD"&forex_biz="FP"&notify_url="http://notify.msp.hk/notify.htm"&service="mobile.securitypay.pay"&payment_type="1"&_input_charset="utf-8"&it_b_pay="30m"&sign="lBBK%2F0w5LOajrMrji7DUgEqNjIhQbidR13GovA5r3TgIbNqv231yC1NksLdw%2Ba3JnfHXoXuet6XNNHtn7VE%2BeCoRO1O%2BR1KugLrQEZMtG5jmJIe2pbjm%2F3kb%2FuGkpG%2BwYQYI51%2BhA3YBbvZHVQBYveBqK%2Bh8mUyb7GM1HxWs9k4%3D"&sign_type="RSA"&secondary_merchant_id="834945"&secondary_merchant_industry="3435"&secondary_merchant_name="holiday"

Processing Client Side Returned URL

Method name: processing client method

Method prototype: -(void)processOrderWithPaymentResult:(NSURL*)resultUrl standbyCallback:(CompletionBlock)completionBlock;

Method function: Client side processing method processes the Alipay client side returned url when the device has installed Alipay app.

Note:

This method must be implemented, otherwise when Alipay app is installed, the payment result cannot be synchronously returned.

Parameter NameParameter Description
NSURL *resultUrlurl returned by Alipay client
CompletionBlock completionBlockWhen Alipay client is installed locally and Alipay client is successfully called to make payment, it will return payment result via completionBlock

Note:

Please call this method - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation in APPDelegate. In iOS9.0 and above versions (including iOS9.0), please call this method in - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options . See Demo for details.

Callback API

After the payment is completed, it will return the payment result synchronously via callbackBlock.

Result returned needs to use value of the resultStatus and result fields to determine the payment result. When verifications of resultStatus=9000 and success=“true”, as well as sign=“xxx” are passed, payment is confirmed to be successful, otherwise, it may be regarded as failure. For circumstances of low security level, payment result can be determined by checking resultStatus and success=“true” only. An example of a successful order payment is shown below:

{ memo = ""; result = "partner=\"2088101568358171\"&seller_id=\"xxx@alipay.com\"&out_trade_no=\"0819145412-6177\"&subject=\"test\"&body=\"testtest\"&total_fee=\"0.01\"&currency=\"USD\"&forex_biz=\"FP\"&notify_url=\"http://notify.msp.hk/notify.htm\"&service=\"mobile.securitypay.pay\"&payment_type=\"1\"&_input_charset=\"utf-8\"&it_b_pay=\"30m\"&success=\"true\"&sign_type=\"RSA\"&sign=\"hkFZr+zE9499nuqDNLZEF7W75RFFPsly876QuRSeN8WMaUgcdR00IKy5ZyBJ4eldhoJ/2zghqrD4E2G2mNjs3aE+HCLiBXrPDNdLKCZgSOIqmv46TfPTEqopYfhs+o5fZzXxt34fwdrzN4mX6S13cr3UwmEV4L3Ffir/02RBVtU=\""; resultStatus = "9000"; }

Note:

The extraction of payment result must be obtained via CompletionBlock, and it prohibits developers from analysing payment results returned URL without permission. Key of the obtained value corresponds to resultStatus, memo and result (developers can analyse the value in the result at their own discretion);

In order to ensure the functioning of the existing seller’s SDK, the initial letter of return parameter ResultStatus is capitalized. For new SDKs, the conversion from ResultStatus to resultStatus has been implemented by unified tool classes, sellers can obtain resultStatus from CompletionBlock.