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

Integration flow

Prerequisites

You have already signed a contract with AlipayHK and allocated it with a MID and ClientId.

Interaction mode

image

Main steps

  1. Prepare transaction information on the server side (the following sample code is written in Node.js).
copy
// Parameter details: See Section 3
// Here is an example. Please replace the following parameters with real transaction parameters in real use.
var sampleParams = {
 method: 'mobile.securitypay.pay', // Payment API, fixed value 'mobile.securitypay.pay'.
 partner: '2088101568358171', // Note: the contract partner's Alipay ID
 seller_id: '2088101568358171', // Note: the contract seller's Alipay ID
 out_trade_no:'ALIPAYTEST2016081622560194853',  // Note: the unique trade transaction serial number in merchant's system.
 subject: 'Merchandise subject',
 body: 'Merchandise description',
 total_fee: '0.1',  // Payment amount
 notify_url: 'http://www.xxx.com',  // The url to which Alipay HK sends payment result in async mode.
 payment_type: '1',  // Payment type, fixed value '1'.
 _input_charset: 'utf-8',  // Character set of parameter code, fixed value 'utf-8'.
 it_b_pay: '30m',  // Transaction time-out auto close time. Decimal point is not supported for the parameter value. For example, 1.5h can be converted to 90m.
 return_url: 'm.alipay.com',  // The URL specified by merchant. After Alipay processed the request, users will be redirected from current page to the URL merchant specified. The value can be null.
 payment_inst: 'ALIPAYHK',  // Payment method on the merchandise lable. For example, ALIPAYHK. The value can be null.  
 currency: 'HKD',  // Transaction currency type on the merchandise lable. For example, HKD.
 product_code: 'NEW_WAP_OVERSEAS_SELLER',  // Payment product type on the merchandise lable, fixed value 'NEW_WAP_OVERSEAS_SELLER'.
 forex_biz: 'FP',  //Foreign exchange business type, fixed value 'FP'.
 payment_type: '1',  //Payment type, fixed value '1'.
}
  1. Construct the request data on the server side (the following sample code is written in Node.js).
copy
// The construction consists of the following steps. The the final request data is the string generated in the third step.
// Step 1,assemble the raw request parameters into a key=value&key=value pre-sign string.
var originOrderString = "method=\"mobile.securitypay.pay\"&partner=\"2088101568358171\"&seller_id=\"2088101568358171\"&out_trade_no=\"ALIPAYTEST2016081622560194853\"&subject=\"Merchandise subject\"&body=\"Merchandise description\"&total_fee=\"0.1\"&notify_url=\"http://www.xxx.com\"&payment_type=\"1\"&_input_charset=\"utf-8\"&it_b_pay=\"30m\"&return_url=\"m.alipay.com\"&payment_inst=\"ALIPAYHK\"&currency=\"HKD\"&product_code=\"NEW_WAP_OVERSEAS_SELLER\"&forex_biz=\"FP\"&payment_type=\"1\""


// Step 2,Sign the step 1 generated pre-sign string. Note that the signature string should be generated by the server.
var sign = 'aueDw0PaUqVMvbiButPCmWy8VsNJIgNKRV4tDEz3mSgIpa5ODnZKVCd1GGCtu7hNzxnwLOiku+TRJUVM24aHkKWrdyBHECjkUBvrziWiZBESLCyJPwT1YHGnioRUhLvL1MqTTm85urPeqAUUir4UyxyWowHitjkxh3ru6nSLkLU=';

// Step 3, Encode the signature of the request string, encode it by using the function `encodeURIComponent` to get the final request string. The encoding format is based on the charset in the request string. If no charset is passed in, use UTF-8 instead.
var orderStr = "method=\"mobile.securitypay.pay\"&partner=\"2088101568358171\"&seller_id=\"2088101568358171\"&out_trade_no=\"ALIPAYTEST2016081622560194853\"&subject=\"商品名稱\"&body=\"商品描述信息\"&total_fee=\"0.1\"&notify_url=\"http://www.xxx.com\"&payment_type=\"1\"&_input_charset=\"utf-8\"&it_b_pay=\"30m\"&return_url=\"m.alipay.com\"&payment_inst=\"ALIPAYHK\"&currency=\"HKD\"&product_code=\"NEW_WAP_OVERSEAS_SELLER\"&forex_biz=\"FP\"&payment_type=\"1\"&sign=\"aueDw0PaUqVMvbiButPCmWy8VsNJIgNKRV4tDEz3mSgIpa5ODnZKVCd1GGCtu7hNzxnwLOiku+TRJUVM24aHkKWrdyBHECjkUBvrziWiZBESLCyJPwT1YHGnioRUhLvL1MqTTm85urPeqAUUir4UyxyWowHitjkxh3ru6nSLkLU\"=&sign_type=\"MD5\"";
  1. Arouse payment with orderStr in the mini program.
copy
my.tradePay({
  orderStr: 'method=\"mobile.securitypay.pay\"&partner=\"2088101568358171\"&seller_id=\"2088101568358171\"&out_trade_no=\"ALIPAYTEST2016081622560194853\"&subject=\"商品名稱\"&body=\"商品描述信息\"&total_fee=\"0.1\"&notify_url=\"http://www.xxx.com\"&payment_type=\"1\"&_input_charset=\"utf-8\"&it_b_pay=\"30m\"&return_url=\"m.alipay.com\"&payment_inst=\"ALIPAYHK\"&currency=\"HKD\"&product_code=\"NEW_WAP_OVERSEAS_SELLER\"&forex_biz=\"FP\"&payment_type=\"1\"&sign=\"aueDw0PaUqVMvbiButPCmWy8VsNJIgNKRV4tDEz3mSgIpa5ODnZKVCd1GGCtu7hNzxnwLOiku+TRJUVM24aHkKWrdyBHECjkUBvrziWiZBESLCyJPwT1YHGnioRUhLvL1MqTTm85urPeqAUUir4UyxyWowHitjkxh3ru6nSLkLU\"=&sign_type=\"MD5\"', 
  success: (res) => {
    my.alert({
      content: JSON.stringify(res),
    });
  },
  fail: (res) => {
    my.alert({
      content: JSON.stringify(res),
    });
  }
});