Commit 141eaec9 by 郑炬波

feat: 组合支付

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