Commit 2c29814e by 郑炬波

feat: fix

parent 1433b669
{ {
"name": "@ydl-packages/toolkit", "name": "@ydl-packages/toolkit",
"version": "1.0.1-next.25", "version": "1.0.1-next.31",
"description": "", "description": "",
"main": "./dist/index.umd.js", "main": "./dist/index.umd.js",
"scripts": { "scripts": {
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
"test": "npx jest __tests__", "test": "npx jest __tests__",
"doc": "npx typedoc", "doc": "npx typedoc",
"prepublishOnly": "npm run lib", "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": [ "keywords": [
"pay", "pay",
......
...@@ -13,7 +13,7 @@ export type BackInfo = { ...@@ -13,7 +13,7 @@ export type BackInfo = {
orderId: number; orderId: number;
payId: number payId: number
} }
export type OrderStateCallBack = (params: BackInfo & { isPay: boolean }) => void export type OrderStateCallBack = (params: BackInfo & { isPay: boolean, isLimit?: boolean }) => void
export type PaymentParams = { export type PaymentParams = {
payChannels?: PayChannel[], payChannels?: PayChannel[],
......
...@@ -161,15 +161,15 @@ export class Payment { ...@@ -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 let payBalance = 0, payAmount = 0
if (balance === 0) { if(payType == PayType.BALANCE){
payAmount = totalAmount payBalance = totalAmount;
} else if (balance > 0 && balance < totalAmount && this.supportCombination) { payAmount = 0;
payBalance = balance }
payAmount = subtract(bignumber(totalAmount), bignumber(balance)).toNumber() else{
} else { payBalance = 0;
payBalance = totalAmount payAmount = totalAmount;
} }
return {payAmount, payBalance} return {payAmount, payBalance}
} }
...@@ -243,7 +243,7 @@ export class Payment { ...@@ -243,7 +243,7 @@ export class Payment {
orderId, orderId,
payType, payType,
payId, payId,
...this.computeAmount(totalAmount, this.balance), ...this.computeAmount(totalAmount, payType)
} }
if (payChannel !== null) { if (payChannel !== null) {
doUnifiedParams.payChannel = payChannel doUnifiedParams.payChannel = payChannel
...@@ -319,7 +319,7 @@ export class Payment { ...@@ -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 [, queryString] = window.location.href.split('?')
const query = queryString ? qs.parse(queryString, {ignoreQueryPrefix: true}) : {} const query = queryString ? qs.parse(queryString, {ignoreQueryPrefix: true}) : {}
const returnParams: BackInfo = {payId: Number(query[BACK_PAY_ID]), orderId: Number(query[BACK_ORDER_ID])} const returnParams: BackInfo = {payId: Number(query[BACK_PAY_ID]), orderId: Number(query[BACK_ORDER_ID])}
...@@ -327,11 +327,11 @@ export class Payment { ...@@ -327,11 +327,11 @@ export class Payment {
const checkLoop = () => { const checkLoop = () => {
if (--count > 0) { if (--count > 0) {
timer = setTimeout(() => { timer = setTimeout(() => {
this.loopValidateOrderState(count, callBack, polltime) this.loopValidateOrderState(count, callBack, pollTime)
}, polltime) }, pollTime)
} else { } else {
clearInterval(timer); callBack({isPay: false, ...returnParams, isLimit:true})
callBack({isPay: false, ...returnParams}) timer && clearTimeout(timer)
} }
} }
if (query[BACK_PAY_ID]) { if (query[BACK_PAY_ID]) {
...@@ -340,8 +340,8 @@ export class Payment { ...@@ -340,8 +340,8 @@ export class Payment {
payId: query[BACK_PAY_ID] payId: query[BACK_PAY_ID]
}) })
if (res.code === '200' && res.data === true) { if (res.code === '200' && res.data === true) {
clearInterval(timer);
callBack({isPay: true, ...returnParams}) callBack({isPay: true, ...returnParams})
timer && clearTimeout(timer)
} else { } else {
checkLoop() 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