def get_rate_response(self):
        gateway = self.data.get('gateway')
        try:
            backend_api_id = SQLMobileBackend.get_backend_api_id(gateway, is_couch_id=True)
        except Exception as e:
            log_smsbillables_error(
                "Failed to get backend for calculating an sms rate due to: %s"
                % e
            )
            raise SMSRateCalculatorError("Could not obtain connection information.")

        country_code = self.data.get('country_code')
        if country_code == NONMATCHING_COUNTRY:
            country_code = None
        direction = self.data.get('direction')

        gateway_fee = SmsGatewayFee.get_by_criteria(
            backend_api_id, direction, backend_instance=gateway,
            country_code=country_code,
        )
        usage_fee = SmsUsageFee.get_by_criteria(direction, self.request.domain)
        usd_gateway_fee = gateway_fee.amount / gateway_fee.currency.rate_to_default
        usd_total = usage_fee.amount + usd_gateway_fee

        return {
            'rate': _("%s per 160 character SMS") % fmt_dollar_amount(usd_total),
        }
    def get_rate_response(self):
        gateway = self.data.get('gateway')
        try:
            backend = SMSBackend.get(gateway)
            backend_api_id = get_backend_by_class_name(
                backend.doc_type).get_api_id()
        except Exception as e:
            logger.error("Failed to get backend for calculating an sms rate "
                         "due to: %s" % e)
            raise SMSRateCalculatorError(
                "Could not obtain connection information.")

        country_code = self.data.get('country_code')
        if country_code == NONMATCHING_COUNTRY:
            country_code = None
        direction = self.data.get('direction')

        gateway_fee = SmsGatewayFee.get_by_criteria(
            backend_api_id,
            direction,
            backend_instance=gateway,
            country_code=country_code,
        )
        usage_fee = SmsUsageFee.get_by_criteria(direction, self.request.domain)
        usd_gateway_fee = gateway_fee.amount * gateway_fee.currency.rate_to_default
        usd_total = usage_fee.amount + usd_gateway_fee

        return {
            'rate':
            _("%s per 160 character SMS") % fmt_dollar_amount(usd_total),
        }
Exemple #3
0
 def _directed_fee(direction, backend_api_id, backend_instance_id):
     gateway_fee = SmsGatewayFee.get_by_criteria(
         backend_api_id, direction, backend_instance=backend_instance_id, country_code=country_code
     )
     if not gateway_fee or gateway_fee.amount is None:
         return None
     usd_gateway_fee = gateway_fee.amount / gateway_fee.currency.rate_to_default
     usage_fee = SmsUsageFee.get_by_criteria(direction)
     return fmt_dollar_amount(usage_fee.amount + usd_gateway_fee)
Exemple #4
0
 def _directed_fee(direction, backend_api_id, backend_instance_id):
     gateway_fee = SmsGatewayFee.get_by_criteria(
         backend_api_id,
         direction,
         backend_instance=backend_instance_id,
         country_code=country_code)
     if not gateway_fee or gateway_fee.amount is None:
         return None
     usd_gateway_fee = gateway_fee.amount / gateway_fee.currency.rate_to_default
     usage_fee = SmsUsageFee.get_by_criteria(direction)
     return fmt_dollar_amount(usage_fee.amount + usd_gateway_fee)