def paypal_completed(request, transaction_id, serialize=None, amount=None): # Make sure transaction has not yet been processed. if Contribution.objects.filter(transaction_id=transaction_id).exists(): paypal_log.info('Completed IPN already processed') return http.HttpResponse('Transaction already processed') # Note that when this completes the uuid is moved over to transaction_id. try: original = Contribution.objects.get(uuid=transaction_id) except Contribution.DoesNotExist: paypal_log.info('Ignoring transaction: %s' % transaction_id) return http.HttpResponse('Transaction not found; skipping.') paypal_log.info('Completed IPN received: %s' % transaction_id) data = StatsDictField().to_python(php.serialize(serialize)) update = { 'transaction_id': transaction_id, 'uuid': None, 'post_data': data } if amount: update['amount'] = _parse_currency(amount)['amount'] original.update(**update) # Send thankyou email. try: original.mail_thankyou(request) except ContributionError as e: # A failed thankyou email is not a show stopper, but is good to know. paypal_log.error('Thankyou note email failed with error: %s' % e) paypal_log.info('Completed successfully processed (%s)' % transaction_id) return http.HttpResponse('Success!')
def test_to_python_json(self): val = {'a': 1} assert StatsDictField().to_python(json.dumps(val)) == val
def test_to_python_php(self): val = {'a': 1} assert StatsDictField().to_python(php.serialize(val)) == val
def test_to_python_dict(self): assert StatsDictField().to_python({'a': 1}) == {'a': 1}
def test_to_python_none(self): assert StatsDictField().to_python(None) is None
def test_to_python_json(self): val = {'a': 1} eq_(StatsDictField().to_python(json.dumps(val)), val)
def test_to_python_php(self): val = {'a': 1} eq_(StatsDictField().to_python(php.serialize(val)), val)
def test_to_python_dict(self): eq_(StatsDictField().to_python({'a': 1}), {'a': 1})
def test_to_python_none(self): eq_(StatsDictField().to_python(None), None)