Commit 2c29814e by 郑炬波

feat: fix

parent 1433b669
{
"name": "@ydl-packages/toolkit",
"version": "1.0.1-next.25",
"version": "1.0.1-next.31",
"description": "",
"main": "./dist/index.umd.js",
"scripts": {
......@@ -8,7 +8,9 @@
"test": "npx jest __tests__",
"doc": "npx typedoc",
"prepublishOnly": "npm run lib",
"commit": "git add . && npx cz-customizable"
"commit": "git add . && npx cz-customizable",
"async": "npm run lib && yalc push",
"watch": "nodemon --ignore dist/ --ignore node_modules/ --watch src/ -C -e ts --debug -x npm run async"
},
"keywords": [
"pay",
......
......@@ -13,7 +13,7 @@ export type BackInfo = {
orderId: number;
payId: number
}
export type OrderStateCallBack = (params: BackInfo & { isPay: boolean }) => void
export type OrderStateCallBack = (params: BackInfo & { isPay: boolean, isLimit?: boolean }) => void
export type PaymentParams = {
payChannels?: PayChannel[],
......@@ -185,6 +185,6 @@ export const FULL_PAY_METHODS: PayMethod[] = [
label: '花呗支付',
value: PayType.HUABEI_BALANCE,
icon: 'https://static.ydlcdn.com/m/order/icon-pay-hb.png',
disabled: false
disabled: false
}
]
\ No newline at end of file
......@@ -161,15 +161,15 @@ export class Payment {
})
}
computeAmount(totalAmount: number, balance: number = 0): { payAmount: number, payBalance: number } {
computeAmount(totalAmount: number, payType: PayType): { payAmount: number, payBalance: number } {
let payBalance = 0, payAmount = 0
if (balance === 0) {
payAmount = totalAmount
} else if (balance > 0 && balance < totalAmount && this.supportCombination) {
payBalance = balance
payAmount = subtract(bignumber(totalAmount), bignumber(balance)).toNumber()
} else {
payBalance = totalAmount
if(payType == PayType.BALANCE){
payBalance = totalAmount;
payAmount = 0;
}
else{
payBalance = 0;
payAmount = totalAmount;
}
return {payAmount, payBalance}
}
......@@ -243,7 +243,7 @@ export class Payment {
orderId,
payType,
payId,
...this.computeAmount(totalAmount, this.balance),
...this.computeAmount(totalAmount, payType)
}
if (payChannel !== null) {
doUnifiedParams.payChannel = payChannel
......@@ -319,7 +319,7 @@ export class Payment {
})
}
static async loopValidateOrderState(count = 0, callBack: OrderStateCallBack, polltime = 3000): Promise<void> {
static async loopValidateOrderState(count = 0, callBack: OrderStateCallBack, pollTime = 3000): Promise<void> {
const [, queryString] = window.location.href.split('?')
const query = queryString ? qs.parse(queryString, {ignoreQueryPrefix: true}) : {}
const returnParams: BackInfo = {payId: Number(query[BACK_PAY_ID]), orderId: Number(query[BACK_ORDER_ID])}
......@@ -327,11 +327,11 @@ export class Payment {
const checkLoop = () => {
if (--count > 0) {
timer = setTimeout(() => {
this.loopValidateOrderState(count, callBack, polltime)
}, polltime)
this.loopValidateOrderState(count, callBack, pollTime)
}, pollTime)
} else {
clearInterval(timer);
callBack({isPay: false, ...returnParams})
callBack({isPay: false, ...returnParams, isLimit:true})
timer && clearTimeout(timer)
}
}
if (query[BACK_PAY_ID]) {
......@@ -340,8 +340,8 @@ export class Payment {
payId: query[BACK_PAY_ID]
})
if (res.code === '200' && res.data === true) {
clearInterval(timer);
callBack({isPay: true, ...returnParams})
timer && clearTimeout(timer)
} else {
checkLoop()
}
......
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