Commit 75f5184d by Ron

Merge branch 'master' into fix_WX_browser_20230403

merge
parents e5f13bf3 c8945665
{ {
"name": "@ydl-packages/toolkit", "name": "@ydl-packages/toolkit",
"version": "1.0.8", "version": "1.0.8-beta.2",
"description": "", "description": "",
"main": "./dist/index.umd.js", "main": "./dist/index.umd.js",
"scripts": { "scripts": {
......
...@@ -126,6 +126,13 @@ export type ToPayReturns = { ...@@ -126,6 +126,13 @@ export type ToPayReturns = {
payUrl?: string payUrl?: string
} }
export type BalanceReturns = {
success: boolean
code?: number
msg?: string
}
export interface DoUnifiedParams extends Omit<ToPayParams, 'totalAmount' | 'redirectUrl'> { export interface DoUnifiedParams extends Omit<ToPayParams, 'totalAmount' | 'redirectUrl'> {
payChannel?: PayChannel, payChannel?: PayChannel,
payBalance: number, payBalance: number,
......
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
PayType, PayType,
ToPayParams, ToPayParams,
ToPayReturns, ToPayReturns,
BalanceReturns,
WechatPayParams WechatPayParams
} from "./Defined"; } from "./Defined";
import {ACCESS_TOKEN, UID} from "@/Const"; import {ACCESS_TOKEN, UID} from "@/Const";
...@@ -89,15 +90,21 @@ export class Payment { ...@@ -89,15 +90,21 @@ export class Payment {
} }
} }
async getBalance(): Promise<number> { //isHandleErr 是否要自定义处理异常
async getBalance(handleErr: (err: BalanceReturns) =>void): Promise<number|null> {
try { try {
const {data: res} = await requestForPhp.post(MY_BALANCE, {balance: 1}) const {data: res} = await requestForPhp.post(MY_BALANCE, {balance: 1})
if (res.data && res.data.balance) { if (res.data && res.data.balance) {
this.balance = Number(res.data.balance) this.balance = Number(res.data.balance)
} }
if(handleErr && res.msg !== 'success'){
handleErr && handleErr(res)
return null
}
return this.balance return this.balance
} catch (err) { } catch (err) {
return 0 handleErr && handleErr({success: false})
return !!handleErr ? null : 0
} }
} }
getPayMethodList (totalAmount:number) { getPayMethodList (totalAmount:number) {
......
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