Commit 141eaec9 by 郑炬波

feat: 组合支付

parent 2c29814e
......@@ -148,7 +148,7 @@ export class Payment {
return this.balance > 0 && this.balance < totalAmount && !Utils.isWechat()
}
}).map(item => {
const {payBalance} = this.computeAmount(totalAmount, this.balance)
const {payBalance} = this.computeAmountForCombination(totalAmount, this.balance)
switch (item.value) {
case PayType.BALANCE:
return {
......@@ -174,6 +174,19 @@ export class Payment {
return {payAmount, payBalance}
}
computeAmountForCombination(totalAmount: number, balance: number = 0): { payAmount: number, payBalance: number } {
let payBalance = 0, payAmount = 0
if (balance === 0) {
payAmount = totalAmount
} else if (balance > 0 && balance < totalAmount) {
payBalance = balance;
payAmount = totalAmount - balance;
} else {
payBalance = totalAmount
}
return {payAmount, payBalance}
}
async toPay(params: ToPayParams): Promise<ToPayReturns> {
const {totalAmount, payType, returnUrl, orderId, redirectUrl, payId} = params
let quitUrl = params.quitUrl
......@@ -237,13 +250,15 @@ export class Payment {
if (payChannel === PayChannel.WX_MWEB || payChannel === PayChannel.WX_JSAPI) {
quitUrl = redirectUrl
}
const { payAmount, payBalance } = this.supportCombination ? this.computeAmountForCombination(totalAmount, this.balance) : this.computeAmount(totalAmount, payType);
const doUnifiedParams: DoUnifiedParams = {
returnUrl,
quitUrl,
orderId,
payType,
payId,
...this.computeAmount(totalAmount, payType)
payAmount,
payBalance
}
if (payChannel !== null) {
doUnifiedParams.payChannel = payChannel
......
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