本文整理汇总了Python中subscriber.Subscriber.get_balance方法的典型用法代码示例。如果您正苦于以下问题:Python Subscriber.get_balance方法的具体用法?Python Subscriber.get_balance怎么用?Python Subscriber.get_balance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subscriber.Subscriber
的用法示例。
在下文中一共展示了Subscriber.get_balance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from subscriber import Subscriber [as 别名]
# 或者: from subscriber.Subscriber import get_balance [as 别名]
def add(self, msisdn, credit):
sub = Subscriber()
sms = SMS();
try:
mysub = sub.get(msisdn)
except SubscriberException as e:
raise CreditException(e)
current_balance = sub.get_balance(msisdn)
new_balance = Decimal(str(credit)) + Decimal(str(current_balance))
# update subscriber balance
try:
cur = db_conn.cursor()
cur.execute('UPDATE subscribers SET balance=%(new_balance)s WHERE msisdn=%(msisdn)s', {'new_balance': Decimal(str(new_balance)), 'msisdn': msisdn})
sms.send(config['smsc'], msisdn, sms_credit_added % (credit, new_balance))
except psycopg2.DatabaseError as e:
raise CreditException('PG_HLR error updating subscriber balance: %s' % e)
# insert transaction into the credit history
try:
cur = db_conn.cursor()
cur.execute('INSERT INTO credit_history(msisdn,previous_balance,current_balance,amount) VALUES(%s,%s,%s,%s)', (msisdn, current_balance, new_balance, credit))
except psycopg2.DatabaseError as e:
db_conn.rollback()
raise CreditException('PG_HLR error inserting invoice in the history: %s' % e)
finally:
db_conn.commit()
示例2: add_subscriber_credit
# 需要导入模块: from subscriber import Subscriber [as 别名]
# 或者: from subscriber.Subscriber import get_balance [as 别名]
def add_subscriber_credit(self, amount):
res_log.info('Add %s to subscriber %s' % (amount, self.subscriber_msisdn))
try:
sub = Subscriber()
from credit import Credit, CreditException
credit = Credit()
res_log.debug('Get current subscriber balance')
current_subscriber_balance = sub.get_balance(self.subscriber_msisdn)
res_log.debug('Current subscriber balance: %s' % current_subscriber_balance)
new_balance = Decimal(str(current_subscriber_balance)) + Decimal(str(amount))
res_log.debug('New balance: %s' % new_balance)
credit.add(self.subscriber_msisdn, amount)
self.subscriber_balance = new_balance
except SubscriberException as e:
raise ResellerException('Error getting subscriber balance: %s' % e)
except CreditException as e:
raise ResellerException('Error adding credit to subscriber: %s' % e)
示例3: bill
# 需要导入模块: from subscriber import Subscriber [as 别名]
# 或者: from subscriber.Subscriber import get_balance [as 别名]
def bill(self, session, subscriber, destination_number, context, duration):
if context == 'LOCAL':
bill_log.info('===========================================================================')
bill_log.info('LOCAL Context')
bleg_connected = session.getVariable('bleg_uuid')
hangup_cause = session.getVariable('hangup_cause')
subscriber = session.getVariable('bleg_destination_number')
#print session.getVariable('bleg_billsec')
configuration = Configuration()
if context == 'OUTBOUND':
bill_log.info('===========================================================================')
bill_log.info('OUTBOUND Context Bill subscriber %s destination %s' % (subscriber, destination_number))
# get rate
rate = self.get_rate(destination_number)
call_cost = self.get_call_cost(duration, rate[3])
# set destination_name and cost for the CDR
session.setVariable('destination_name', rate[1])
session.setVariable('cost', str(call_cost))
bill_log.info('Call duration: %d sec Call cost: %.2f' % (duration, call_cost))
sub = Subscriber()
try:
previous_balance = sub.get_balance(subscriber)
current_balance = previous_balance - call_cost
real_balance = 0 if current_balance < 0 else current_balance
bill_log.info('Previous balance: %.2f Current Balance: %.2f' % (previous_balance, real_balance))
sub.set_balance(subscriber, real_balance)
bill_log.info('Billing %s completed successfully' % subscriber)
except SubscriberException as e:
bill_log.error('Error during billing the subscriber: %s' % e)
if context == 'INBOUND':
bill_log.info('===========================================================================')
bill_log.info('INBOUND Context')
bleg_connected = session.getVariable('bleg_uuid')
hangup_cause = session.getVariable('hangup_cause')
subscriber = session.getVariable('bleg_destination_number')
#print session.getVariable('bleg_billsec')
configuration = Configuration()
if (bleg_connected != '' and bleg_connected != None) and hangup_cause == 'NORMAL_CLEARING':
bill_log.info('Call B-leg was connected. Bill subscriber %s' % subscriber)
try:
charge_info = configuration.get_charge_inbound_calls()
if charge_info[1] == 'call':
bill_log.info('Charge type: per call, Cost: %s' % charge_info[0])
call_cost = charge_info[0]
try:
sub = Subscriber()
previous_balance = sub.get_balance(subscriber)
current_balance = previous_balance - call_cost
bill_log.info('Previous balance: %.2f Current Balance: %.2f' % (previous_balance, current_balance))
sub.set_balance(subscriber, current_balance)
bill_log.info('Billing %s completed successfully' % subscriber)
except SubscriberException as e:
bill_log.error('Error during billing the subscriber: %s' % e)
elif charge_info[1] == 'min':
bill_log.info('Charge type rate per min, cost per min: %s' % charge_info[0])
# BUG: Cannot get b-leg billsec from FS. Use the billsec of a-leg instead
call_cost = self.get_call_cost(duration, charge_info[0])
bill_log.info('Call duration %s sec Call cost: %s' % (duration, call_cost))
try:
sub = Subscriber()
previous_balance = sub.get_balance(subscriber)
current_balance = previous_balance - call_cost
bill_log.info('Previous balance: %.2f Current Balance: %.2f' % (previous_balance, current_balance))
sub.set_balance(subscriber, current_balance)
bill_log.info('Billing %s completed successfully' % subscriber)
except SubscriberException as e:
bill_log.error('Error during billing the subscriber: %s' % e)
except ConfigurationException as e:
bill_log.error(e)
else:
bill_log.info('Call B-leg was not connected. Not billing subscriber %s' % subscriber)