当前位置: 首页>>代码示例>>Python>>正文


Python Subscriber.set_balance方法代码示例

本文整理汇总了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)
开发者ID:ciaby,项目名称:rccn,代码行数:79,代码来源:billing.py


注:本文中的subscriber.Subscriber.set_balance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。