def obj_create(self, bundle, request, **kwargs): form = CreateBillingConfigurationForm(bundle.data) if not form.is_valid(): raise self.form_errors(form) data = form.bango_data create_data = data.copy() create_data['transaction_uuid'] = data.pop('externalTransactionId') try: resp = self.call(form) except BangoError: log.error('Error on createBillingConfiguration, uuid: %s' % (create_data['transaction_uuid'])) create.send(sender=self, bundle=bundle, data=create_data, form=form, status=STATUS_FAILED) raise bundle.data = {'responseCode': resp.responseCode, 'responseMessage': resp.responseMessage, 'billingConfigurationId': resp.billingConfigurationId} log.info('Sending trans uuid %s from Bango config %s' % (create_data['transaction_uuid'], bundle.data['billingConfigurationId'])) create.send(sender=self, bundle=bundle, data=create_data, form=form) return bundle
def obj_create(self, bundle, request, **kwargs): form = CreateBillingConfigurationForm(bundle.data) if not form.is_valid(): raise self.form_errors(form) data = form.bango_data create_data = data.copy() create_data['transaction_uuid'] = data.pop('externalTransactionId') try: resp = self.call(form) except BangoError: log.error('Error on createBillingConfiguration, uuid: %s' % (create_data['transaction_uuid'])) create.send(sender=self, bundle=bundle, data=create_data, form=form, status=STATUS_FAILED) raise bundle.data = { 'responseCode': resp.responseCode, 'responseMessage': resp.responseMessage, 'billingConfigurationId': resp.billingConfigurationId } log.info('Sending trans uuid %s from Bango config %s' % (create_data['transaction_uuid'], bundle.data['billingConfigurationId'])) create.send(sender=self, bundle=bundle, data=create_data, form=form) return bundle
def obj_create(self, bundle, request, **kwargs): form = CreateBillingConfigurationForm(bundle.data) if not form.is_valid(): raise self.form_errors(form) client = get_client() billing = client.client('billing') data = form.bango_data types = billing.factory.create('ArrayOfString') for f in PAYMENT_TYPES: types.string.append(f) data['typeFilter'] = types price_list = billing.factory.create('ArrayOfPrice') for item in form.cleaned_data['prices']: price = billing.factory.create('Price') price.amount = item.cleaned_data['amount'] price.currency = item.cleaned_data['currency'] price_list.Price.append(price) data['priceList'] = price_list config = billing.factory.create('ArrayOfBillingConfigurationOption') configs = { 'APPLICATION_CATEGORY_ID': '18', 'APPLICATION_SIZE_KB': 2, 'BILLING_CONFIGURATION_TIME_OUT': 120, 'REDIRECT_URL_ONSUCCESS': data.pop('redirect_url_onsuccess'), 'REDIRECT_URL_ONERROR': data.pop('redirect_url_onerror'), 'REQUEST_SIGNATURE': sign(data['externalTransactionId']), } for k, v in configs.items(): opt = billing.factory.create('BillingConfigurationOption') opt.configurationOptionName = k opt.configurationOptionValue = v config.BillingConfigurationOption.append(opt) data['configurationOptions'] = config resp = self.client('CreateBillingConfiguration', data) bundle.data = {'responseCode': resp.responseCode, 'responseMessage': resp.responseMessage, 'billingConfigurationId': resp.billingConfigurationId} create_data = data.copy() create_data['transaction_uuid'] = data.pop('externalTransactionId') create.send(sender=self, bundle=bundle, data=create_data, form=form) return bundle
def obj_create(self, bundle, request, **kwargs): form = CreateBillingConfigurationForm(bundle.data) if not form.is_valid(): raise self.form_errors(form) client = get_client() billing = client.client('billing') data = form.bango_data usd_price = None price_list = billing.factory.create('ArrayOfPrice') for item in form.cleaned_data['prices']: price = billing.factory.create('Price') price.amount = item.cleaned_data['amount'] price.currency = item.cleaned_data['currency'] if price.currency == 'USD': usd_price = Decimal(price.amount) price_list.Price.append(price) data['priceList'] = price_list if not usd_price: # This should never happen because USD is always part of the list. raise ValueError('Purchase for %r did not contain a USD price' % data.get('externalTransactionId')) if usd_price < settings.BANGO_MAX_MICRO_AMOUNT: type_filters = MICRO_PAYMENT_TYPES else: type_filters = PAYMENT_TYPES types = billing.factory.create('ArrayOfString') for f in type_filters: types.string.append(f) data['typeFilter'] = types config = billing.factory.create('ArrayOfBillingConfigurationOption') configs = { 'APPLICATION_CATEGORY_ID': '18', 'APPLICATION_SIZE_KB': 2, 'BILLING_CONFIGURATION_TIME_OUT': 120, 'REDIRECT_URL_ONSUCCESS': data.pop('redirect_url_onsuccess'), 'REDIRECT_URL_ONERROR': data.pop('redirect_url_onerror'), 'REQUEST_SIGNATURE': sign(data['externalTransactionId']), } if settings.BANGO_ICON_URLS: icon_url = data.pop('icon_url', None) if icon_url: configs['APPLICATION_LOGO_URL'] = icon_url for k, v in configs.items(): opt = billing.factory.create('BillingConfigurationOption') opt.configurationOptionName = k opt.configurationOptionValue = v config.BillingConfigurationOption.append(opt) data['configurationOptions'] = config resp = self.client('CreateBillingConfiguration', data) bundle.data = {'responseCode': resp.responseCode, 'responseMessage': resp.responseMessage, 'billingConfigurationId': resp.billingConfigurationId} create_data = data.copy() create_data['transaction_uuid'] = data.pop('externalTransactionId') create.send(sender=self, bundle=bundle, data=create_data, form=form) return bundle