bornhack-website/src/shop/epay.py
Thomas Steen Rasmussen 00af109e2f
add flake8 and isort to pre-commit config, make flake8 and isort happy (#441)
* add flake8 to pre-commit config, and fixup many things to make flake8 happy

* add isort and sort all imports, add to pre-commit and requirements
2020-02-12 13:10:41 +01:00

33 lines
1,000 B
Python

import hashlib
from django.conf import settings
def calculate_epay_hash(order, request):
hashstring = (
"{merchant_number}{description}11{amount}DKK"
"{order_id}{accept_url}{cancel_url}{callback_url}{md5_secret}"
).format(
merchant_number=settings.EPAY_MERCHANT_NUMBER,
description=order.description,
amount=order.total * 100,
order_id=order.pk,
accept_url=order.get_epay_accept_url(request),
cancel_url=order.get_cancel_url(request),
callback_url=order.get_epay_callback_url(request),
md5_secret=settings.EPAY_MD5_SECRET,
)
epay_hash = hashlib.md5(hashstring.encode("utf-8")).hexdigest()
return epay_hash
def validate_epay_callback(query):
hashstring = ""
for key, value in query.items():
if key != "hash":
hashstring += value
hash = hashlib.md5(
(hashstring + settings.EPAY_MD5_SECRET).encode("utf-8")
).hexdigest()
return hash == query["hash"]