Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions payeezy_python/example/build/lib/payeezy/http_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ def __init__(self, apiKey,apiSecret, token, url,tokenurl):
self.token = token
self.url = url
self.tokenurl = tokenurl
# cryptographically strong random number
self.nonce = str(int(os.urandom(16).encode('hex'),16))
self.timestamp = str(int(round(time.time() * 1000)))
self.timeout = 30 # max timeout is 30 sec

# HMAC Generation
def generateHMACAuthenticationHeader(self, payload):
# cryptographically strong random number
nonce = str(int(os.urandom(16).encode('hex'),16))
currentTimeInMilli = str(int(round(time.time() * 1000)))
messageData = self.apikey+nonce+currentTimeInMilli+self.token+payload
messageData = self.apikey+self.nonce+self.timestamp+self.token+payload
hmacInHex = hmac.new(self.apisecret, msg=messageData, digestmod=hashlib.sha256).hexdigest()
return b64encode(hmacInHex)

Expand All @@ -81,7 +82,7 @@ def getTokenPostCall(self, payload):
response.mount('https://', MyAdapter())
self.payload = json.dumps(payload)
authorizationVal = self.generateHMACAuthenticationHeader(payload=self.payload)
result = response.post(self.tokenURL, headers={'User-Agent':'Payeezy-Python','content-type': 'application/json','apikey':self.apikey,'token':self.token,'Authorization':'xxxxx'}, data=self.payload)
result = response.post(self.tokenURL, headers={'User-Agent':'Payeezy-Python','content-type': 'application/json','apikey':self.apikey,'token':self.token,'nonce':self.nonce,'timestamp':self.timestamp,'Authorization':'xxxxx'}, data=self.payload)
return result

#Generic method to make calls for primary transactions
Expand All @@ -90,7 +91,7 @@ def makeCardBasedTransactionPostCall(self, payload):
response.mount('https://', MyAdapter())
self.payload = json.dumps(payload)
authorizationVal = self.generateHMACAuthenticationHeader(payload=self.payload)
result = response.post(self.url, headers={'User-Agent':'Payeezy-Python','content-type': 'application/json','apikey':self.apikey,'token':self.token,'Authorization':authorizationVal}, data=self.payload)
result = response.post(self.url, headers={'User-Agent':'Payeezy-Python','content-type': 'application/json','apikey':self.apikey,'token':self.token,'nonce':self.nonce,'timestamp':self.timestamp,'Authorization':authorizationVal}, data=self.payload)
return result


Expand All @@ -101,7 +102,7 @@ def makeCaptureVoidRefundPostCall(self,payload,transactionID):
self.url = self.url + '/' + transactionID
self.payload = json.dumps(payload)
authorizationVal = self.generateHMACAuthenticationHeader(payload=self.payload)
result = response.post(self.url, headers={'User-Agent':'Payeezy-Python','content-type': 'application/json','apikey':self.apikey,'token':self.token,'Authorization':authorizationVal}, data=self.payload)
result = response.post(self.url, headers={'User-Agent':'Payeezy-Python','content-type': 'application/json','apikey':self.apikey,'token':self.token,'nonce':self.nonce,'timestamp':self.timestamp,'Authorization':authorizationVal}, data=self.payload)
return result