Commit b669e734 by zhengxiao

feat: modify any

parent 73a41446
...@@ -28,7 +28,7 @@ const requestForJava = defaultRequest ...@@ -28,7 +28,7 @@ const requestForJava = defaultRequest
export class Payment { export class Payment {
balance = 0; balance = 0;
limitPayChannels: PayChannel[] = []; limitPayChannels: PayChannel[] = [];
isEnabledCombinationPay: boolean = true; // 配置的是否开组合支付 isEnabledCombinationPay: boolean = true; // 配置的是否开组合支付
supportCombination: boolean = true; // 余额开关的改变是否支持组合支付 supportCombination: boolean = true; // 余额开关的改变是否支持组合支付
constructor(paymentParams?: PaymentParams) { constructor(paymentParams?: PaymentParams) {
this.limitPayChannels = paymentParams?.payChannels ?? Object.keys(PayChannel).map(key => key) as PayChannel[]; this.limitPayChannels = paymentParams?.payChannels ?? Object.keys(PayChannel).map(key => key) as PayChannel[];
...@@ -41,10 +41,12 @@ export class Payment { ...@@ -41,10 +41,12 @@ export class Payment {
} }
} }
// 原型方法设置是否支持组合支付
setIsSupportCombination (value: boolean) { setIsSupportCombination (value: boolean) {
this.supportCombination = value this.supportCombination = value
} }
// 获取余额
getBalance() { getBalance() {
return new Promise<number|null>(async (resolve, reject) =>{ return new Promise<number|null>(async (resolve, reject) =>{
try { try {
...@@ -83,6 +85,7 @@ export class Payment { ...@@ -83,6 +85,7 @@ export class Payment {
}) })
} }
// 获取支付方式列表
getPayMethodList (totalAmount:number, doctorId?:string, orderId?:string) { getPayMethodList (totalAmount:number, doctorId?:string, orderId?:string) {
// 计算支付方式列表 // 计算支付方式列表
const List = this.supportCombination ? this.getPayMethodListForCombination(totalAmount) : this.getPayMethodListForNotCombination(totalAmount) const List = this.supportCombination ? this.getPayMethodListForCombination(totalAmount) : this.getPayMethodListForNotCombination(totalAmount)
...@@ -102,6 +105,7 @@ export class Payment { ...@@ -102,6 +105,7 @@ export class Payment {
}) })
} }
// 不支持组合支付的情况下获取支付方式列表
private getPayMethodListForNotCombination(totalAmount: number): PayMethod[] { private getPayMethodListForNotCombination(totalAmount: number): PayMethod[] {
return FULL_PAY_METHODS.filter(({value}) => { return FULL_PAY_METHODS.filter(({value}) => {
switch (value) { switch (value) {
...@@ -133,6 +137,8 @@ export class Payment { ...@@ -133,6 +137,8 @@ export class Payment {
return item return item
}) })
} }
// 支持组合支付的情况下获取支付方式列表
private getPayMethodListForCombination(totalAmount: number): PayMethod[] { private getPayMethodListForCombination(totalAmount: number): PayMethod[] {
return FULL_PAY_METHODS.filter(({value}) => { return FULL_PAY_METHODS.filter(({value}) => {
switch (value) { switch (value) {
...@@ -164,6 +170,7 @@ export class Payment { ...@@ -164,6 +170,7 @@ export class Payment {
}) })
} }
// 计算非组合支付金额
computeAmount(totalAmount: number, payType: PayType): { payAmount: number, payBalance: number } { computeAmount(totalAmount: number, payType: PayType): { payAmount: number, payBalance: number } {
let payBalance = 0, payAmount = 0 let payBalance = 0, payAmount = 0
if(payType == PayType.BALANCE){ if(payType == PayType.BALANCE){
...@@ -177,6 +184,7 @@ export class Payment { ...@@ -177,6 +184,7 @@ export class Payment {
return {payAmount, payBalance} return {payAmount, payBalance}
} }
// 计算组合支付金额
computeAmountForCombination(totalAmount: number, balance: number = 0): { payAmount: number, payBalance: number } { computeAmountForCombination(totalAmount: number, balance: number = 0): { payAmount: number, payBalance: number } {
console.log("🚀 ~ file: Payment.ts:171 ~ Payment ~ computeAmountForCombination ~ balance:", balance) console.log("🚀 ~ file: Payment.ts:171 ~ Payment ~ computeAmountForCombination ~ balance:", balance)
let payBalance = 0, payAmount = 0 let payBalance = 0, payAmount = 0
...@@ -193,6 +201,7 @@ export class Payment { ...@@ -193,6 +201,7 @@ export class Payment {
return {payAmount, payBalance} return {payAmount, payBalance}
} }
// 去支付
async toPay(params: ToPayParams): Promise<ToPayReturns> { async toPay(params: ToPayParams): Promise<ToPayReturns> {
console.log("🚀 ~ file: Payment.ts:179 ~ Payment ~ toPay ~ params:", params) console.log("🚀 ~ file: Payment.ts:179 ~ Payment ~ toPay ~ params:", params)
const {totalAmount, payType, returnUrl, orderId, subOrderIds, redirectUrl} = params const {totalAmount, payType, returnUrl, orderId, subOrderIds, redirectUrl} = params
...@@ -341,6 +350,7 @@ export class Payment { ...@@ -341,6 +350,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}) : {}
......
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