Exemple #1
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()
Exemple #2
0
def billing(request):
    """
    Call the Bango API to begin a payment transaction.

    The resulting billingConfigId can be used on the query
    string in a URL to initiate a user payment flow.

    We are able to configure a few parameters that come
    back to us on the Bango success URL query string.
    Here are some highlights:

    **config[REQUEST_SIGNATURE]**
        This arrives as **MozSignature** in the redirect query string.

    **externalTransactionId**
        This is set to solitude's own transaction_uuid. It arrives
        in the redirect query string as **MerchantTransactionId**.
    """

    view = BangoResource()
    try:
        serial, form = view.process(
            serial_class=SellerProductBangoOnly,
            form_class=CreateBillingConfigurationForm,
            request=request)
    except ProcessError, exc:
        return exc.response
Exemple #3
0
def billing(request):
    """
    Call the Bango API to begin a payment transaction.

    The resulting billingConfigId can be used on the query
    string in a URL to initiate a user payment flow.

    We are able to configure a few parameters that come
    back to us on the Bango success URL query string.
    Here are some highlights:

    **config[REQUEST_SIGNATURE]**
        This arrives as **MozSignature** in the redirect query string.

    **externalTransactionId**
        This is set to solitude's own transaction_uuid. It arrives
        in the redirect query string as **MerchantTransactionId**.
    """

    view = BangoResource()
    try:
        serial, form = view.process(serial_class=SellerProductBangoOnly,
                                    form_class=CreateBillingConfigurationForm,
                                    request=request)
    except ProcessError, exc:
        return exc.response
Exemple #4
0
def rating(request):
    view = BangoResource()
    view.error_lookup = {
        'INVALID_RATING': 'rating',
        'INVALID_RATING_SCHEME': 'ratingScheme',
    }
    try:
        serial, form = view.process(serial_class=SellerProductBangoOnly,
                                    form_class=UpdateRatingForm,
                                    request=request)
    except ProcessError, exc:
        return exc.response
Exemple #5
0
def bank(request):
    view = BangoResource()
    view.error_lookup = {
        'INVALID_COUNTRYISO': 'bankAddressIso',
    }

    try:
        serial, form = view.process(
            serial_class=SellerBangoOnly,
            form_class=CreateBankDetailsForm,
            request=request)
    except ProcessError, exc:
        return exc.response
Exemple #6
0
def rating(request):
    view = BangoResource()
    view.error_lookup = {
        'INVALID_RATING': 'rating',
        'INVALID_RATING_SCHEME': 'ratingScheme',
    }
    try:
        serial, form = view.process(
            serial_class=SellerProductBangoOnly,
            form_class=UpdateRatingForm,
            request=request)
    except ProcessError, exc:
        return exc.response
Exemple #7
0
def premium(request):
    view = BangoResource()
    view.error_lookup = {
        'INVALID_COUNTRYISO': 'currencyIso',
    }

    try:
        serial, form = view.process(
            serial_class=SellerProductBangoOnly,
            form_class=MakePremiumForm,
            request=request)
    except ProcessError, exc:
        return exc.response
Exemple #8
0
def notification(request):
    view = BangoResource()
    form = NotificationForm(request, request.DATA)

    bill_conf_id = form.data.get('billing_config_id')
    log.info('Received notification for billing_config_id %r: '
             'bango_response_code: %r; bango_response_message: %r; '
             'bango_trans_id: %r; bango_token: %r; moz_transaction: %r; '
             'amount: %r; currency: %r'
             % (bill_conf_id,
                form.data.get('bango_response_code'),
                form.data.get('bango_response_message'),
                form.data.get('bango_trans_id'),
                form.data.get('bango_token'),
                form.data.get('moz_transaction'),
                form.data.get('amount'),
                form.data.get('currency')))

    if not form.is_valid():
        log.info(u'Notification invalid: %s' % bill_conf_id)
        return view.form_errors(form)

    trans = form.cleaned_data['moz_transaction']
    states = {OK: ['completed', STATUS_COMPLETED],
              CANCEL: ['cancelled', STATUS_CANCELLED]}
    message, state = states.get(form.cleaned_data['bango_response_code'],
                                ['failed', STATUS_FAILED])

    log.info(u'Transaction %s: %s' % (message, trans.uuid))
    statsd.incr('bango.notification.%s' % message)
    statsd.decr('solitude.pending_transactions')

    log_cef('Transaction change success', request, severity=7,
            cs6Label='old', cs6=STATUSES_INVERTED.get(trans.status),
            cs7Label='new', cs7=STATUSES_INVERTED.get(state))

    trans.status = state
    # This is the id for the actual transaction, useful for refunds.
    trans.uid_support = form.cleaned_data['bango_trans_id']
    # The price/currency may be empty for error notifications.
    trans.amount = form.cleaned_data['amount']
    trans.currency = form.cleaned_data['currency']
    # Set carrier and region.
    if form.cleaned_data.get('network'):
        trans.carrier = form.cleaned_data['carrier']
        trans.region = form.cleaned_data['region']

    trans.save()
    return Response(status=204)
Exemple #9
0
def login(request):
    """
    Retrieve package's infos from the package id
    to be able to later retrieve the authentication token
    given that we do not store any emails/persons ids.
    """
    view = BangoResource()
    form = GetEmailAddressesForm(request.DATA)
    if not form.is_valid():
        return view.form_errors(form)

    try:
        address = view.client('GetEmailAddresses', form.cleaned_data)
    except BangoError, exc:
        return view.client_errors(exc)
Exemple #10
0
def login(request):
    """
    Retrieve package's infos from the package id
    to be able to later retrieve the authentication token
    given that we do not store any emails/persons ids.
    """
    view = BangoResource()
    form = GetEmailAddressesForm(request.DATA)
    if not form.is_valid():
        return view.form_errors(form)

    try:
        address = view.client('GetEmailAddresses', form.cleaned_data)
    except BangoError, exc:
        return view.client_errors(exc)
Exemple #11
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()
Exemple #12
0
def event(request):
    view = BangoResource()
    form = EventForm(request.DATA, request_encoding=request.encoding)
    if not form.is_valid():
        log.info('Event invalid.')
        return view.form_errors(form)

    notification = form.cleaned_data['notification']
    transaction = form.cleaned_data['transaction']

    if notification['new_status'] != transaction.status:
        old_status = transaction.status
        transaction.status = notification['new_status']
        transaction.save()

        log_cef('Transaction change success', request, severity=7,
                cs6Label='old', cs6=STATUSES_INVERTED[old_status],
                cs7Label='new', cs7=STATUSES_INVERTED[transaction.status])
        log.info('Transaction {0} changed to {1} from {2}'
                 .format(transaction.pk, transaction.status,
                         old_status))

    return Response(status=204)
Exemple #13
0
    def post(self, request, *args, **kwargs):
        view = BangoResource()
        form = CreateBangoNumberForm(request.DATA)
        if not form.is_valid():
            return self.form_errors(form)

        serial = SellerProductBangoSerializer(data=request.DATA)
        if not serial.is_valid():
            return Response(serial.errors, status=400)

        # Create the product.
        data = form.cleaned_data
        data['packageId'] = serial.object.seller_bango.package_id

        resp = view.client('CreateBangoNumber', data)

        product = SellerProductBango.objects.create(
            seller_bango=serial.object.seller_bango,
            seller_product=serial.object.seller_product,
            bango_id=resp.bango,
        )

        # Make it premium.
        data = request.DATA.copy()
        data['bango'] = resp.bango
        data['price'] = '0.99'
        data['currencyIso'] = 'USD'

        form = MakePremiumForm(data)
        if not form.is_valid():
            return self.form_errors(form)

        data = form.cleaned_data
        data['bango'] = resp.bango
        view.client('MakePremiumPerAccess', data)

        for rating, scheme in (['UNIVERSAL', 'GLOBAL'], ['GENERAL', 'USA']):
            # Make it global and US rating.
            data.update({'rating': rating, 'ratingScheme': scheme})
            form = UpdateRatingForm(data)
            if not form.is_valid():
                return self.form_errors(form)

            data = form.cleaned_data
            data['bango'] = resp.bango
            view.client('UpdateRating', data)

        return Response(SellerProductBangoSerializer(product).data)
Exemple #14
0
    def post(self, request, *args, **kwargs):
        view = BangoResource()
        form = CreateBangoNumberForm(request.DATA)
        if not form.is_valid():
            return self.form_errors(form)

        serial = SellerProductBangoSerializer(data=request.DATA)
        if not serial.is_valid():
            return Response(serial.errors, status=400)

        # Create the product.
        data = form.cleaned_data
        data['packageId'] = serial.object.seller_bango.package_id

        resp = view.client('CreateBangoNumber', data)

        product = SellerProductBango.objects.create(
            seller_bango=serial.object.seller_bango,
            seller_product=serial.object.seller_product,
            bango_id=resp.bango,
        )

        # Make it premium.
        data = request.DATA.copy()
        data['bango'] = resp.bango
        data['price'] = '0.99'
        data['currencyIso'] = 'USD'

        form = MakePremiumForm(data)
        if not form.is_valid():
            return self.form_errors(form)

        data = form.cleaned_data
        data['bango'] = resp.bango
        view.client('MakePremiumPerAccess', data)

        for rating, scheme in (['UNIVERSAL', 'GLOBAL'],
                               ['GENERAL', 'USA']):
            # Make it global and US rating.
            data.update({'rating': rating, 'ratingScheme': scheme})
            form = UpdateRatingForm(data)
            if not form.is_valid():
                return self.form_errors(form)

            data = form.cleaned_data
            data['bango'] = resp.bango
            view.client('UpdateRating', data)

        return Response(SellerProductBangoSerializer(product).data)
Exemple #15
0
def sbi(request):
    view = BangoResource()
    if request.method.upper() == 'GET':
        return sbi_get(view, request)
    return sbi_post(view, request)