2016-05-17 05:06:25 +00:00
|
|
|
import hashlib
|
2020-02-12 12:10:41 +00:00
|
|
|
|
2016-05-17 05:06:25 +00:00
|
|
|
from django.conf import settings
|
|
|
|
|
2018-03-04 14:38:40 +00:00
|
|
|
|
2016-05-17 05:06:25 +00:00
|
|
|
def calculate_epay_hash(order, request):
|
|
|
|
hashstring = (
|
2019-06-16 12:32:24 +00:00
|
|
|
"{merchant_number}{description}11{amount}DKK"
|
|
|
|
"{order_id}{accept_url}{cancel_url}{callback_url}{md5_secret}"
|
2016-05-17 05:06:25 +00:00
|
|
|
).format(
|
|
|
|
merchant_number=settings.EPAY_MERCHANT_NUMBER,
|
|
|
|
description=order.description,
|
2019-06-16 12:32:24 +00:00
|
|
|
amount=order.total * 100,
|
2016-05-17 05:06:25 +00:00
|
|
|
order_id=order.pk,
|
2018-03-04 14:38:40 +00:00
|
|
|
accept_url=order.get_epay_accept_url(request),
|
|
|
|
cancel_url=order.get_cancel_url(request),
|
|
|
|
callback_url=order.get_epay_callback_url(request),
|
2016-05-17 05:06:25 +00:00
|
|
|
md5_secret=settings.EPAY_MD5_SECRET,
|
|
|
|
)
|
2019-06-16 12:32:24 +00:00
|
|
|
epay_hash = hashlib.md5(hashstring.encode("utf-8")).hexdigest()
|
2016-05-17 05:06:25 +00:00
|
|
|
return epay_hash
|
|
|
|
|
2016-05-17 05:42:31 +00:00
|
|
|
|
|
|
|
def validate_epay_callback(query):
|
2019-06-16 12:32:24 +00:00
|
|
|
hashstring = ""
|
2017-01-30 11:16:07 +00:00
|
|
|
for key, value in query.items():
|
2019-06-16 12:32:24 +00:00
|
|
|
if key != "hash":
|
2016-05-17 05:42:31 +00:00
|
|
|
hashstring += value
|
2018-03-04 14:38:40 +00:00
|
|
|
hash = hashlib.md5(
|
2019-06-16 12:32:24 +00:00
|
|
|
(hashstring + settings.EPAY_MD5_SECRET).encode("utf-8")
|
2018-03-04 14:38:40 +00:00
|
|
|
).hexdigest()
|
2019-06-16 12:32:24 +00:00
|
|
|
return hash == query["hash"]
|