Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
    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()
Esempio n. 4
0
    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
Esempio n. 5
0
    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
Esempio n. 6
0
    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()
Esempio n. 7
0
    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