Integration flow

Prerequisites

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

Interaction mode

AlipayHK in-app payment method can be used to pay the bill by calling the alipay.intl.acquiring.wap.pay API. The following graphic shows a full in-app payment flow:

image

  1. The user checks the payment details and pays by AlipayHK.
    1.1 Transactions are created in the merchant backend and the order information is collected after signature.
    1.1.1 The order information is returned after signature.
  2. The mini program JSAPI my.tradePay is called by using the returned order information.
    2.1 The payment request is sent to AlipayHK backend for processing.
    2.1.1 The payment request is being processed.
    2.1.2 AlipayHK backend sends the synchronous payment result.
    2.1.2.1. JSAPI returns payment result.
  3. AlipayHK backend sends a payment notice via notify_url asynchronously.
    3.1 AlipayHK receives payment response from the merchant endpoint notify_url.
  4. Synchronous payment result is returned to the seller server. The seller server checks the signature and analyzes the payment result.
    4.1 The final payment result is returned.
  5. The payment result is presented to users.

Main steps

  1. Prepare transaction information on the server side (the following sample code is written in JSON).
copy
// Parameter details: See Section 3
// Here is an example. Please replace the following parameters with real transaction parameters in real use.
{
    "head":{
        "version":"2.0.0",
        "reqMsgId":"2b76d599f8072d042b68bc2f43be4211",
        "reqTime":"2018-12-04T22:00:53-08:00",
        "clientId":"4Q5XSH6SSG02T006",
        "reserve":"{}",
        "function":"alipay.intl.acquiring.cashier.wap.pay"
    },
    "body":{
        "merchantId":"2160400000002012",
        "productCode":"AGREEMENT_OR_CASHIER_PAY",
        "merchantTransId":"201904030205425512477",
        "order":{
        "seller":{
            "sellerId":"2160400000002012",
            "sellerName":"TEST",
            "mcc":"1234"
        },
        "orderAmount":{
            "currency":"HKD",
            "value":"1000"
        },
        "orderDetail":"testOrder",
        "orderTitle":"testTitle"
    },
    "notifyUrl":"https://notify.alipay.hk/123",
    "returnUrl":"https://sreturn.alipay.hk/123",
    "extendInfo":"{\"productScene\":\"Prepay\"}"
    }
}
  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 = "{\"head\":{\"version\":\"2.0.0\",\"reqMsgId\":\"2b76d599f8072d042b68bc2f43be3197\",\"reqTime\":\"2018-12-04T22:00:53-08:00\",\"clientId\":\"4Q5XSH6SSG02T006\",\"reserve\":\"{}\",\"function\":\"alipay.intl.acquiring.cashier.wap.pay\"},\"body\":{\"merchantId\":\"2160400000002012\",\"productCode\":\"AGREEMENT_OR_CASHIER_PAY\",\"merchantTransId\":\"201904030205425512477\",\"order\":{\"seller\":{\"sellerId\":\"2160400000002013\",\"sellerName\":\"COD\",\"mcc\":\"1234\"},\"orderAmount\":{\"currency\":\"HKD\",\"value\":\"1000\"},\"orderDetail\":\"testorder\",\"orderTitle\":\"testTitle\"},\"notifyUrl\":\"__[https://q43tb6ekkc.execute-api.ap-northeast-1.amazonaws.com/dev/ipay-notify/in-store/2160400000002013\](https://q43tb6ekkc.execute-api.ap-northeast-1.amazonaws.com/dev/ipay-notify/in-store/2160400000002013/)__",\"returnUrl\":\"__[https://sbs-mobops.sandbox-payment.com/debug/tc/wap_pay_result.html\](https://sbs-mobops.sandbox-payment.com/debug/tc/wap_pay_result.html/)__",\"extendInfo\":\"{\\\"productScene\\\":\\\"Prepay\\\"}\"}}"


// 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 = "{\"request\":{\"head\":{\"version\":\"2.0.0\",\"reqMsgId\":\"2b76d599f8072d042b68bc2f43be3197\",\"reqTime\":\"2018-12-04T22:00:53-08:00\",\"clientId\":\"4Q5XSH6SSG02T006\",\"reserve\":\"{}\",\"function\":\"alipay.intl.acquiring.cashier.wap.pay\"},\"body\":{\"merchantId\":\"2160400000002012\",\"productCode\":\"AGREEMENT_OR_CASHIER_PAY\",\"merchantTransId\":\"201904030205425512477\",\"order\":{\"seller\":{\"sellerId\":\"2160400000002013\",\"sellerName\":\"COD\",\"mcc\":\"1234\"},\"orderAmount\":{\"currency\":\"HKD\",\"value\":\"1000\"},\"orderDetail\":\"testorder\",\"orderTitle\":\"testTitle\"},\"notifyUrl\":\"__[https://q43tb6ekkc.execute-api.ap-northeast-1.amazonaws.com/dev/ipay-notify/in-store/2160400000002013\](https://q43tb6ekkc.execute-api.ap-northeast-1.amazonaws.com/dev/ipay-notify/in-store/2160400000002013/)__",\"returnUrl\":\"__[https://sbs-mobops.sandbox-payment.com/debug/tc/wap_pay_result.html\](https://sbs-mobops.sandbox-payment.com/debug/tc/wap_pay_result.html/)__",\"extendInfo\":\"{\\\"productScene\\\":\\\"Prepay\\\"}\"}},\"signature\":\"aueDw0PaUqVMvbiButPCmWy8VsNJIgNKRV4tDEz3mSgIpa5ODnZKVCd1GGCtu7hNzxnwLOiku+TRJUVM24aHkKWrdyBHECjkUBvrziWiZBESLCyJPwT1YHGnioRUhLvL1MqTTm85urPeqAUUir4UyxyWowHitjkxh3ru6nSLkLU=\"}";
  1. Arouse payment with orderStr in the mini program.
copy
my.tradePay({
    version:'2.0.0',
  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),
    });
  }
});