Use PaymentUrl to pay
Users can use the super app to pay for the order placed in the mini program if the super app provides the payment service. This document introduces the payment by calling the my.tradePay API with paymentUrl.
User experience
To complete a payment in the mini program, users usually follow the steps below:
- The user chooses goods in the mini program and creates an order, then presses the Pay button in the mini program.
- The mini program redirects the user to the super app and the super app displays the payment page.
- The user confirms the order information, such as the payee and amount, then clicks the Pay button to make the payment.
- After confirming the payment, the super app displays the payment result and redirects the user back to the payment result page in the mini program.
Procedures
To use the my.tradePay API to initiate a payment in the mini program, mini program developers must complete the following steps:
- Confirm that the payment service provided by the super app supports the payment by paymentUrl and obtain the integration guide from the super app.
- Integrate the payment service at the mini program server side.
- Create a mini program in the super app workspace on the Mini Program Platform, or make sure that the mini program can be published in the super app.
- Provide goods and payment services in the mini program.
- Publish the mini program.
Payment process
The following figure illustrates the payment process:
The payment process contains the following steps:
- The user places an order in the mini program (Step 1).
- The mini program client sends a request to create the order to the mini program server by calling the my.request API (Step 2).
- The mini program server creates the order and sends the request to the super app server via the server API provided by the Super APP (Step 3 & 4).
- The Super APP server creates the order and generates paymentUrl, then returns paymentUrl to the mini program server (Step 5-7).
- The mini program server returns paymentUrl to the mini program client (Step 8).
- The mini program client initiates the payment request by calling the my.tradePay API with paymentUrl to the super app (Step 9).
- The Super APP app obtains the order information and renders the cashier page (Step 10-13).
- The user confirms the payment and the super app processes the payment request (Step 14-17).
- The super app returns the payment result to the mini program client. At the same time, the super app server returns the payment result to the mini program server (Step 18 & 19).
- The mini program client displays the payment result (Step 20).
Note:
The payment flow is for reference and may vary depending on the API implementation of the super app.
Sample code
Sample code for the my.tradePay API calling with paymentUrl is as follows:
copy
my.tradePay({
paymentUrl: 'payment url',
success: function(res) {
my.alert({
content: JSON.stringify(res),
});
},
fail: function(res) {
my.alert({
content: JSON.stringify(res),
});
},
});