Example #1
0
    def create(self, request):
        form = EventForm(request.DATA)
        param = form.data.get('param')

        if not form.is_valid():
            log.info('Notification invalid: {0}'.format(param))
            return self.form_errors([form])

        cleaned = form.cleaned_data
        transaction = cleaned['param']

        # Verify this against Boku, this will raise errors if there's
        # an issue.
        log.info('Verifying notification for Boku transaction id: {0}'
                 .format(transaction))

        status = STATUS_COMPLETED
        try:
            verify(cleaned['trx_id'], cleaned['amount'], cleaned['currency'])
        except BokuException, exc:
            log.info('Got non-zero Boku API response: '
                     '{exc}; code={exc.result_code}; msg={exc.result_msg}'
                     .format(exc=exc))
            # Boku will return non-zero error codes to indicate certain
            # transaction states. These states mean that the notification
            # itself is valid.
            if exc.result_code in TRANS_STATUS_FROM_VERIFY_CODE:
                status = TRANS_STATUS_FROM_VERIFY_CODE[exc.result_code]
                log.info('got Boku transaction status {s} from code {c}'
                         .format(s=status, c=exc.result_code))
            else:
                raise
Example #2
0
 def test_action(self):
     form = EventForm(self.sample())
     ok_(form.is_valid(), form.errors)
Example #3
0
 def form_error(self, data, *errors):
     form = EventForm(data)
     assert not form.is_valid()
     eq_(set(errors), set(form.errors.keys()), form.errors)