export interface WxPayParams {
	timeStamp: string;
	nonceStr: string;
	package: string;
	signType: string;
	paySign: string;
}

export const requestWxPayment = (params: WxPayParams) => {
	return new Promise<void>((resolve, reject) => {
		uni.requestPayment({
			provider: 'wxpay',
			timeStamp: params.timeStamp,
			nonceStr: params.nonceStr,
			package: params.package,
			signType: params.signType,
			paySign: params.paySign,
			success: () => resolve(),
			fail: (error) => reject(error)
		});
	});
};

export const isPaymentCancelled = (error: unknown) => {
	const message = String((error as any)?.errMsg || '');
	return message.includes('cancel');
};
