def obj_create(self, bundle, request, **kwargs):
        form = NotificationForm(request, bundle.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)
            raise self.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 bundle
示例#2
0
    def obj_create(self, bundle, request, **kwargs):
        form = NotificationForm(request, bundle.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)
            raise self.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 bundle
示例#3
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)
示例#4
0
    def obj_create(self, bundle, request, **kwargs):
        form = NotificationForm(request, bundle.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)
            raise self.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')
        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']
        trans.save()
        return bundle
示例#5
0
文件: signals.py 项目: Doist/powerapp
def integration_cnt_decr(sender, instance=None, **kwargs):
    statsd.decr('integration_cnt')
    statsd.decr('integration_cnt.%s' % instance.service_id)
示例#6
0
def integration_cnt_decr(sender, instance=None, **kwargs):
    statsd.decr('integration_cnt')
    statsd.decr('integration_cnt.%s' % instance.service_id)