Commit 02061305 by xuzhenzhao

feat(custom): add appid,openid validate

 -
parent d32de7b1
......@@ -13,6 +13,13 @@ describe('测试: 创建实例', () => {
const payment = new Payment()
expect(payment.limitPayChannels).toEqual(Object.keys(PayChannel).map(key => key))
})
test('empty array', () => {
const payment = new Payment({
payChannels: []
})
expect(payment.limitPayChannels).toEqual([])
})
})
test('测试订单查询链接', () => {
......
......@@ -113,13 +113,15 @@ export enum PayErrorMessage {
BALANCE_EMPTY = '余额不足',
WECHAT_REDIRECT_URL_MISSING= `请填写微信回调地址页面 'redirectUrl`,
WECHAT_REDIRECT_URL_ENCODE = 'redirectUrl需要encode',
WECHAT_PAY_CHANNEL_MISSING =`缺少持的渠道参数:'WX_MWEB','WX_JSAPI'`,
WECHAT_PAY_CHANNEL_MISSING =`缺少渠道参数:'WX_MWEB','WX_JSAPI'`,
WECHAT_APPID_MISSING = '缺少微信APPID入参',
ALIPAY_QUIT_URL_MISSING = `缺少支付失败回调地址:'quitUrl'`,
ALIPAY_RETURN_URL_MISSING = `缺少支付成功回调地址:'returnUrl'`,
ALIPAY_PAY_CHANNEL_MISSING = `缺少持的渠道参数:'ALI_WAP'`,
WECHAT_JSSDK_PAY_ERROR = '微信JSSDK支付失败',
WECHAT_H5_PAY_BREAK = '微信h5支付中断',
ALIPAY_H5_PAY_BREAK = '支付宝支付中断'
ALIPAY_H5_PAY_BREAK = '支付宝支付中断',
ALIPAY_APPID_MISSING = '缺少微信APPID入参',
}
export type ToPayReturns = {
......
import {UNIT_PAY, IS_PAY, MY_BALANCE} from "./API";
import {IS_PAY, MY_BALANCE, UNIT_PAY} from "./API";
import md5 from 'blueimp-md5'
import qs from 'qs'
import {Utils} from "@/Utils/Utils";
......@@ -145,7 +145,7 @@ export class Payment {
return {payAmount, payBalance}
}
async toPay(params: ToPayParams): Promise<ToPayReturns> {
public async toPay(params: ToPayParams): Promise<ToPayReturns> {
const {totalAmount, payType, returnUrl, orderId, redirectUrl, openId, appId,} = params
let quitUrl = params.quitUrl
// validate start >>>
......@@ -170,6 +170,12 @@ export class Payment {
success: false,
errorType: PayError.VALIDATE
}
} else if (!appId) {
return {
success: false,
errorMessage: PayErrorMessage.WECHAT_APPID_MISSING,
errorType: PayError.VALIDATE
}
}
} else {
return {
......@@ -198,6 +204,12 @@ export class Payment {
success: false,
errorType: PayError.VALIDATE
}
} else if (!appId) {
return {
success: false,
errorMessage: PayErrorMessage.ALIPAY_APPID_MISSING,
errorType: PayError.VALIDATE
}
}
} else {
return {
......@@ -255,7 +267,7 @@ export class Payment {
return {success: false, errorType: PayError.UNKNOWN}
}
getPayChannel(payType: PayType): PayChannel | null {
private getPayChannel(payType: PayType): PayChannel | null {
switch (payType) {
case PayType.WECHAT_BALANCE:
case PayType.WECHAT:
......@@ -271,7 +283,7 @@ export class Payment {
return null
}
wechatPayJSSDK(wechatPayParams: WechatPayParams): Promise<boolean> {
private wechatPayJSSDK(wechatPayParams: WechatPayParams): Promise<boolean> {
const {appId, timeStamp, nonceStr, signType, paySign, package: packageAlias} = wechatPayParams
return new Promise((resolve) => {
window.WeixinJSBridge.invoke(
......
......@@ -4,6 +4,7 @@ npx changeset pre enter next
npx changeset
npx changeset version --prelease
npx run lib
npx changeset publish
npx changeset pre exit
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment