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.
Before using a mock service, you need to have an Alipay merchant account. See Creating an Alipay merchant account
Watch the following video to have a quick overview of how to use a Mock service:
1. Log in your sandbox and go to the mock service part. By now, the mock service supports the following 4 APIs:
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.
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:
http://mapi.alipaydev.com/gateway.do?client_info=%7B%22client_ip%22%3A%2210.20.30.40%22%7D&identity_code_type=barcode&memo=nomemo&trans_amount=9901&sign_type=MD5&trans_name=xxxzgl&buyer_identity_code=288888888888888888&partner_trans_id=8567745904202380&password=SJV88po0XvIptqWGM4rxP5EQ&sendFormat=normal¤cy=USD&sign=6030aea30c96e01c6e5c709c9f66a7df&agreement_info=%7B%22agreement_no%22%3A%22123%22%7D&trans_currency=USD&biz_product=OVERSEAS_MBARCODE_PAY&service=alipay.acquire.overseas.spot.pay&format_type=xml&quantity=1&partner=2088621880270354
<?xml version="1.0" encoding="GBK"?><alipay> <is_success>T</is_success> <request> <param name="client_info">{"client_ip":"10.20.30.40"}</param> <param name="quantity">1</param> <param name="biz_product">OVERSEAS_MBARCODE_PAY</param> <param name="identity_code_type">barcode</param> <param name="sign">6030aea30c96e01c6e5c709c9f66a7df</param> <param name="memo">nomemo</param> <param name="trans_name">xxxzgl</param> <param name="trans_amount">9901</param> <param name="sendFormat">normal</param> <param name="partner_trans_id">8567745904202380</param> <param name="password">SJV88po0XvIptqWGM4rxP5EQ</param> <param name="format_type">xml</param> <param name="trans_currency">USD</param> <param name="partner">2088621880270354</param> <param name="agreement_info">{"agreement_no":"123"}</param> <param name="service">alipay.acquire.overseas.spot.pay</param> <param name="currency">USD</param> <param name="sign_type">MD5</param> <param name="buyer_identity_code">288888888888888888</param> </request> <response> <alipay> <error>SYSTEM_ERROR</error> <result_code>FAILED</result_code> </alipay> </response> <sign>d0117413cdf375ab667329892ab7f890</sign> <sign_type>MD5</sign_type></alipay>