Commit c8945665 by 许振钊

Merge branch 'feat_balance_0403' into 'master'

feat: 余额请求能力透出

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