Ejemplo n.º 1
0
    def cco_charge(self):
        self._cco_charge = CCOProfile(
            brand_id=self._cco['brand_id'],
            partner_id=self._cco['partner_id'],
            product_id=self._cco['product_id'],
            application_id=self._cco['application_id'],
            is_sync=self._cco['is_sync'],
            username=self._cco['username'],
            password=self._cco['password'],
            url=self._cco['url']
        )

        self.msisdn = self._cco['destination']['msisdn']
        self.subscription_id = self._cco['destination']['id']

        self._logger.info('[%s] Charging Brand %s; ANI: %s; Product ID: %s' % (
            self._cco['charge_id'], self._cco['brand_id'], self.msisdn,
            self._cco['product_id']))

        start_time = time()
        self._cco_result = self._cco_charge.charge(self.msisdn,
            self.subscription_id)
        request_lenght = time() - start_time

        self._logger.info('[%s] Charge request time: [%.2fs]; %s Resp: %s' % (
            self._cco['charge_id'], request_lenght, self._cco['brand_id'],
            self._cco_result['response']))
Ejemplo n.º 2
0
class CollectorProcess(object):

    def __init__(self, *args, **kwargs):
        self._logger = kwargs['logger']
        self._rabbit_cfg = kwargs['rabbit_cfg']
        self._rabbit_sc_cfg = kwargs['rabbit_sc_cfg']
        self._dispatch_info = kwargs['dispatch_info']
        self._cco = kwargs['cco_profile']
        self._notification = kwargs.get('notification', None)
        self._dispatch_content = kwargs.get('dispatch_content', None)

    def cco_charge(self):
        self._cco_charge = CCOProfile(
            brand_id=self._cco['brand_id'],
            partner_id=self._cco['partner_id'],
            product_id=self._cco['product_id'],
            application_id=self._cco['application_id'],
            is_sync=self._cco['is_sync'],
            username=self._cco['username'],
            password=self._cco['password'],
            url=self._cco['url']
        )

        self.msisdn = self._cco['destination']['msisdn']
        self.subscription_id = self._cco['destination']['id']

        self._logger.info('[%s] Charging Brand %s; ANI: %s; Product ID: %s' % (
            self._cco['charge_id'], self._cco['brand_id'], self.msisdn,
            self._cco['product_id']))

        start_time = time()
        self._cco_result = self._cco_charge.charge(self.msisdn,
            self.subscription_id)
        request_lenght = time() - start_time

        self._logger.info('[%s] Charge request time: [%.2fs]; %s Resp: %s' % (
            self._cco['charge_id'], request_lenght, self._cco['brand_id'],
            self._cco_result['response']))

    def report_charge(self):
        try:
            data = msgpack.dumps({
                'charge_id': self._cco['charge_id'],
                'cco_transaction_id': self._cco_result['transaction'],
                'cco_response': self._cco_result['response'],
                'cco_ws_response_date': datetime.utcnow().strftime(
                    '%Y-%m-%d %H:%M:%S')
            })

            rabbit = RabbitHandler(**self._rabbit_sc_cfg)
            rabbit.put(data=data, exchange='x', routing_key='charesp')
            rabbit.disconnect()

        except Exception, e:
            self._logger.exception('[%s] Error on make report.' % (
                self._cco['charge_id']))