Last active
March 6, 2018 14:55
-
-
Save sameerkumar18/b297009370cf2c64ce82b865d41c457c to your computer and use it in GitHub Desktop.
Instamojo Django Webhook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate_webhook(request): | |
data = dict(request.POST.lists()) | |
print(data) | |
mac_provided = data.pop('mac')[0] | |
print("mac provided is =") | |
print(mac_provided) | |
message = "|".join(v[0] for k, v in sorted(data.items(), key=lambda x: x[0].lower())) | |
# Pass the 'salt' without the <>. Found in API Integration dashboard | |
mac_calculated = hmac.new("<YOUR_SALT>", message.encode('utf-8'), hashlib.sha1).hexdigest() | |
print("mac calculated is =") | |
print(mac_calculated) | |
if mac_provided == mac_calculated: | |
#AUTH SUCCESSFUL | |
if request.POST["status"] == "Credit": | |
# Payment was successful, mark it as completed in your database. | |
print("SUCCESS") | |
return True, True | |
else: | |
# Payment was unsuccessful, mark it as failed in your database. | |
print("FAIL") | |
return True, False | |
else: | |
return False, False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment