本文整理汇总了Python中subscriber.Subscriber.set_balance方法的典型用法代码示例。如果您正苦于以下问题:Python Subscriber.set_balance方法的具体用法?Python Subscriber.set_balance怎么用?Python Subscriber.set_balance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subscriber.Subscriber
的用法示例。
在下文中一共展示了Subscriber.set_balance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bill
# 需要导入模块: from subscriber import Subscriber [as 别名]
# 或者: from subscriber.Subscriber import set_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)