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
ed9acb52
Commit
ed9acb52
authored
Oct 28, 2022
by
郑炬波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 去payId
parent
332f2f17
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
11 additions
and
22 deletions
+11
-22
hasBalance.test.ts
packages/toolkit/__tests__/payment/hasBalance.test.ts
+1
-1
notHaveBalance.test.ts
packages/toolkit/__tests__/payment/notHaveBalance.test.ts
+1
-1
units.test.ts
packages/toolkit/__tests__/payment/units.test.ts
+2
-5
package.json
packages/toolkit/package.json
+1
-1
API.ts
packages/toolkit/src/Payment/API.ts
+1
-1
Defined.ts
packages/toolkit/src/Payment/Defined.ts
+0
-4
Payment.ts
packages/toolkit/src/Payment/Payment.ts
+5
-9
No files found.
packages/toolkit/__tests__/payment/hasBalance.test.ts
View file @
ed9acb52
...
@@ -22,7 +22,7 @@ const globalDatabase: any = {
...
@@ -22,7 +22,7 @@ const globalDatabase: any = {
}
}
}
}
const
createOrder
=
async
():
Promise
<
{
orderId
:
number
,
title
:
string
,
payId
:
number
,
money
:
number
}
>
=>
{
const
createOrder
=
async
():
Promise
<
{
orderId
:
number
,
title
:
string
,
money
:
number
}
>
=>
{
const
res
=
await
defaultRequest
.
post
<
any
,
DefaultResponse
>
(
'https://testapi.ydl.com/api/consult/user/order/submitWorriesConsultOrder'
,
globalDatabase
.
MOCK_GOODS
)
const
res
=
await
defaultRequest
.
post
<
any
,
DefaultResponse
>
(
'https://testapi.ydl.com/api/consult/user/order/submitWorriesConsultOrder'
,
globalDatabase
.
MOCK_GOODS
)
return
res
.
data
return
res
.
data
}
}
...
...
packages/toolkit/__tests__/payment/notHaveBalance.test.ts
View file @
ed9acb52
...
@@ -23,7 +23,7 @@ const globalDatabase: any = {
...
@@ -23,7 +23,7 @@ const globalDatabase: any = {
}
}
}
}
const
createOrder
=
async
():
Promise
<
{
orderId
:
number
,
title
:
string
,
payId
:
number
,
money
:
number
}
>
=>
{
const
createOrder
=
async
():
Promise
<
{
orderId
:
number
,
title
:
string
,
money
:
number
}
>
=>
{
const
res
=
await
defaultRequest
.
post
<
any
,
DefaultResponse
>
(
'https://testapi.ydl.com/api/consult/user/order/submitWorriesConsultOrder'
,
globalDatabase
.
MOCK_GOODS
)
const
res
=
await
defaultRequest
.
post
<
any
,
DefaultResponse
>
(
'https://testapi.ydl.com/api/consult/user/order/submitWorriesConsultOrder'
,
globalDatabase
.
MOCK_GOODS
)
return
res
.
data
return
res
.
data
}
}
...
...
packages/toolkit/__tests__/payment/units.test.ts
View file @
ed9acb52
import
{
describe
,
expect
,
test
}
from
'@jest/globals'
import
{
describe
,
expect
,
test
}
from
'@jest/globals'
import
{
BACK_ORDER_ID
,
BACK_PAY_ID
,
PayChannel
,
PayError
,
PayErrorMessage
,
Payment
,
PayType
}
from
"@/Payment/Payment"
;
import
{
BACK_ORDER_ID
,
PayChannel
,
PayError
,
PayErrorMessage
,
Payment
,
PayType
}
from
"@/Payment/Payment"
;
describe
(
'测试: 创建实例'
,
()
=>
{
describe
(
'测试: 创建实例'
,
()
=>
{
test
(
'supportCombination'
,
()
=>
{
test
(
'supportCombination'
,
()
=>
{
...
@@ -38,12 +38,9 @@ describe('测试: 创建实例', () => {
...
@@ -38,12 +38,9 @@ describe('测试: 创建实例', () => {
})
})
test
(
'测试订单查询链接'
,
()
=>
{
test
(
'测试订单查询链接'
,
()
=>
{
const
testPayId
=
111
const
testOrderId
=
222
const
testOrderId
=
222
const
backUrl
=
Payment
.
createBackInfoUrl
(
window
.
location
.
href
,
testPayId
,
testOrderId
)
const
backUrl
=
Payment
.
createBackInfoUrl
(
window
.
location
.
href
,
testOrderId
)
expect
(
backUrl
).
toContain
(
BACK_PAY_ID
)
expect
(
backUrl
).
toContain
(
BACK_ORDER_ID
)
expect
(
backUrl
).
toContain
(
BACK_ORDER_ID
)
expect
(
backUrl
).
toContain
(
testPayId
.
toString
())
expect
(
backUrl
).
toContain
(
testOrderId
.
toString
())
expect
(
backUrl
).
toContain
(
testOrderId
.
toString
())
expect
(
backUrl
).
toContain
(
window
.
location
.
origin
)
expect
(
backUrl
).
toContain
(
window
.
location
.
origin
)
})
})
...
...
packages/toolkit/package.json
View file @
ed9acb52
{
{
"name"
:
"@ydl-packages/toolkit"
,
"name"
:
"@ydl-packages/toolkit"
,
"version"
:
"1.0.
1-next.3
3"
,
"version"
:
"1.0.
3-next.
3"
,
"description"
:
""
,
"description"
:
""
,
"main"
:
"./dist/index.umd.js"
,
"main"
:
"./dist/index.umd.js"
,
"scripts"
:
{
"scripts"
:
{
...
...
packages/toolkit/src/Payment/API.ts
View file @
ed9acb52
...
@@ -24,7 +24,7 @@ export const UNIT_PAY = `${BASE_URL_JAVA}/api/auth/cashierV2/unityPay`
...
@@ -24,7 +24,7 @@ export const UNIT_PAY = `${BASE_URL_JAVA}/api/auth/cashierV2/unityPay`
export
const
COMMIT_ORDER
=
`
${
BASE_URL_JAVA
}
/api/consult/consult/commit-order`
export
const
COMMIT_ORDER
=
`
${
BASE_URL_JAVA
}
/api/consult/consult/commit-order`
export
const
IS_PAY
=
`
${
BASE_URL_JAVA
}
/api/auth/Order/
i
sPay`
export
const
IS_PAY
=
`
${
BASE_URL_JAVA
}
/api/auth/Order/
orderI
sPay`
export
const
MY_BALANCE
=
`
${
BASE_GATEWAY
}
/v3/uc/mybalance`
export
const
MY_BALANCE
=
`
${
BASE_GATEWAY
}
/v3/uc/mybalance`
...
...
packages/toolkit/src/Payment/Defined.ts
View file @
ed9acb52
...
@@ -5,13 +5,10 @@ export type PayMethod = {
...
@@ -5,13 +5,10 @@ export type PayMethod = {
disabled
:
boolean
disabled
:
boolean
}
}
export
const
BACK_PAY_ID
=
'backPayId'
export
const
BACK_ORDER_ID
=
'backOrderId'
export
const
BACK_ORDER_ID
=
'backOrderId'
export
type
BackInfo
=
{
export
type
BackInfo
=
{
orderId
:
number
;
orderId
:
number
;
payId
:
number
}
}
export
type
OrderStateCallBack
=
(
params
:
BackInfo
&
{
isPay
:
boolean
,
isLimit
?:
boolean
})
=>
void
export
type
OrderStateCallBack
=
(
params
:
BackInfo
&
{
isPay
:
boolean
,
isLimit
?:
boolean
})
=>
void
...
@@ -97,7 +94,6 @@ export type ToPayParams = {
...
@@ -97,7 +94,6 @@ export type ToPayParams = {
/**
/**
* 支付记录id, 采用余额支付的时候如果前端有此值就带过来
* 支付记录id, 采用余额支付的时候如果前端有此值就带过来
*/
*/
payId
?:
number
;
}
}
export
enum
PayError
{
export
enum
PayError
{
...
...
packages/toolkit/src/Payment/Payment.ts
View file @
ed9acb52
...
@@ -6,7 +6,6 @@ import Decimal from 'decimal.js';
...
@@ -6,7 +6,6 @@ import Decimal from 'decimal.js';
import
{
createRequest
,
defaultRequest
,
DefaultResponse
}
from
"@/Request/Request"
;
import
{
createRequest
,
defaultRequest
,
DefaultResponse
}
from
"@/Request/Request"
;
import
{
import
{
BACK_ORDER_ID
,
BACK_ORDER_ID
,
BACK_PAY_ID
,
BackInfo
,
BackInfo
,
DoUnifiedParams
,
DoUnifiedParams
,
FULL_PAY_METHODS
,
FULL_PAY_METHODS
,
...
@@ -190,7 +189,7 @@ export class Payment {
...
@@ -190,7 +189,7 @@ export class Payment {
}
}
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
}
=
params
let
quitUrl
=
params
.
quitUrl
let
quitUrl
=
params
.
quitUrl
// validate start >>>
// validate start >>>
switch
(
payType
)
{
switch
(
payType
)
{
...
@@ -258,7 +257,6 @@ export class Payment {
...
@@ -258,7 +257,6 @@ export class Payment {
quitUrl
,
quitUrl
,
orderId
,
orderId
,
payType
,
payType
,
payId
,
payAmount
,
payAmount
,
payBalance
payBalance
}
}
...
@@ -339,7 +337,7 @@ export class Payment {
...
@@ -339,7 +337,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
=
{
orderId
:
Number
(
query
[
BACK_ORDER_ID
])}
let
timer
:
any
=
null
;
let
timer
:
any
=
null
;
const
checkLoop
=
()
=>
{
const
checkLoop
=
()
=>
{
if
(
--
count
>
0
)
{
if
(
--
count
>
0
)
{
...
@@ -351,10 +349,10 @@ export class Payment {
...
@@ -351,10 +349,10 @@ export class Payment {
timer
&&
clearTimeout
(
timer
)
timer
&&
clearTimeout
(
timer
)
}
}
}
}
if
(
query
[
BACK_
PAY
_ID
])
{
if
(
query
[
BACK_
ORDER
_ID
])
{
try
{
try
{
const
res
=
await
requestForJava
.
post
<
Record
<
string
,
string
>
,
DefaultResponse
>
(
IS_PAY
,
{
const
res
=
await
requestForJava
.
post
<
Record
<
string
,
string
>
,
DefaultResponse
>
(
IS_PAY
,
{
payId
:
query
[
BACK_PAY
_ID
]
orderId
:
query
[
BACK_ORDER
_ID
]
})
})
if
(
res
.
code
===
'200'
&&
res
.
data
===
true
)
{
if
(
res
.
code
===
'200'
&&
res
.
data
===
true
)
{
callBack
({
isPay
:
true
,
...
returnParams
})
callBack
({
isPay
:
true
,
...
returnParams
})
...
@@ -371,13 +369,11 @@ export class Payment {
...
@@ -371,13 +369,11 @@ export class Payment {
/**
/**
* 创建订单查询页面链接, 返回的url不做encode处理
* 创建订单查询页面链接, 返回的url不做encode处理
* @param url
* @param url
* @param backPayId
* @param backOrderId
* @param backOrderId
*/
*/
static
createBackInfoUrl
(
url
:
string
,
back
PayId
:
number
,
back
OrderId
:
number
):
string
{
static
createBackInfoUrl
(
url
:
string
,
backOrderId
:
number
):
string
{
const
[
path
,
queryString
]
=
url
.
split
(
'?'
)
const
[
path
,
queryString
]
=
url
.
split
(
'?'
)
const
query
=
queryString
?
qs
.
parse
(
queryString
,
{
ignoreQueryPrefix
:
true
})
:
{}
const
query
=
queryString
?
qs
.
parse
(
queryString
,
{
ignoreQueryPrefix
:
true
})
:
{}
query
[
BACK_PAY_ID
]
=
backPayId
.
toString
()
query
[
BACK_ORDER_ID
]
=
backOrderId
.
toString
()
query
[
BACK_ORDER_ID
]
=
backOrderId
.
toString
()
return
`
${
path
}
?
${
qs
.
stringify
(
query
)}
`
return
`
${
path
}
?
${
qs
.
stringify
(
query
)}
`
}
}
...
...
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