Type definitions for APIs of WeChat Mini Program in TypeScript
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Comprehensive payment system for WeChat Mini Programs, including WeChat Pay, global payments, plugin payments, and merchant transfers.
Core WeChat payment functionality for processing transactions in WeChat Mini Programs.
/**
* Launch WeChat payment process
* @param option - Payment parameters from unified order API
*/
function requestPayment<T extends RequestPaymentOption = RequestPaymentOption>(
option: T
): PromisifySuccessResult<T, RequestPaymentOption>;
interface RequestPaymentOption {
/** Payment timestamp */
timeStamp: string;
/** Random string, length less than 32 characters */
nonceStr: string;
/** Unified order API prepay_id parameter, format: prepay_id=*** */
package: string;
/** Signature algorithm, default MD5 */
signType?: 'MD5' | 'HMAC-SHA256';
/** Payment signature */
paySign: string;
/** Success callback */
success?(res: RequestPaymentSuccessCallbackResult): void;
/** Failure callback */
fail?(res: any): void;
/** Completion callback */
complete?(res: any): void;
}
interface RequestPaymentSuccessCallbackResult {
/** Success message */
errMsg: string;
}Usage Examples:
// Basic WeChat payment
wx.requestPayment({
timeStamp: '1414561699',
nonceStr: 'QVqbvGRU',
package: 'prepay_id=u802345jgfjsdfgsdg888',
signType: 'MD5',
paySign: '70EA570631E4BB79628FBCA90534C63FF7FADD89',
success(res) {
console.log('Payment successful:', res);
},
fail(err) {
console.error('Payment failed:', err);
}
});
// With cloud development
wx.cloud.callFunction({
name: 'payment',
data: {
amount: 100,
description: 'Product purchase'
},
success: res => {
const payment = res.result.payment;
wx.requestPayment({
...payment,
success(res) {
console.log('Payment completed:', res);
}
});
}
});Payment for custom transaction component scenarios with order validation.
/**
* Payment for transaction component orders
* @param args - Order payment parameters with validation
*/
function requestOrderPayment<T extends RequestOrderPaymentOption = RequestOrderPaymentOption>(
args: T
): PromisifySuccessResult<T, RequestOrderPaymentOption>;
interface RequestOrderPaymentOption {
/** Payment timestamp */
timeStamp: string;
/** Random string */
nonceStr: string;
/** Prepay package */
package: string;
/** Signature type */
signType: string;
/** Payment signature */
paySign: string;
/** Order information for validation */
orderInfo?: OrderInfo;
/** Success callback */
success?(res: RequestOrderPaymentSuccessCallbackResult): void;
/** Failure callback */
fail?(res: any): void;
/** Completion callback */
complete?(res: any): void;
}
interface OrderInfo {
/** Order ID */
order_id: string;
/** Product information */
product_info?: ProductInfo;
/** Payment info for B2B scenarios */
requestPaymentInfo?: RequestPaymentInfo;
}
interface RequestOrderPaymentSuccessCallbackResult {
/** Success message */
errMsg: string;
}Unified payment interface for various payment scenarios including retail and service payments.
/**
* Common payment interface for unified payment scenarios
* @param option - Common payment configuration
*/
function requestCommonPayment(option: RequestCommonPaymentOption): void;
interface RequestCommonPaymentOption {
/** Signed payment data in JSON format */
signData: string;
/** Payment mode: retail goods, service fees, etc. */
mode: 'retail_pay_goods' | 'retail_pay_order' | 'service_fee';
/** Payment description */
description: string;
/** Payment amount information */
amount: PaymentAmount;
/** Additional payment parameters */
attach?: string;
/** Success callback */
success?(res: RequestCommonPaymentSuccessCallbackResult): void;
/** Failure callback */
fail?(res: any): void;
/** Completion callback */
complete?(res: any): void;
}
interface PaymentAmount {
/** Total amount in cents */
total: number;
/** Currency code */
currency: string;
}
interface RequestCommonPaymentSuccessCallbackResult {
/** Success message */
errMsg: string;
}Usage Examples:
wx.requestCommonPayment({
signData: JSON.stringify({
mchid: '1234567890',
out_trade_no: 'order_12345',
appid: 'wxapp123456'
}),
mode: 'retail_pay_goods',
description: 'Product purchase',
amount: {
total: 10000, // 100.00 yuan in cents
currency: 'CNY'
},
success(res) {
console.log('Common payment success:', res);
},
fail({ errMsg, errno }) {
console.error('Payment failed:', errMsg, errno);
}
});International payment system supporting multiple payment methods and regions.
/**
* Create global payment object for international transactions
* @param option - Global payment configuration
*/
function createGlobalPayment(option: CreateGlobalPaymentOption): GlobalPayment;
interface CreateGlobalPaymentOption {
/** Merchant region code */
mchRegion: string;
/** Sandbox mode for testing */
isSandbox?: boolean;
}
interface GlobalPayment {
/** Selected payment method key */
methodKey?: string;
/**
* Open payment method picker
* @param option - Picker configuration
*/
openMethodPicker(option: OpenMethodPickerOption): Promise<OpenMethodPickerResult>;
/**
* Process global payment after method selection
* @param option - Global payment parameters
*/
requestGlobalPayment(option: RequestGlobalPaymentOption): Promise<RequestGlobalPaymentResult>;
}
interface OpenMethodPickerOption {
/** Payment amount */
amount: number;
/** Currency code */
currency: string;
/** Merchant information */
merchantInfo?: MerchantInfo;
}
interface RequestGlobalPaymentOption {
/** Payment ID from pre-order */
paymentId: string;
/** Prepay information */
prepayInfo: any;
}Usage Examples:
// Global payment workflow
const globalPayment = wx.createGlobalPayment({
mchRegion: 'SG',
isSandbox: true
});
try {
// Step 1: Let user select payment method
const pickerResult = await globalPayment.openMethodPicker({
amount: 100.00,
currency: 'SGD',
merchantInfo: {
name: 'Example Store',
region: 'Singapore'
}
});
console.log('Selected method:', pickerResult.methodKey);
// Step 2: Process payment (for non-WeChat methods)
if (pickerResult.methodKey !== 'wechat_pay') {
// Create pre-order with third-party payment gateway
const preOrderResult = await createTPGPreOrder({
amount: 100.00,
currency: 'SGD'
});
// Step 3: Complete payment
const paymentResult = await globalPayment.requestGlobalPayment({
paymentId: preOrderResult.payment_id,
prepayInfo: preOrderResult.prepay_info
});
console.log('Global payment completed:', paymentResult);
}
} catch (error) {
console.error('Global payment error:', error);
}Payment functionality for WeChat Mini Program plugins.
/**
* Process payment in plugin context
* @param option - Plugin payment configuration
*/
function requestPluginPayment(option: RequestPluginPaymentOption): void;
interface RequestPluginPaymentOption {
/** Plugin version */
version: 'release' | 'trial' | 'dev';
/** Payment fee amount */
fee: number;
/** Payment arguments object */
paymentArgs: Record<string, any>;
/** Currency type */
currencyType: 'CNY';
/** Success callback */
success?(res: any): void;
/** Failure callback */
fail?(res: any): void;
/** Completion callback */
complete?(res: any): void;
}Direct transfer functionality for merchant-to-user transfers.
/**
* Process merchant transfer to user
* @param option - Transfer configuration
*/
function requestMerchantTransfer(option: RequestMerchantTransferOption): void;
interface RequestMerchantTransferOption {
/** Merchant ID */
mchId: string;
/** Sub-merchant ID */
subMchId?: string;
/** Application ID */
appId: string;
/** Sub-application ID */
subAppId?: string;
/** Transfer package data */
package: string;
/** Success callback */
success?(res: any): void;
/** Failure callback */
fail?(res: any): void;
/** Completion callback */
complete?(res: any): void;
}Specialized payment interface for Hong Kong offline payment scenarios.
/**
* Open Hong Kong offline payment view
* @param option - HK offline payment parameters
*/
function openHKOfflinePayView(option: OpenHKOfflinePayViewOption): void;
interface OpenHKOfflinePayViewOption {
/** Payment timestamp */
timeStamp: string;
/** Random string */
nonceStr: string;
/** Payment package */
package: string;
/** Signature type, must be SHA1 */
signType: 'SHA1';
/** Payment signature */
paySign: string;
/** Success callback */
success?(res: any): void;
/** Failure callback */
fail?(res: any): void;
/** Completion callback */
complete?(res: any): void;
}Usage Examples:
// Hong Kong offline payment
wx.openHKOfflinePayView({
timeStamp: '1414561699',
nonceStr: 'QVqbvGRU',
package: 'prepay_id=u802345jgfjsdfgsdg888',
signType: 'SHA1',
paySign: '70EA570631E4BB79628FBCA90534C63FF7FADD89',
success(res) {
console.log('HK offline payment opened:', res);
}
});
// Plugin payment
wx.requestPluginPayment({
version: 'release',
fee: 100, // 1.00 yuan
paymentArgs: {
productId: 'product_123',
description: 'Premium feature unlock'
},
currencyType: 'CNY',
success(res) {
console.log('Plugin payment successful:', res);
},
fail(err) {
console.error('Plugin payment failed:', err);
}
});
// Merchant transfer
wx.requestMerchantTransfer({
mchId: '1234567890',
appId: 'wxapp123456',
package: 'transfer_data_package',
success(res) {
console.log('Transfer initiated:', res);
}
});interface ProductInfo {
/** Product name */
name: string;
/** Product description */
description?: string;
/** Product price */
price: number;
/** Product quantity */
quantity: number;
}
interface RequestPaymentInfo {
/** Random string, length less than 32 characters */
nonceStr?: string;
/** Prepay package from unified order API */
package?: string;
/** Payment signature */
paySign?: string;
/** Signature type */
signType?: string;
/** Payment timestamp */
timeStamp?: string;
}
interface MerchantInfo {
/** Merchant name */
name: string;
/** Merchant region */
region: string;
/** Merchant contact */
contact?: string;
}
interface OpenMethodPickerResult {
/** Selected payment method key */
methodKey: string;
/** Method display name */
methodName?: string;
}
interface RequestGlobalPaymentResult {
/** Payment result status */
status: 'success' | 'failed' | 'pending';
/** Transaction ID */
transactionId?: string;
/** Error message if failed */
errorMsg?: string;
}