Пример #1
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)
Пример #2
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)
Пример #3
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)
Пример #4
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)