import {
|
BlLifeRechargeServices,
|
PhoneMesssageCodeLoginInput,
|
RequestConfig,
|
} from './lifeRechargeServices';
|
import { BlLifeRechargeOptions } from './types';
|
import { LifeRechargeConstants } from './lifeRechargeConstants';
|
import { BlLifeRechargeAccountModel } from './lifeRechargeAccountModel';
|
|
export class BlLifeRecharge<TResponse = any, TRequestOptions = any> {
|
services: BlLifeRechargeServices<TResponse, TRequestOptions>;
|
accountModel: BlLifeRechargeAccountModel;
|
|
static constants = LifeRechargeConstants;
|
constants = LifeRechargeConstants;
|
|
constructor(options: BlLifeRechargeOptions<TResponse, TRequestOptions>) {
|
this.services = new BlLifeRechargeServices(options);
|
this.accountModel = new BlLifeRechargeAccountModel({
|
userId: options.userId,
|
phoneNumber: options.phoneNumber,
|
});
|
}
|
|
async login(body: PhoneMesssageCodeLoginInput, options?: RequestConfig) {
|
try {
|
let res = await this.services.lifePayPhoneMesssageCodeLogin(body, options);
|
this.accountModel.setUserId(res);
|
this.accountModel.setPhoneNumber(body.phoneNumber);
|
return res;
|
} catch (error) {
|
throw new Error(error);
|
}
|
}
|
|
loginout() {
|
this.accountModel.setUserId('');
|
this.accountModel.setPhoneNumber('');
|
}
|
|
isLogin() {
|
return !!this.accountModel.userId;
|
}
|
|
getRechargeParValue(amount: number | string, rate: number) {
|
return (Number(amount) * rate).toFixed(2);
|
}
|
|
MaxParValue = 300;
|
|
filterParValueList(parValueList: string[]) {
|
return parValueList.filter((x) => Number(x) <= this.MaxParValue);
|
}
|
}
|