2016-05-17 05:06:25 +00:00
|
|
|
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}{md5_secret}'
|
|
|
|
).format(
|
|
|
|
merchant_number=settings.EPAY_MERCHANT_NUMBER,
|
|
|
|
description=order.description,
|
2016-05-17 05:13:10 +00:00
|
|
|
amount=order.total*100,
|
2016-05-17 05:06:25 +00:00
|
|
|
order_id=order.pk,
|
2016-05-17 05:10:18 +00:00
|
|
|
accept_url = order.get_epay_accept_url(request),
|
2016-05-29 13:55:48 +00:00
|
|
|
cancel_url = order.get_cancel_url(request),
|
2016-05-17 05:06:25 +00:00
|
|
|
md5_secret=settings.EPAY_MD5_SECRET,
|
|
|
|
)
|
|
|
|
epay_hash = hashlib.md5(hashstring).hexdigest()
|
|
|
|
return epay_hash
|
|
|
|
|
2016-05-17 05:42:31 +00:00
|
|
|
|
|
|
|
def validate_epay_callback(query):
|
|
|
|
hashstring = ''
|
|
|
|
for key, value in query.iteritems():
|
|
|
|
if key != 'hash':
|
|
|
|
hashstring += value
|
2016-05-17 05:46:36 +00:00
|
|
|
hash = hashlib.md5(hashstring + settings.EPAY_MD5_SECRET).hexdigest()
|
2016-05-17 05:42:31 +00:00
|
|
|
return hash == query['hash']
|
|
|
|
|