Home > Article > Backend Development > Implementation of php online payment function (Alipay)
( 1) The user initiates a request to confirm the order to the mall website (for example, click Buy Now)
(2) The mall website receives the request and saves the order data to the database or other storage media
(3) Returns to the order confirmation page, on the page The order amount and other information should be displayed (the order interface after clicking Buy Now)
(4) The user confirms the payment and initiates a payment request. Note: The payment request is sent to the payment gateway (such as Alipay, online banking) rather than to the mall website.
(5) Display the payment page (this interface is the same interface as Alipay)
(6) The user fills in the authentication information and submits it (scanning the QR code is relatively convenient)
(7) There are two steps here. One is After the deduction is successful, the page jumps to the payment result page (displayed to the user), and the other is the payment notification. These two steps may be executed at the same time in no particular order. After receiving the payment notification, the mall website verifies according to Verification Rules Validity of the information, and make corresponding changes (for example: if valid, change the order to paid status , if invalid, change the order to unpaid status).
Take Alipay as an example: If you want to integrate Alipayinterface into your website, you must first have an Alipay account, then apply for online payment business with Alipay and sign an agreement. After the agreement comes into effect, Alipay will give the website a partner ID and a Security verification code. With these two things, you can develop the Alipay interface according to the Alipay interface document, as shown in the steps above. Only steps 4 and 7 have information exchange between the mall and the payment gateway. In step 4, it means sending the data to the payment gateway (Alipay). In step 7, it is the notification verification part. The verification gateway requests a certain address of the website. The website verifies the information according to the verification rules, records and responds. We are developing almost any payment When it comes to the interface, the focus is on the development of these two parts. If you understand the principles of the payment interface, it will not be difficult to develop the payment interface. It should be emphasized that if we want to test the entire process, then we need to have a merchant account (signing account), which means we need to submit a business license and other materials to Alipay. After passing the Alipay review, we can proceed The account number for payment. (This is rarely available to individuals. You can apply for one in the name of your company during development)
InterfaceIntroduction and testing
Alipay is currently Several interfaces are provided, such as guaranteed transactions, standard instant payment, and dual functions. There are only some differences in functions, but the website integration method is the same. Taking the standard instant account interface as an example, after signing an agreement with Alipay (that is, after becoming an official merchant), several steps are needed to complete the integration. For each function, Alipay's developer platform has listed detailed steps and case studies. For information on how to sign a contract, please visit Alipay Verification
1. Users can open the mobile wallet and select “Scan Scan", aim at the screen to scan the QR code, wait until the mobile phone prompts for payment, select the payment tool and enter the password to pay;
2. If you don’t want to use mobile payment, you can click “Login Account Payment” on the right side of the page as shown above, enter your Alipay account and password to log in.
Please refer to Alipay DSA, RSA, MD5 Three signature methods, it is recommended to use the official tool provided by Alipay, click here to go.
(1) Download the official file (demo) and click to download.
(2) Configure the developer information in DEMO, find the alipay.config.php file in the directory and open it, the content is as follows:
(3) Find the following parameters in config file for corresponding configuration:
(4) If you choose the MD5 signature method, please Configure according to the MD5 method: See step 3
(5) for details. Connect with our php code. We can see that there is another file named alipayapi.php. , this file is used to accept order information, and the order parameters are passed to this file in the form of post. This file has referencedalipay.config.php, so everyone’s basic configuration must be correct. When the parameters are successfully accepted, , will jump to the payment interface pre-written by Alipay.
(6) Accept payment results: configure synchronous return (synchronous jump notification) and asynchronous Callback (asynchronous notification). There are two parameters return_url and notification_url in the configuration file, which can be configured to the return_url page and notify_url page in DEMO respectively. Synchronous returns are obtained using the GET method, and asynchronous notifications are obtained using the POST method. There is a 1-minute timeout for synchronous return verification, and there is no time limit for asynchronous notification verification. Both the return_url page and the notify_url page will verify the data using the AlipayNotify.verify() signature verification method.
(7) Final judgment: judge by the trade_status field (transaction status) in the return parameter and write the execution business logic code.
The above is the detailed content of Implementation of php online payment function (Alipay). For more information, please follow other related articles on the PHP Chinese website!