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

Mock Service

What is a mock service

The mock service provides simulations of different payment results to get you familiarized with the possible payment scenarios beforehand. With the simulated scenarios provided in a sandbox environment, you can test failed payment processes with different types of responses and learn to handle exception scenarios. The mock service aims to optimize your exception and error handling abilities and therefore, improve your Alipay integration quality with lower integration cost and better user experience.

Previously, many exception scenarios are difficult or even impossible to be simulated. With the mock service, you can run test cases for all the scenarios and see whether the response is as designed. Besides the default mock rules, you can also customize mock rules for exception scenarios based on your business requirements. By now, the mock service supports the process of payment, cancel, refund, and query.

How to use a mock service

Before using a mock service, you need to have an Alipay merchant account. See Prerequisites.

The following video explains how to use Mock services:

1、Log in your sandbox and go to the mock service part. By now, the mock service supports the following 4 APIs:

  • alipay.acquire.oversears.spot.pay
  • alipay.acquire.cancel
  • alipay.acquire.overseas.spot.refund
  • alipay.acquire.overseas.query

Mock Service

2、Configure mock rules by specifying mock API requests and corresponding responses.

Two types of mock rules exist for each API: default rules and custom rules.

  • Default rules apply for all the sandbox test accounts. You don't need to make any configuration to make the default rules work.
  • Custom rules are rules where you can specify conditions and expected responses based on your business requirements.

Mock Service

3、Send an API request that matches the specified mock rules. You will receive a corresponding mock response and then process it. For example, you can send an alipay.acquire.overseas.spot.pay request with the following mock rule. See the below sample code and a corresponding mock response for details. The default mock rule:

Mock Service

Samples

Sample request

copy
http://mapi.alipaydev.com/gateway.do?biz_product=OVERSEAS_MBARCODE_PAY&identity_code_type=barcode&_input_charset=utf-8&sign=bKTQrOiOZ2tyyDQjn%2BSa9cE9BytEJhunOWCCUJdSJVedsnfMX4gh3HYLNpvue1kJ6PG9e23kc4%2BvVro5g1DPRRuBPt6jdDEfx1aIUYWKoPE%2FgAeBsgQTAjLq1paMVdyLumFB9JseE%2FwZBjrCoca9Q3CaGpZkr%2B8jt%2FDYsIgYMOA%3D&trans_name=xxxzgl&trans_amount=9901&notify_url=http%253A%252F%252Falipay.com&extend_info=%7B%22secondary_merchant_name%22%3A%22MNAME006%22%2C%22secondary_merchant_id%22%3A%22MID0071525932232000%22%2C%22secondary_merchant_industry%22%3A%225300%22%2C%22store_id%22%3A%22SID0071525932232000%22%2C%22store_name%22%3A%22store1525932232000%22%7D&partner_trans_id=620923196607215160_1588066245285&trans_currency=USD&partner=2088621893731583&service=alipay.acquire.overseas.spot.pay&currency=USD&buyer_identity_code=286865667671986813&sign_type=RSA

Sample response

copy
<?xml version="1.0" encoding="utf-8"?>
<alipay>
    <is_success>T</is_success>
    <request>
        <param name="biz_product">OVERSEAS_MBARCODE_PAY</param>
        <param name="identity_code_type">barcode</param>
        <param name="_input_charset">utf-8</param>
        <param name="sign">bKTQrOiOZ2tyyDQjn+Sa9cE9BytEJhunOWCCUJdSJVedsnfMX4gh3HYLNpvue1kJ6PG9e23kc4+vVro5g1DPRRuBPt6jdDEfx1aIUYWKoPE/gAeBsgQTAjLq1paMVdyLumFB9JseE/wZBjrCoca9Q3CaGpZkr+8jt/DYsIgYMOA=</param>
        <param name="trans_name">xxxzgl</param>
        <param name="trans_amount">9901</param>
        <param name="notify_url">http%3A%2F%2Falipay.com</param>
        <param name="extend_info">{"secondary_merchant_name":"MNAME006","secondary_merchant_id":"MID0071525932232000","secondary_merchant_industry":"5300","store_id":"SID0071525932232000","store_name":"store1525932232000"}</param>
        <param name="partner_trans_id">620923196607215160_1588066245285</param>
        <param name="trans_currency">USD</param>
        <param name="partner">2088621893731583</param>
        <param name="service">alipay.acquire.overseas.spot.pay</param>
        <param name="currency">USD</param>
        <param name="buyer_identity_code">286865667671986813</param>
        <param name="sign_type">RSA</param>
    </request>
    <response>
        <alipay>
            <error>SYSTEM_ERROR</error>
            <result_code>FAILED</result_code>
        </alipay>
    </response>
    <sign>LZFwCkhvJdwcd7AaIhbCBHe37nFJrhDXomldutoMI0sCzbz+us99GiOJ6p7FZhwCsB5pavYaPlyKg3NU14Ixwqtv+jxKaYC6U1ACc38tg4XYR92YHye16JmitAe5vExJx/vNDAd54VnYX5vs4ztTuJkLI4iuPl4w/eKNr5JcuB4=</sign>
    <sign_type>RSA</sign_type>
</alipay>