def check_bango(self, obj): pk = obj.seller_product_bango.pk form = CreateBillingConfigurationForm({ 'seller_product_bango': ( self.get_serializer().fields['seller_product_bango'] .to_native(obj.seller_product_bango)), 'pageTitle': 'Test of app status', 'prices': [{'price': 0.99, 'currency': 'USD', 'method': PAYMENT_METHOD_ALL}], 'redirect_url_onerror': 'http://test.mozilla.com/error', 'redirect_url_onsuccess': 'http://test.mozilla.com/success', 'transaction_uuid': 'test:status:{0}'.format(uuid.uuid4()), 'user_uuid': 'test:user:{0}'.format(uuid.uuid4()) }) if not form.is_valid(): log.info('Form not valid: {0}'.format(pk)) obj.status = STATUS_BAD obj.errors = json.dumps({'form.errors': form.errors}) obj.save() raise ParseError resource = CreateBillingConfigurationResource() try: resource.call(form) except ImmediateHttpResponse, exc: log.info('Bango error: {0}'.format(pk)) obj.status = STATUS_BAD obj.errors = exc.response.content obj.save() return
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 check_bango(self, obj): view = BangoResource() pk = obj.seller_product_bango.pk form = CreateBillingConfigurationForm({ 'seller_product_bango': (self.get_serializer().fields['seller_product_bango'].to_native( obj.seller_product_bango)), 'pageTitle': 'Test of app status', 'prices': [{ 'price': 0.99, 'currency': 'USD', 'method': PAYMENT_METHOD_ALL }], 'redirect_url_onerror': 'http://test.mozilla.com/error', 'redirect_url_onsuccess': 'http://test.mozilla.com/success', 'transaction_uuid': 'test:status:{0}'.format(uuid.uuid4()), 'user_uuid': 'test:user:{0}'.format(uuid.uuid4()) }) if not form.is_valid(): log.info('Form not valid: {0}'.format(pk)) raise ParseError try: data = prepare(form, obj.seller_product_bango.bango_id) view.client('CreateBillingConfiguration', data) except BangoImmediateError: # Cause the information about this record to be saved # by not raising an error. log.info('Bango error in check status: {0}'.format(pk)) obj.status = STATUS_BAD obj.save() return log.info('All good: {0}'.format(pk)) obj.status = STATUS_GOOD obj.save()