Integration
System architecture
The Alipay fast food self-service solution can be designed to three modules: the front end, the back end, and the data analysis layer. Each module contains specific functions for providing corresponding services.
The following system architecture is an example for your reference to design the self-service system:
- The front end: Contains several underlying components to ensure a user-friendly interface. An ordering and food delivery section can be designed to provide customers easy entries for food services. Sales data can also be displayed for customers. Electronic menu is also needed to support the online ordering service. Restaurant point-of-sale (POS) system is needed for checking out bills. Cloud service, object storage, and load balancing are also functional parts nice to have.
- The back end: Contains at least the menu system, the ordering system, the payment system, and other IT system to deal with the business logic. Also a cloud service need to be provided.
- Data analyzer: Contains modules to handle customer data and sales data, and several sub modules that can be designed according to the merchant requirements.
Alipay can provide technical support for the following modules:
- Digital menu: The alipay.system.oauth.token interface can be used to get user ID, which is used in the digital menu model to identify ordered dishes belong to different users.
- Restaurant POS system: Alipay can provide a payment interface for the restaurant POS system and standalone tablet modules to collect payments.
- Payment system: Connected to Alipay gateway directly or indirectly through an acquirer gateway.
- Sales data: Alipay can provide the sales data for merchants to do further analysis.
- Business analysis, Marketing, Process optimization, User research, Industry trends: Alipay can provide transaction data and marketing related data for these modules.
- Cloud server, Object storage, Load balancing, Big data platform: Alibaba group has a lot of mature products and services that can support the functions of these modules.
Integration with Alipay
Before integration, you need to create an Alipay account and an Alipay application. Besides, the development environment and keys also need to be configured. You can use the sandbox environment to test the integration before going live. The following content provides some key information about the integration process. For more details about integration, please contact Global Merchant Technical Support at AlipayGlobalTechService@service.alipay.com.
Prepare keys
To generate a digital signature, normally a key is required to sign the data. You must prepare the MD5 private key or the RSA/RSA2 private and public key pair to generate and verify a digital signature.
Implement APIs
To integrate with the Alipay system for a specific service, you can call Alipay APIs by sending an HTTP/HTTPS request to Alipay and use keys to sign the request before you send them.
Alipay provides two ways for customers to pay:
- Barcode payment: also called B-scan-C payment, with which customers pay the bill by providing their payment QR code for merchants to scan.
- Merchant QR code payment: also called C-scan-B payment, with which customers pay the bill by scanning the merchant QR code and pay.
The following sequence diagrams give you a big picture of how the merchant, the institution, and Alipay work together to provide services for customers in each case.
Barcode payment (B-scan-C payment)
The barcode payment supports two types of payment modes: offline mode and offline-to-online mode. The following sequence flow shows details of both modes:
Offline mode:
- The customer places an order and see a screen prompt for payment.
- The customer shows the Alipay app barcode to be scanned by a scanner for payment.
- The ECR/POS/app calls partner API, then the partner calls Alipay payment API. When the payment process returns a result code of
SUCCESS
orFAILED
, a payment result is returned. - The ECR/POS/app completes the payment and generates the receipt.
- The customer receives the receipt.
Offline-to-online mode:
- The customer places an order and see a screen prompt for payment.
- The customer shows the Alipay app barcode to be scanned by a scanner for payment.
- The ECR/POS/app calls partner API, then the partner calls Alipay payment API. When the payment process returns a result code of
UNKNOWN
orTIMEOUT
, the query API is to be called to check the payment result.
- If the payment succeeds, the successful result will be returned to ECR/POS/App and a receipt will be generated.
- If the payment fails, you can call the cancel API to cancel the transaction.
Merchant QR code payment (C-scan-B payment)
The merchant QR code payment solution makes use of a static QR code to represent the account of a merchant. In this payment solution, the customer needs to scan the QR code and then enter the amount to complete the payment.
- The customer scans the merchant QR code with the Alipay wallet.
- The customer enters the amount to pay and submit the payment request.
2.1. A payment is created in the Alipay system.
- The cashier inside the Alipay wallet is evoked.
3.1 The customer makes the payment.
- Alipay processes the payment and notifies the payment results to customers.
- Alipay notifies the payment results to partners.
5.1 Alipay notifies the payment results to merchants.
Test in sandbox environment
Sandbox is an environment where you can mimic the characteristics of the production environment and create simulated responses from all APIs the application relies on before going live. You can make API tests based on your own requirements including making a transaction, cancel, or refund a transaction, and so on.
Go Live
When you have completed tests in the sandbox environment and are ready for going live, you can turn to the production environment by changing the gateway, PID, and keys to real ones.
Exception handling
Users are prompted to enter payment password during the payment process. To keep the payment status updated correctly in the merchant server, the merchant is recommended to call the query API once every 5 seconds during a 60-second interval since the start of the payment request. If the payment status is UNKNOWN, keep calling the query API every 5 seconds until Alipay responds TRADE_SUCCESS
or TRADE_FAIL
. If the payment status is still UNKNOWN
after 60 seconds, then call the cancel API to cancel this order.