Skip to content

Instantly share code, notes, and snippets.

@mlissner
Created December 30, 2014 19:24
Show Gist options
  • Save mlissner/b309d529ab457c604695 to your computer and use it in GitHub Desktop.
Save mlissner/b309d529ab457c604695 to your computer and use it in GitHub Desktop.
GAH! time.sleep(1)
def process_dwolla_transaction_status_callback(request):
if request.method == 'POST':
data = simplejson.loads(request.body)
logger.info('Dwolla transaction status callback triggered with '
'data: %s' % data)
if check_dwolla_signature(
request.META['HTTP_X_DWOLLA_SIGNATURE'],
request.body):
# Statuses can be found at:
# https://developers.dwolla.com/dev/pages/statuses
if data['Value'].lower() == 'pending':
# Wait, because Dwolla issues this faster than they issue
# their application callback. If we don't wait for a second
# here, we'll have no ID to lookup, and we'll get a
# DoesNotExist exception. Maddening.
time.sleep(1)
d = get_object_or_404(Donation, transaction_id=data['Id'])
if data['Value'].lower() == 'processed':
d.clearing_date = parser.parse(data['Triggered'])
d.status = 4
elif data['Value'].lower() == 'pending':
d.clearing_date = parser.parse(data['Triggered'])
d.status = 5
elif data['Value'].lower() == 'cancelled':
d.status = 3
elif data['Value'].lower() == 'failed':
d.status = 6
elif data['Value'].lower() == 'reclaimed':
d.status = 7
d.save()
return HttpResponse('<h1>200: OK</h1>')
else:
logger.warn('Dwolla signature check failed.')
return HttpResponseForbidden(
'<h1>403: Did not pass signature check.</h1>'
)
else:
return HttpResponseNotAllowed(
permitted_methods={'POST'},
content='<h1>405: This is a callback endpoint for a payment '
'provider. Only POST methods are allowed.</h1>'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment