#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. Go to Alipay portal to sign up.
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:
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.
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: