def get_balance(account): with HydraConnection() as conn: user_id, account_id = conn.get_account_by_ls(account) balance = conn.get_balance(account_id) servs = conn.get_all_servs(user_id, account_id) recommended = conn.get_recommended_pay(user_id) return balance, servs, recommended
def set_promised_payment(account, login=None, password=None): error_code, error = 0, u'' with HydraConnection() as conn: user_id, account_id = conn.get_account_by_ls(account) if login is None: login, password = conn.get_lk_login_pass(user_id) if login is None or password is None or len(login) == 0: return 1002, u"Ошибка авторизации" log(u'set_payment: account %s, login %s, password %s, user_id %s' % (account, login, password, str(user_id))) conn.main_init(login, password) recommended = conn.get_recommended_pay(user_id) if abs(recommended) > 1e-9: conn.set_promised_payment(account_id) recommended = conn.get_recommended_pay(user_id) if abs(recommended) > 1e-9: error_code, error = 1001, u"Ошибка установки обещанного платежа" # не смогли установить обещанный платёж else: error_code, error = 1000, u"Обещанный платёж не требуется" # не можем установить обещанный платёж return error_code, error
def set_promised_payment(account, login=None, password=None): error_code, error = 0, u'' with HydraConnection() as conn: user_id, account_id = conn.get_account_by_ls(account) try: conn.init_session(user_id) except HydraAdapterError: return 1002, u"Ошибка авторизации" log(u'set_payment: account %s, login %s, password %s, user_id %s' % (account, login, password, str(user_id))) conn.main_init(login, password) recommended = conn.get_recommended_pay(user_id) if abs(recommended) > 1e-9: conn.set_promised_payment(account_id) recommended = conn.get_recommended_pay(user_id) if abs(recommended) > 1e-9: # не смогли установить обещанный платёж error_code, error = 1001, u"Ошибка установки обещанного платежа" else: # нет причин для установки обещанного платежа, рекомендуемый платёж не больше нуля error_code, error = 1000, u"Обещанный платёж не требуется" return error_code, error
def add_tariff(account, tariff_id): """ Получаем список тарифов, добавляем первый тариф из биллинга, который соответствует тарифу, перезаписываем, если список изменился """ error = 0 # tariff_id = adapter_utils.get_any_billing_tariff(tariff_id, settings.tariffs) if tariff_id == -1: error = 1010 else: with HydraConnection() as conn: goods = conn.get_goods(account) tariff_list, parent_sub_id = filter_goods(goods) if parent_sub_id is None: main_goods = conn.get_main_goods(account) l, parent_sub_id = filter_goods(main_goods) if parent_sub_id is not None: if tariff_id not in tariff_list: tariff_list.append(tariff_id) user_id, account_id = conn.get_account_by_ls(account) conn.init_session(user_id) conn.overwrite_subscriptions(account, tariff_list, parent_sub_id) else: error = 1004 return error
def remove_tariff(account, tariff_id): """ Получаем список тарифов, убираем из списка все, соответствующе переданному тарифу, перезаписываем список, если он изменился """ error = 0 # removing_list = adapter_utils.get_all_billing_tariffs(tariff_id, settings.tariffs) if tariff_id == -1: error = 1010 else: with HydraConnection() as conn: goods = conn.get_goods(account) tariff_list, parent_sub_id = filter_goods(goods) if parent_sub_id is None: main_goods = conn.get_main_goods(account) l, parent_sub_id = filter_goods(main_goods) if parent_sub_id is not None: if tariff_id in tariff_list: tariff_list.remove(tariff_id) user_id, account_id = conn.get_account_by_ls(account) conn.init_session(user_id) conn.overwrite_subscriptions(account, tariff_list, parent_sub_id) else: error = 1004 return error
def check_login_pass(account, user, password): error = 0 with HydraConnection() as conn: user_id, account_id = conn.get_account_by_ls(account) user = conn.get_user_by_login_pass(user, password) if user_id != user: error = 1000 return error
def add_device(account, mac, serial): with HydraConnection() as conn: user_id, account_id = conn.get_account_by_ls(account) check_code = check_device(conn, user_id, serial, mac) if check_code == 1: raise HydraAdapterError(u'Устройство не найдено', 1010) if check_code == 2: raise HydraAdapterError(u'Превышен лимит устройств', 1011) conn.set_mac_and_serial(user_id, mac, serial)
def add_device(account, mac, serial): with HydraConnection() as conn: user_id, account_id = conn.get_account_by_ls(account) conn.set_mac_and_serial(user_id, mac, serial)
def set_mac_close_date(mac, account): with HydraConnection() as conn: user_id, account_id = conn.get_account_by_ls(account) conn.set_mac_close_date(user_id, mac)
def load_service_list_from_db(account): with HydraConnection() as conn: user_id, account_id = conn.get_account_by_ls(account) conn.init_session(user_id) return conn.get_goods(account)