def _dial(self, method, location, body): '''Make the authorization HTTP headers and call the API URL. Returns the standard HTTPResponse object.''' headers = common.makeHeaders(self.APINAME, common.makeTimestamp(), self.apiKey, self.secret, method, location, body) conn = self.connectionMethod(self.apiLocation) conn.request(method, location, body, headers) return conn.getresponse()
def _dial(self, method, location, body): '''Make the authorization HTTP headers and call the API URL. Returns the standard HTTPResponse object.''' headers = common.makeHeaders(self.APINAME, common.makeTimestamp(), self.apiKey, self.secret, method, location, body) conn = self.connectionMethod(self.apiLocation) print("self", self) conn.request(method, location, body, headers) return conn.getresponse()
def testMakeHeaders(self): merchantAPITestBody='''{ "email": "*****@*****.**", "notifyUrl": "https://example.com/notify", "rows": [ { "amount": 1599, "description": "Long sleeve shirt", "vatPercent": 2400 } ] }''' testData = [ ('PaytrailConnectAPI', 'timestamp', 'apikey', b'secret', 'method', 'uri', 'body', {'Timestamp': 'timestamp', 'Content-MD5': 'hBotaJrYa9FhFEdFPCLG/A==', 'Authorization': 'PaytrailConnectAPI apikey:vHx8XcMZLsuFQaYAI7IcB6u5yMq98AODOQmoKbAAj4A='}), ('PaytrailMerchantAPI', '2015-05-01T12:00:00+0200', '13466', b'6pKF4jkv97zmqBJ3ZL8gUw5DfT2NMQ', 'POST', '/merchant/v1/payments/15153/refunds', merchantAPITestBody, {'Timestamp': '2015-05-01T12:00:00+0200', 'Content-MD5': 'yEUgr/ru9HcX91flnRzLRg==', 'Authorization': 'PaytrailMerchantAPI 13466:W4P34H0xiTB202rsjtZIsMlEPQLRoS60d26KKl0zwZo='}), ('PaytrailConnectAPI', '2012-12-31T12:00:00+02:00', '13466', b'6pKF4jkv97zmqBJ3ZL8gUw5DfT2NMQ', 'POST', '/connectapi/authorizations', '{"authSecret":"1234"}', {'Timestamp': '2012-12-31T12:00:00+02:00', 'Content-MD5': 'm/+9rBseCrTRRSJChVP9Kw==', 'Authorization': 'PaytrailConnectAPI 13466:bL///v1z99+fhnVDfXCrI/6fNdrtULTYiMxgQFVFCOA='}), ] for td in testData: self.assertEqual(makeHeaders(*td[0:7]), td[7])