tencent cloud

Last updated: 2025-12-05 22:29:15
Payment
Last updated: 2025-12-05 22:29:15

requestPayment

This API is called using wx.requestPayment(Object object).
Feature description:This API initiates payment in the superapp. The superapp must have payment capabilities and complete the payment process integration. We recommend developers refer to our Payment and Merchant Practical Tutorial for API implementation. It requires the collaboration between superapp and mini program developers to effectively ensure data security and payment scalability.
Note: Generally, the parameters timeStamp, nonceStr, package, signType, and paySign should be generated by the mini program backend. The values are returned when the mini program frontend calls the backend order API, and then used to call wx.requestPayment to initiate the payment process.
Parameter and description: Object object.
Property
Type
Default value
‍Required
Description
timeStamp
string
-
True
Timestamp in seconds since 1970-01-01 00:00:00, representing the current time.
nonceStr
string
-
True
Random string, up to 32 characters long.
package
string
-
True
The prepay_id parameter value returned from the unified order API, formatted as: prepay_id=***.
signType
string
-
True
Signature algorithm, should match the value used during backend ordering, typically: RSA.
paySign
string
-
True
Signature. For details, see Payment and Merchant Practical Tutorial
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Example:
wx.requestPayment({
timeStamp: '',
nonceStr: '',
package: '',
signType: 'RSA',
paySign: '',
success (res) {
/* res is typically returned by the superapp to the mini program frontend, with its structure customized by the superapp
* Upon successful payment, res.errMsg will be 'requestPayment:ok'
* It is recommended for the mini program to call the backend API to confirm payment status in the success callback to ensure payment callback information is synchronized with the mini program backend
*/
if(res.errMsg === 'resquestPayment:ok'){
// send request to miniprogram backend to comfirm payment state
}
},
fail (err) {
// The error message is usually returned by the superapp to the mini program frontend, and the mini program frontend should provide appropriate user guidance after the error occurs.
}
})
If the superapp already has a mature and reliable payment process, the developers can customize the payment flow by combining this API with custom APIs.

requestVirtualPayment

This API is called using wx.requestVirtualPayment(Object object).
Feature description:This API initiates payment in the superapp. The superapp must have virtual payment capabilities and complete the payment process integration. We recommend developers refer to our Payment and Merchant Practical Tutorial for API implementation. It requires the collaboration between superapp and mini program developers to effectively ensure data security and payment scalability.
Note: Typically, the signature and paySign should be generated by the mini program background. The values are returned when the mini program frontend calls the backend order API, and then used to call wx.requestVirtualPayment to initiate the payment process.
Parameter and description: Object object.
Property
Type
Default value
‍Required
Description
signData
string
-
True
For specific payment parameters, see signData. This parameter must be passed as a string, for example: signData: '{"offerId":"123","buyQuantity":1,"currencyType":"USD","productId":"testproductId","goodsPrice":10,"outTradeNo":"xxxxxx","attach":"testdata"}'
mode
string
-
True
Only short_series_goods is supported.
signature
string
-
True
User-mode signature. For details, see Payment and Merchant Practical Tutorial
paySign
string
-
True
Payment signature. For details, see Payment and Merchant Practical Tutorial
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
signData parameter:
Property
Type
Default value
‍Required
Description
offerId
string
-
True
Merchant ID.
buyQuantity
string
-
True
Purchase quantity.
currencyType
string
-
True
Currency, e.g., USD. For details, see the payment currencies supported by the superapp in the console.
productId
string
-

Item ID. This field is required when mode=short_series_goods.
goodsPrice
number
-

Item unit price (in cents). This field is required when mode=short_series_goods.
outTradeNo
string
-
True
Order number. Each order number can only be used once. Reusing it will result in a failure.
attach
string
-
True
Pass-through data, which will be passed back to the developer in the delivery push.
Example:
wx.requestVirtualPayment({
signData: JSON.stringify({
offerId: '123',
buyQuantity: 1,
currencyType: 'USD',
productId: 'testproductId',
goodsPrice: 10,
outTradeNo: 'xxxxxx',
attach: 'testdata',
}),
paySig: 'd0b8bbccbe109b11549bcfd6602b08711f46600965253a949cd6a2b895152f9d',
signature: 'd0b8bbccbe109b11549bcfd6602b08711f46600965253a949cd6a2b895152f9d',
mode: 'short_series_goods',
success(res) {
console.log('requestVirtualPayment success', res)
},
fail({ errMsg, errCode }) {
console.error(errMsg, errCode)
},
})
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback