def handle(self, *args, **options): SmsGatewayFee.create_new(TropoBackend.get_api_id(), INCOMING, 0.01) rates_csv = open('corehq/apps/smsbillables/management/' 'pricing_data/tropo_international_rates_2013-12-19.csv', 'r') for line in rates_csv.readlines(): data = line.split(',') if data[1] == 'Fixed Line' and data[4] != '\n': SmsGatewayFee.create_new(TropoBackend.get_api_id(), OUTGOING, float(data[4].rstrip()), country_code=int(data[2])) rates_csv.close() print "Updated Tropo gateway fees."
def bootstrap_tropo_gateway(orm): currency = (orm['accounting.Currency'] if orm else Currency).objects.get( code="USD") sms_gateway_fee_class = orm[ 'smsbillables.SmsGatewayFee'] if orm else SmsGatewayFee sms_gateway_fee_criteria_class = orm[ 'smsbillables.SmsGatewayFeeCriteria'] if orm else SmsGatewayFeeCriteria SmsGatewayFee.create_new( TropoBackend.get_api_id(), INCOMING, 0.01, currency=currency, fee_class=sms_gateway_fee_class, criteria_class=sms_gateway_fee_criteria_class, ) rates_csv = open( 'corehq/apps/smsbillables/management/' 'pricing_data/tropo_international_rates_2013-12-19.csv', 'r') for line in rates_csv.readlines(): data = line.split(',') if data[1] == 'Fixed Line' and data[4] != '\n': SmsGatewayFee.create_new( TropoBackend.get_api_id(), OUTGOING, float(data[4].rstrip()), country_code=int(data[2]), currency=currency, fee_class=sms_gateway_fee_class, criteria_class=sms_gateway_fee_criteria_class, ) rates_csv.close() # Fee for invalid phonenumber SmsGatewayFee.create_new( TropoBackend.get_api_id(), OUTGOING, 0.01, country_code=None, currency=currency, fee_class=sms_gateway_fee_class, criteria_class=sms_gateway_fee_criteria_class, ) logger.info("Updated Tropo gateway fees.")
def handle(self, *args, **options): SmsGatewayFee.create_new(TropoBackend.get_api_id(), INCOMING, 0.01) rates_csv = open( 'corehq/apps/smsbillables/management/' 'pricing_data/tropo_international_rates_2013-12-19.csv', 'r') for line in rates_csv.readlines(): data = line.split(',') if data[1] == 'Fixed Line' and data[4] != '\n': SmsGatewayFee.create_new(TropoBackend.get_api_id(), OUTGOING, float(data[4].rstrip()), country_code=int(data[2])) rates_csv.close() # Fee for invalid phonenumber SmsGatewayFee.create_new(TropoBackend.get_api_id(), OUTGOING, 0.01, country_code=None) logger.info("Updated Tropo gateway fees.")
def testIncomingTropoApi(self): logging.info("\n\n[Billing] Tropo: Incoming SMS Test") self.assertEqual(self.tropo_rate_incoming.conversion_rate, self.usd_rate.conversion) # fake_post = {InboundParams.SENDER: str(self.tropo_couch_user.phone_number), # InboundParams.MESSAGE: self.test_message, # InboundParams.TIMESTAMP: datetime.datetime.now().strftime(DATE_FORMAT), # InboundParams.DCS: '8', # InboundParams.UDHI: '0'} # # class FakeRequest(object): # # HACK # params = {} # @property # def REQUEST(self): # return self.params # # req = FakeRequest() # req.params = fake_post log = create_incoming_msg(str(self.tropo_couch_user.phone_number), self.test_message, TropoBackend.get_api_id(), delay=False) billable_items = TropoSMSBillable.by_domain_and_direction(self.domain, INCOMING) if billable_items: billable_item = billable_items[0] self.assertEqual(self.tropo_rate_incoming.base_fee, billable_item.billable_amount) self.assertEqual(self.tropo_rate_incoming._id, billable_item.rate_id) self.assertEqual(log._id, billable_item.log_id) self.assertEqual(self.tropo_rate_incoming.conversion_rate, billable_item.conversion_rate) self.assertEqual(self.dimagi_surcharge_I.base_fee, billable_item.dimagi_surcharge) self.assertEqual(INCOMING_MSG_ID, billable_item.tropo_id) if billable_item.has_error: raise Exception("There were recorded errors creating an incoming Tropo billing rate: %s" % billable_item.error_message) else: raise Exception("There were unknown errors creating an incoming Tropo billing rate!")
continue mach_number = MachPhoneNumber.get_by_number(message.phone_number, mach_row) rate_item = MachSMSRate.get_by_number(message.direction, mach_number) if mach_number else None billable = cls.new_billable(rate_item, message) if billable: billable.contacted_mach_api = datetime.datetime.now(tz=pytz.utc) billable.update_mach_delivery_status(mach_row) billable.save() return logging.error("[Billing] MACH API Response was successful, but creating the MACH " "billable was not. SMSLog # %s" % message.get_id) else: logging.error("[Billing] There was an error retrieving message delivery information from MACH.") else: logging.error("[Billing] There was an error accessing the MACHI API.") else: logging.error("[Billing] There was an error while trying to send an SMS via MACH.") @staticmethod def api_name(): return "Mach" API_TO_BILLABLE = { UnicelBackend.get_api_id(): UnicelSMSBillable, TropoBackend.get_api_id(): TropoSMSBillable, MachBackend.get_api_id(): MachSMSBillable, }