Commit 51a8abe5 by 郑炬波

feat: zf

parent e87fa7e3
{
"name": "@ydl-packages/toolkit",
"version": "1.0.1-next.14",
"version": "1.0.1-next.16",
"description": "",
"main": "./dist/index.umd.js",
"scripts": {
......@@ -27,7 +27,7 @@
"require": "./dist/index.umd.js"
}
},
"types": "'./dist/index.d.ts",
"types": "./dist/index.d.ts",
"dependencies": {
"axios": "^0.27.2",
"blueimp-md5": "^2.19.0",
......
......@@ -97,10 +97,11 @@ export type ToPayParams = {
* 用户在微信公众号或小程序的openId
*/
openId?: string;
appId?: string;
/**
* 支付记录id, 采用余额支付的时候如果前端有此值就带过来
*/
wx_appId?: number;
zfb_appId?: number;
payId?: number;
}
......@@ -138,7 +139,8 @@ export type ToPayReturns = {
export interface DoUnifiedParams extends Omit<ToPayParams, 'totalAmount' | 'redirectUrl'> {
payChannel?: PayChannel,
payBalance: number,
payAmount: number
payAmount: number,
appId: number|undefined
}
export interface WechatPayParams {
......
......@@ -105,26 +105,18 @@ export class Payment {
case PayType.BALANCE:
return this.balance > 0
case PayType.WECHAT:
return this.balance === 0
case PayType.WECHAT_BALANCE:
return this.balance > 0 && this.balance < totalAmount
return true
case PayType.ALIPAY:
return this.balance === 0 && !Utils.isWechat()
case PayType.ALIPAY_BALANCE:
return this.balance > 0 && this.balance < totalAmount && !Utils.isWechat()
return !Utils.isWechat()
case PayType.HUABEI:
return this.balance === 0 && !Utils.isWechat()
case PayType.HUABEI_BALANCE:
return this.balance > 0 && this.balance < totalAmount && !Utils.isWechat()
return !Utils.isWechat()
}
return true
}).map(item => {
const {payBalance} = this.computeAmount(totalAmount, this.balance)
switch (item.value) {
case PayType.BALANCE:
return {
...item,
label: `余额支付(¥${payBalance})`,
label: `余额支付(¥${this.balance})`,
disabled: this.balance > 0 && this.balance < totalAmount
}
}
......@@ -137,8 +129,8 @@ export class Payment {
if (balance === 0) {
payAmount = totalAmount
} else if (balance > 0 && balance < totalAmount) {
payBalance = balance
payAmount = subtract(bignumber(totalAmount), bignumber(balance)).toNumber()
payBalance = 0;
payAmount = totalAmount;
} else {
payBalance = totalAmount
}
......@@ -146,7 +138,7 @@ export class Payment {
}
async toPay(params: ToPayParams): Promise<ToPayReturns> {
const {totalAmount, payType, returnUrl, orderId, redirectUrl, openId, appId, payId,} = params
const {totalAmount, payType, returnUrl, orderId, openId, wx_appId, zfb_appId, payId} = params
let quitUrl = params.quitUrl
// validate start >>>
switch (payType) {
......@@ -158,19 +150,7 @@ export class Payment {
case PayType.WECHAT_BALANCE:
case PayType.WECHAT:
if (this.limitPayChannels.includes(PayChannel.WX_MWEB) && this.limitPayChannels.includes(PayChannel.WX_JSAPI)) {
if (!redirectUrl) {
return {
errorMessage: PayErrorMessage.WECHAT_REDIRECT_URL_MISSING,
success: false,
errorType: PayError.VALIDATE
}
} else if (decodeURIComponent(redirectUrl) === redirectUrl) {
return {
errorMessage: PayErrorMessage.WECHAT_REDIRECT_URL_ENCODE,
success: false,
errorType: PayError.VALIDATE
}
} else if (!appId) {
if (!wx_appId) {
return {
success: false,
errorMessage: PayErrorMessage.WECHAT_APPID_MISSING,
......@@ -204,7 +184,7 @@ export class Payment {
success: false,
errorType: PayError.VALIDATE
}
} else if (!appId) {
} else if (!zfb_appId) {
return {
success: false,
errorMessage: PayErrorMessage.ALIPAY_APPID_MISSING,
......@@ -223,8 +203,12 @@ export class Payment {
// validate end <<<
// hack, 后端微信redirectUrl用的quitUrl
const payChannel = this.getPayChannel(payType)
let appId;
if (payChannel === PayChannel.ALI_WAP) {
appId = zfb_appId;
}
if (payChannel === PayChannel.WX_MWEB || payChannel === PayChannel.WX_JSAPI) {
quitUrl = redirectUrl
appId = wx_appId;
}
const doUnifiedParams: DoUnifiedParams = {
returnUrl,
......@@ -242,7 +226,7 @@ export class Payment {
const res = await requestForJava.post<DoUnifiedParams, DefaultResponse>(UNIT_PAY, doUnifiedParams)
if (res.code !== '200') return {errorMessage: res.msg as any, success: false, errorType: PayError.BACKEND}
if (params.payType === PayType.BALANCE && res.data) {
return {success: res.data.result, errorType: PayError.BALANCE}
return {success: res.data.result, errorType: PayError.BALANCE} //返回回调地址
} else if (payChannel === PayChannel.WX_JSAPI) {
const isPaySucc = await this.wechatPayJSSDK(res.data)
return {
......@@ -252,7 +236,7 @@ export class Payment {
}
} else if (payChannel === PayChannel.WX_MWEB) {
return {
redirectUrl: res.data.content,
redirectUrl: res.data.content.split("mwebUrl\":\"")[1].split(",")[0],
success: false,
errorType: PayError.WECHAT_H5_BREAK,
errorMessage: PayErrorMessage.WECHAT_H5_PAY_BREAK
......
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