Commit ed9acb52 by 郑炬波

feat: 去payId

parent 332f2f17
......@@ -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)
return res.data
}
......
......@@ -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)
return res.data
}
......
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('测试: 创建实例', () => {
test('supportCombination', () => {
......@@ -38,12 +38,9 @@ describe('测试: 创建实例', () => {
})
test('测试订单查询链接', () => {
const testPayId = 111
const testOrderId = 222
const backUrl = Payment.createBackInfoUrl(window.location.href, testPayId, testOrderId)
expect(backUrl).toContain(BACK_PAY_ID)
const backUrl = Payment.createBackInfoUrl(window.location.href, testOrderId)
expect(backUrl).toContain(BACK_ORDER_ID)
expect(backUrl).toContain(testPayId.toString())
expect(backUrl).toContain(testOrderId.toString())
expect(backUrl).toContain(window.location.origin)
})
......
{
"name": "@ydl-packages/toolkit",
"version": "1.0.1-next.33",
"version": "1.0.3-next.3",
"description": "",
"main": "./dist/index.umd.js",
"scripts": {
......
......@@ -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 IS_PAY = `${BASE_URL_JAVA}/api/auth/Order/isPay`
export const IS_PAY = `${BASE_URL_JAVA}/api/auth/Order/orderIsPay`
export const MY_BALANCE = `${BASE_GATEWAY}/v3/uc/mybalance`
......
......@@ -5,13 +5,10 @@ export type PayMethod = {
disabled: boolean
}
export const BACK_PAY_ID = 'backPayId'
export const BACK_ORDER_ID = 'backOrderId'
export type BackInfo = {
orderId: number;
payId: number
}
export type OrderStateCallBack = (params: BackInfo & { isPay: boolean, isLimit?: boolean }) => void
......@@ -97,7 +94,6 @@ export type ToPayParams = {
/**
* 支付记录id, 采用余额支付的时候如果前端有此值就带过来
*/
payId?: number;
}
export enum PayError {
......
......@@ -6,7 +6,6 @@ import Decimal from 'decimal.js';
import {createRequest, defaultRequest, DefaultResponse} from "@/Request/Request";
import {
BACK_ORDER_ID,
BACK_PAY_ID,
BackInfo,
DoUnifiedParams,
FULL_PAY_METHODS,
......@@ -190,7 +189,7 @@ export class Payment {
}
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
// validate start >>>
switch (payType) {
......@@ -258,7 +257,6 @@ export class Payment {
quitUrl,
orderId,
payType,
payId,
payAmount,
payBalance
}
......@@ -339,7 +337,7 @@ export class Payment {
static async loopValidateOrderState(count = 0, callBack: OrderStateCallBack, pollTime = 3000): Promise<void> {
const [, queryString] = window.location.href.split('?')
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;
const checkLoop = () => {
if (--count > 0) {
......@@ -351,10 +349,10 @@ export class Payment {
timer && clearTimeout(timer)
}
}
if (query[BACK_PAY_ID]) {
if (query[BACK_ORDER_ID]) {
try {
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) {
callBack({isPay: true, ...returnParams})
......@@ -371,13 +369,11 @@ export class Payment {
/**
* 创建订单查询页面链接, 返回的url不做encode处理
* @param url
* @param backPayId
* @param backOrderId
*/
static createBackInfoUrl(url: string, backPayId: number, backOrderId: number): string {
static createBackInfoUrl(url: string, backOrderId: number): string {
const [path, queryString] = url.split('?')
const query = queryString ? qs.parse(queryString, {ignoreQueryPrefix: true}) : {}
query[BACK_PAY_ID] = backPayId.toString()
query[BACK_ORDER_ID] = backOrderId.toString()
return `${path}?${qs.stringify(query)}`
}
......
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