Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ydl-packages
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
许振钊
ydl-packages
Commits
141eaec9
Commit
141eaec9
authored
Sep 14, 2022
by
郑炬波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 组合支付
parent
2c29814e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
2 deletions
+17
-2
Payment.ts
packages/toolkit/src/Payment/Payment.ts
+17
-2
No files found.
packages/toolkit/src/Payment/Payment.ts
View file @
141eaec9
...
...
@@ -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
.
computeAmount
ForCombination
(
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment