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
51a8abe5
Commit
51a8abe5
authored
Sep 05, 2022
by
郑炬波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: zf
parent
e87fa7e3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
36 deletions
+22
-36
package.json
packages/toolkit/package.json
+2
-2
Defined.ts
packages/toolkit/src/Payment/Defined.ts
+4
-2
Payment.ts
packages/toolkit/src/Payment/Payment.ts
+16
-32
No files found.
packages/toolkit/package.json
View file @
51a8abe5
{
"name"
:
"@ydl-packages/toolkit"
,
"version"
:
"1.0.1-next.1
4
"
,
"version"
:
"1.0.1-next.1
6
"
,
"description"
:
""
,
"main"
:
"./dist/index.umd.js"
,
"scripts"
:
{
...
...
@@ -27,7 +27,7 @@
"require"
:
"./dist/index.umd.js"
}
},
"types"
:
"
'
./dist/index.d.ts"
,
"types"
:
"./dist/index.d.ts"
,
"dependencies"
:
{
"axios"
:
"^0.27.2"
,
"blueimp-md5"
:
"^2.19.0"
,
...
...
packages/toolkit/src/Payment/Defined.ts
View file @
51a8abe5
...
...
@@ -97,10 +97,11 @@ export type ToPayParams = {
* 用户在微信公众号或小程序的openId
*/
openId
?:
string
;
appId
?:
string
;
/**
* 支付记录id, 采用余额支付的时候如果前端有此值就带过来
*/
wx_appId
?:
number
;
zfb_appId
?:
number
;
payId
?:
number
;
}
...
...
@@ -138,7 +139,8 @@ export type ToPayReturns = {
export
interface
DoUnifiedParams
extends
Omit
<
ToPayParams
,
'totalAmount'
|
'redirectUrl'
>
{
payChannel
?:
PayChannel
,
payBalance
:
number
,
payAmount
:
number
payAmount
:
number
,
appId
:
number
|
undefined
}
export
interface
WechatPayParams
{
...
...
packages/toolkit/src/Payment/Payment.ts
View file @
51a8abe5
...
...
@@ -105,26 +105,18 @@ export class Payment {
case
PayType
.
BALANCE
:
return
this
.
balance
>
0
case
PayType
.
WECHAT
:
return
this
.
balance
===
0
case
PayType
.
WECHAT_BALANCE
:
return
this
.
balance
>
0
&&
this
.
balance
<
totalAmount
return
true
case
PayType
.
ALIPAY
:
return
this
.
balance
===
0
&&
!
Utils
.
isWechat
()
case
PayType
.
ALIPAY_BALANCE
:
return
this
.
balance
>
0
&&
this
.
balance
<
totalAmount
&&
!
Utils
.
isWechat
()
return
!
Utils
.
isWechat
()
case
PayType
.
HUABEI
:
return
this
.
balance
===
0
&&
!
Utils
.
isWechat
()
case
PayType
.
HUABEI_BALANCE
:
return
this
.
balance
>
0
&&
this
.
balance
<
totalAmount
&&
!
Utils
.
isWechat
()
return
!
Utils
.
isWechat
()
}
return
true
}).
map
(
item
=>
{
const
{
payBalance
}
=
this
.
computeAmount
(
totalAmount
,
this
.
balance
)
switch
(
item
.
value
)
{
case
PayType
.
BALANCE
:
return
{
...
item
,
label
:
`余额支付(¥
${
payB
alance
}
)`
,
label
:
`余额支付(¥
${
this
.
b
alance
}
)`
,
disabled
:
this
.
balance
>
0
&&
this
.
balance
<
totalAmount
}
}
...
...
@@ -137,8 +129,8 @@ export class Payment {
if
(
balance
===
0
)
{
payAmount
=
totalAmount
}
else
if
(
balance
>
0
&&
balance
<
totalAmount
)
{
payBalance
=
balance
payAmount
=
subtract
(
bignumber
(
totalAmount
),
bignumber
(
balance
)).
toNumber
()
payBalance
=
0
;
payAmount
=
totalAmount
;
}
else
{
payBalance
=
totalAmount
}
...
...
@@ -146,7 +138,7 @@ export class Payment {
}
async
toPay
(
params
:
ToPayParams
):
Promise
<
ToPayReturns
>
{
const
{
totalAmount
,
payType
,
returnUrl
,
orderId
,
redirectUrl
,
openId
,
appId
,
payId
,
}
=
params
const
{
totalAmount
,
payType
,
returnUrl
,
orderId
,
openId
,
wx_appId
,
zfb_appId
,
payId
}
=
params
let
quitUrl
=
params
.
quitUrl
// validate start >>>
switch
(
payType
)
{
...
...
@@ -158,19 +150,7 @@ export class Payment {
case
PayType
.
WECHAT_BALANCE
:
case
PayType
.
WECHAT
:
if
(
this
.
limitPayChannels
.
includes
(
PayChannel
.
WX_MWEB
)
&&
this
.
limitPayChannels
.
includes
(
PayChannel
.
WX_JSAPI
))
{
if
(
!
redirectUrl
)
{
return
{
errorMessage
:
PayErrorMessage
.
WECHAT_REDIRECT_URL_MISSING
,
success
:
false
,
errorType
:
PayError
.
VALIDATE
}
}
else
if
(
decodeURIComponent
(
redirectUrl
)
===
redirectUrl
)
{
return
{
errorMessage
:
PayErrorMessage
.
WECHAT_REDIRECT_URL_ENCODE
,
success
:
false
,
errorType
:
PayError
.
VALIDATE
}
}
else
if
(
!
appId
)
{
if
(
!
wx_appId
)
{
return
{
success
:
false
,
errorMessage
:
PayErrorMessage
.
WECHAT_APPID_MISSING
,
...
...
@@ -204,7 +184,7 @@ export class Payment {
success
:
false
,
errorType
:
PayError
.
VALIDATE
}
}
else
if
(
!
appId
)
{
}
else
if
(
!
zfb_
appId
)
{
return
{
success
:
false
,
errorMessage
:
PayErrorMessage
.
ALIPAY_APPID_MISSING
,
...
...
@@ -223,8 +203,12 @@ export class Payment {
// validate end <<<
// hack, 后端微信redirectUrl用的quitUrl
const
payChannel
=
this
.
getPayChannel
(
payType
)
let
appId
;
if
(
payChannel
===
PayChannel
.
ALI_WAP
)
{
appId
=
zfb_appId
;
}
if
(
payChannel
===
PayChannel
.
WX_MWEB
||
payChannel
===
PayChannel
.
WX_JSAPI
)
{
quitUrl
=
redirectUrl
appId
=
wx_appId
;
}
const
doUnifiedParams
:
DoUnifiedParams
=
{
returnUrl
,
...
...
@@ -242,7 +226,7 @@ export class Payment {
const
res
=
await
requestForJava
.
post
<
DoUnifiedParams
,
DefaultResponse
>
(
UNIT_PAY
,
doUnifiedParams
)
if
(
res
.
code
!==
'200'
)
return
{
errorMessage
:
res
.
msg
as
any
,
success
:
false
,
errorType
:
PayError
.
BACKEND
}
if
(
params
.
payType
===
PayType
.
BALANCE
&&
res
.
data
)
{
return
{
success
:
res
.
data
.
result
,
errorType
:
PayError
.
BALANCE
}
return
{
success
:
res
.
data
.
result
,
errorType
:
PayError
.
BALANCE
}
//返回回调地址
}
else
if
(
payChannel
===
PayChannel
.
WX_JSAPI
)
{
const
isPaySucc
=
await
this
.
wechatPayJSSDK
(
res
.
data
)
return
{
...
...
@@ -252,7 +236,7 @@ export class Payment {
}
}
else
if
(
payChannel
===
PayChannel
.
WX_MWEB
)
{
return
{
redirectUrl
:
res
.
data
.
content
,
redirectUrl
:
res
.
data
.
content
.
split
(
"mwebUrl
\"
:
\"
"
)[
1
].
split
(
","
)[
0
]
,
success
:
false
,
errorType
:
PayError
.
WECHAT_H5_BREAK
,
errorMessage
:
PayErrorMessage
.
WECHAT_H5_PAY_BREAK
...
...
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