Commit 51a8abe5 by 郑炬波

feat: zf

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