diff --git a/addonpayments/api/card_storage/requests.py b/addonpayments/api/card_storage/requests.py index 0b1f22b..1ec5dc1 100644 --- a/addonpayments/api/card_storage/requests.py +++ b/addonpayments/api/card_storage/requests.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import attr from attr import ib as Field diff --git a/addonpayments/api/client.py b/addonpayments/api/client.py index e18db6d..b6fda50 100644 --- a/addonpayments/api/client.py +++ b/addonpayments/api/client.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import requests import attr from decouple import config @@ -58,7 +60,7 @@ def send(self, request, response_validation=True): result = requests.post(self.endpoint, data=xml.encode(self.encoding_charset), headers=self.headers) except requests.exceptions.RequestException as e: error_msg = "POST requests error" - logger.error("{}: {}".format(error_msg)) + logger.error(error_msg) raise SdkError(error_msg, e) normalized_dict = XmlUtils.from_xml_api_response(result.text) diff --git a/addonpayments/api/common/requests.py b/addonpayments/api/common/requests.py index e71d2c6..74c9b7b 100644 --- a/addonpayments/api/common/requests.py +++ b/addonpayments/api/common/requests.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import attr from attr import ib as Field diff --git a/addonpayments/api/common/responses.py b/addonpayments/api/common/responses.py index 2c3c287..2081bf6 100644 --- a/addonpayments/api/common/responses.py +++ b/addonpayments/api/common/responses.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + from addonpayments.responses import SdkResponse diff --git a/addonpayments/api/dcc/requests.py b/addonpayments/api/dcc/requests.py index 31e7f07..77680ed 100644 --- a/addonpayments/api/dcc/requests.py +++ b/addonpayments/api/dcc/requests.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import attr from attr import ib as Field diff --git a/addonpayments/api/elements.py b/addonpayments/api/elements.py index 32ca7ec..6a81f81 100644 --- a/addonpayments/api/elements.py +++ b/addonpayments/api/elements.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import attr from attr import ib as Field diff --git a/addonpayments/api/mixins.py b/addonpayments/api/mixins.py index bfe76b9..773337b 100644 --- a/addonpayments/api/mixins.py +++ b/addonpayments/api/mixins.py @@ -1,6 +1,9 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import attr +import six from attr import ib as Field from addonpayments.mixins import DictMixin @@ -82,7 +85,7 @@ def normalize_xml(self): :return: dict """ result = {} - for key, value in self.to_dict().items(): + for key, value in six.iteritems(self.to_dict()): # This field (key) is an object if key in self.object_fields: result.update(value.normalize_xml()) diff --git a/addonpayments/api/payment/requests.py b/addonpayments/api/payment/requests.py index 0f95bcf..af00967 100644 --- a/addonpayments/api/payment/requests.py +++ b/addonpayments/api/payment/requests.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import attr from attr import ib as Field diff --git a/addonpayments/api/tests/conftest.py b/addonpayments/api/tests/conftest.py index 7bb4dcb..0fdf63c 100644 --- a/addonpayments/api/tests/conftest.py +++ b/addonpayments/api/tests/conftest.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import pytest from decouple import config diff --git a/addonpayments/api/tests/tests/test_card_storage.py b/addonpayments/api/tests/tests/test_card_storage.py index 02b46f0..0f92e93 100644 --- a/addonpayments/api/tests/tests/test_card_storage.py +++ b/addonpayments/api/tests/tests/test_card_storage.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import pytest from addonpayments.api.tests.conftest import BaseTest diff --git a/addonpayments/api/tests/tests/test_dcc.py b/addonpayments/api/tests/tests/test_dcc.py index a83e60d..4af8158 100644 --- a/addonpayments/api/tests/tests/test_dcc.py +++ b/addonpayments/api/tests/tests/test_dcc.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import pytest from addonpayments.api.tests.conftest import BaseTest diff --git a/addonpayments/api/tests/tests/test_payment.py b/addonpayments/api/tests/tests/test_payment.py index 37b292f..9730a37 100644 --- a/addonpayments/api/tests/tests/test_payment.py +++ b/addonpayments/api/tests/tests/test_payment.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + from addonpayments.api.tests.conftest import BaseTest from addonpayments.api.client import ApiClient from addonpayments.api.payment.requests import AuthRequest diff --git a/addonpayments/api/tests/tests/test_three_ds.py b/addonpayments/api/tests/tests/test_three_ds.py index a8f4118..fbff68f 100644 --- a/addonpayments/api/tests/tests/test_three_ds.py +++ b/addonpayments/api/tests/tests/test_three_ds.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import pytest from addonpayments.api.tests.conftest import BaseTest diff --git a/addonpayments/api/tests/tests/test_transaction_management.py b/addonpayments/api/tests/tests/test_transaction_management.py index c405f03..ee5d45e 100644 --- a/addonpayments/api/tests/tests/test_transaction_management.py +++ b/addonpayments/api/tests/tests/test_transaction_management.py @@ -1,4 +1,7 @@ # -*- encoding: utf-8 -*- + +from __future__ import absolute_import, unicode_literals + import pytest from addonpayments.api.tests.conftest import BaseTest diff --git a/addonpayments/api/three_ds/requests.py b/addonpayments/api/three_ds/requests.py index 0e2ebf2..fcce50d 100644 --- a/addonpayments/api/three_ds/requests.py +++ b/addonpayments/api/three_ds/requests.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import attr from attr import ib as Field diff --git a/addonpayments/api/three_ds/validators.py b/addonpayments/api/three_ds/validators.py index b92adb3..651ecd8 100644 --- a/addonpayments/api/three_ds/validators.py +++ b/addonpayments/api/three_ds/validators.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + from addonpayments.utils import ValidateUtils as Validate diff --git a/addonpayments/api/transaction_management/requests.py b/addonpayments/api/transaction_management/requests.py index b5e191f..1629549 100644 --- a/addonpayments/api/transaction_management/requests.py +++ b/addonpayments/api/transaction_management/requests.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import attr from attr import ib as Field diff --git a/addonpayments/api/transaction_management/validators.py b/addonpayments/api/transaction_management/validators.py index c25667f..00d22e6 100644 --- a/addonpayments/api/transaction_management/validators.py +++ b/addonpayments/api/transaction_management/validators.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + from addonpayments.utils import ValidateUtils as Validate diff --git a/addonpayments/api/utils.py b/addonpayments/api/utils.py index b3a2ce2..e2bc220 100644 --- a/addonpayments/api/utils.py +++ b/addonpayments/api/utils.py @@ -1,5 +1,8 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + +import six import xmltodict import json @@ -40,7 +43,7 @@ def from_xml_api_response(xml): try: resp = json.loads(json.dumps(xmltodict.parse(xml))) resp['response'] - response = {key.replace('@', ''): value for key, value in resp['response'].items()} + response = {key.replace('@', ''): value for key, value in six.iteritems(resp['response'])} except Exception as e: error_msg = "Error parsing response XML" logger.error("{}: {}".format(error_msg, e)) diff --git a/addonpayments/api/validators.py b/addonpayments/api/validators.py index 5a766c8..83a549c 100644 --- a/addonpayments/api/validators.py +++ b/addonpayments/api/validators.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + from addonpayments.utils import ValidateUtils as Validate diff --git a/addonpayments/exceptions.py b/addonpayments/exceptions.py index ce671d1..244542d 100644 --- a/addonpayments/exceptions.py +++ b/addonpayments/exceptions.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + class SdkError(Exception): """ diff --git a/addonpayments/hpp/card_storage/requests.py b/addonpayments/hpp/card_storage/requests.py index 85290d8..906d964 100644 --- a/addonpayments/hpp/card_storage/requests.py +++ b/addonpayments/hpp/card_storage/requests.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import attr from attr import ib as Field diff --git a/addonpayments/hpp/card_storage/validators.py b/addonpayments/hpp/card_storage/validators.py index 1d9dfcf..923c365 100644 --- a/addonpayments/hpp/card_storage/validators.py +++ b/addonpayments/hpp/card_storage/validators.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + from addonpayments.utils import ValidateUtils as Validate diff --git a/addonpayments/hpp/common/requests.py b/addonpayments/hpp/common/requests.py index d9df43e..4ce41d8 100644 --- a/addonpayments/hpp/common/requests.py +++ b/addonpayments/hpp/common/requests.py @@ -1,6 +1,9 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import attr +import six from attr import ib as Field from addonpayments.mixins import DictMixin, HashMixin @@ -65,20 +68,20 @@ def to_dict(self): :return: dict """ result = {} - for key, value in self.__dict__.items(): + for key, value in six.iteritems(self.__dict__): # Add supplementary data into dict if key == 'supplementary_data': try: - for key_supp, value_supp in self.supplementary_data.items(): - if key_supp not in self.__dict__.keys(): + for key_supp, value_supp in six.iteritems(self.supplementary_data): + if key_supp not in six.iterkeys(self.__dict__): result[key_supp] = value_supp except AttributeError: result[key.upper()] = value - - # Parse boolean fields to str '1' (True) or '0' (False) - result_value = self.set_flags(key, value) - if result_value: - result[key.upper()] = result_value + else: + # Parse boolean fields to str '1' (True) or '0' (False) + result_value = self.set_flags(key, value) + if result_value: + result[key.upper()] = result_value return result def hash(self, secret): diff --git a/addonpayments/hpp/common/responses.py b/addonpayments/hpp/common/responses.py index 9fb1948..8f66f76 100644 --- a/addonpayments/hpp/common/responses.py +++ b/addonpayments/hpp/common/responses.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + from addonpayments.responses import SdkResponse diff --git a/addonpayments/hpp/hpp.py b/addonpayments/hpp/hpp.py index 9f2c9b6..e1fda30 100644 --- a/addonpayments/hpp/hpp.py +++ b/addonpayments/hpp/hpp.py @@ -1,6 +1,9 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import attr +import six from addonpayments.exceptions import SdkError from addonpayments.logger import Logger @@ -143,7 +146,7 @@ def response_from_dict(self, response_dict): :return: """ logger.info("Converting dict to HppResponse.") - normalized_dict = {key.lower(): value for key, value in response_dict.items()} + normalized_dict = {key.lower(): value for key, value in six.iteritems(response_dict)} hpp_response = HppResponse(**normalized_dict) return ValidationUtils.validate_response(hpp_response, self.secret) diff --git a/addonpayments/hpp/payment/requests.py b/addonpayments/hpp/payment/requests.py index 54bf70d..4a57b6b 100644 --- a/addonpayments/hpp/payment/requests.py +++ b/addonpayments/hpp/payment/requests.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import attr from addonpayments.hpp.common.requests import HppRequest diff --git a/addonpayments/hpp/tests/conftest.py b/addonpayments/hpp/tests/conftest.py index 8fa85cb..5526e9d 100644 --- a/addonpayments/hpp/tests/conftest.py +++ b/addonpayments/hpp/tests/conftest.py @@ -1,5 +1,8 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + +import codecs import pytest from addonpayments.hpp.card_storage.requests import CardStorageRequest @@ -30,35 +33,35 @@ def valid_hpp_request_storage_enabled(): @pytest.fixture() def json_hpp_payment_request_valid(): - with open(sample_path(HPP_PAYMENT_REQUEST_VALID_JSON_PATH)) as data_file: - yield JsonUtils.from_json_hpp_request(data_file, CHARSET, False) + with codecs.open(sample_path(HPP_PAYMENT_REQUEST_VALID_JSON_PATH), 'r', encoding='utf-8') as data_file: + yield JsonUtils.from_json_hpp_request(data_file.read(), CHARSET, False) @pytest.fixture() def json_hpp_payment_request_supplementary_data(): - with open(sample_path(HPP_PAYMENT_REQUEST_SUPPLEMENTARY_JSON_PATH)) as data_file: - yield JsonUtils.from_json_hpp_request(data_file, CHARSET, False) + with codecs.open(sample_path(HPP_PAYMENT_REQUEST_SUPPLEMENTARY_JSON_PATH), 'r', encoding='utf-8') as data_file: + yield JsonUtils.from_json_hpp_request(data_file.read(), CHARSET, False) @pytest.fixture() def json_hpp_payment_request_encoded(): - with open(sample_path(HPP_PAYMENT_REQUEST_ENCODED_JSON_PATH)) as data_file: - yield JsonUtils.from_json_hpp_request(data_file, CHARSET, True) + with codecs.open(sample_path(HPP_PAYMENT_REQUEST_ENCODED_JSON_PATH), 'r', encoding='utf-8') as data_file: + yield JsonUtils.from_json_hpp_request(data_file.read(), CHARSET, True) @pytest.fixture() def json_hpp_card_storage_request_valid(): - with open(sample_path(HPP_CARD_STORAGE_REQUEST_VALID_JSON_PATH)) as data_file: - yield JsonUtils.from_json_hpp_request(data_file, CHARSET, False) + with codecs.open(sample_path(HPP_CARD_STORAGE_REQUEST_VALID_JSON_PATH), 'r', encoding='utf-8') as data_file: + yield JsonUtils.from_json_hpp_request(data_file.read(), CHARSET, False) @pytest.fixture() -def json_hpp_card_storage_request_supplementary_data(): - with open(sample_path(HPP_CARD_STORAGE_REQUEST_SUPPLEMENTARY_JSON_PATH)) as data_file: - yield JsonUtils.from_json_hpp_request(data_file, CHARSET, False) +def json_hpp_card_storage_request_supp_data(): + with codecs.open(sample_path(HPP_CARD_STORAGE_REQUEST_SUPPLEMENTARY_JSON_PATH), 'r', encoding='utf-8') as data_file: + yield JsonUtils.from_json_hpp_request(data_file.read(), CHARSET, False) @pytest.fixture() def json_hpp_card_storage_request_encoded(): - with open(sample_path(HPP_CARD_STORAGE_REQUEST_ENCODED_JSON_PATH)) as data_file: - yield JsonUtils.from_json_hpp_request(data_file, CHARSET, True) + with codecs.open(sample_path(HPP_CARD_STORAGE_REQUEST_ENCODED_JSON_PATH), 'r', encoding='utf-8') as data_file: + yield JsonUtils.from_json_hpp_request(data_file.read(), CHARSET, True) diff --git a/addonpayments/hpp/tests/samples/hpp_card_storage_request.json b/addonpayments/hpp/tests/samples/hpp_card_storage_request.json index f2ebebc..cfc37df 100644 --- a/addonpayments/hpp/tests/samples/hpp_card_storage_request.json +++ b/addonpayments/hpp/tests/samples/hpp_card_storage_request.json @@ -9,7 +9,6 @@ "AUTO_SETTLE_FLAG": "1", "COMMENT1": "a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | = ;ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿŒŽšœžŸ¥", "COMMENT2": "Comment Two", - "RETURN_TSS": "0", "SHIPPING_CODE": "56|987", "SHIPPING_CO": "IRELAND", "BILLING_CODE": "123|56", diff --git a/addonpayments/hpp/tests/samples/hpp_card_storage_request_encoded.json b/addonpayments/hpp/tests/samples/hpp_card_storage_request_encoded.json index 047175d..00eb595 100644 --- a/addonpayments/hpp/tests/samples/hpp_card_storage_request_encoded.json +++ b/addonpayments/hpp/tests/samples/hpp_card_storage_request_encoded.json @@ -9,7 +9,6 @@ "AUTO_SETTLE_FLAG": "MQ==", "COMMENT1": "Q29tbWVudCBUd28=", "COMMENT2": "Q29tbWVudCBUd28=", - "RETURN_TSS": "MA==", "SHIPPING_CODE": "NTZ8OTg3", "SHIPPING_CO": "SVJFTEFORA==", "BILLING_CODE": "MTIzfDU2", diff --git a/addonpayments/hpp/tests/samples/hpp_payment_request.json b/addonpayments/hpp/tests/samples/hpp_payment_request.json index 10557f7..6d556a3 100644 --- a/addonpayments/hpp/tests/samples/hpp_payment_request.json +++ b/addonpayments/hpp/tests/samples/hpp_payment_request.json @@ -9,7 +9,6 @@ "AUTO_SETTLE_FLAG": "1", "COMMENT1": "a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | = ;ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿŒŽšœžŸ¥", "COMMENT2": "Comment Two", - "RETURN_TSS": "0", "SHIPPING_CODE": "56|987", "SHIPPING_CO": "IRELAND", "BILLING_CODE": "123|56", diff --git a/addonpayments/hpp/tests/tests/test_generation_utils.py b/addonpayments/hpp/tests/tests/test_generation_utils.py index 5ee307a..5d4c36e 100644 --- a/addonpayments/hpp/tests/tests/test_generation_utils.py +++ b/addonpayments/hpp/tests/tests/test_generation_utils.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import re from addonpayments.utils import GenerationUtils diff --git a/addonpayments/hpp/tests/tests/test_hpp_request.py b/addonpayments/hpp/tests/tests/test_hpp_request.py index 7d6155b..172d111 100644 --- a/addonpayments/hpp/tests/tests/test_hpp_request.py +++ b/addonpayments/hpp/tests/tests/test_hpp_request.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + class TestHppRequest: secret = "mysecret" diff --git a/addonpayments/hpp/tests/tests/test_json_utils.py b/addonpayments/hpp/tests/tests/test_json_utils.py index 0e3ef7c..0547e1c 100644 --- a/addonpayments/hpp/tests/tests/test_json_utils.py +++ b/addonpayments/hpp/tests/tests/test_json_utils.py @@ -1,7 +1,12 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + +import json + from addonpayments.hpp.card_storage.requests import CardStorageRequest from addonpayments.hpp.payment.requests import PaymentRequest +from addonpayments.hpp.utils import JsonUtils class TestJsonUtils: @@ -33,6 +38,39 @@ def test_from_json_hpp_payment_request(self, json_hpp_payment_request_valid): assert json_hpp_payment_request_valid.hpp_lang == "EN" assert json_hpp_payment_request_valid.card_payment_button == "Submit Payment" + def test_to_json_hpp_payment_request(self, json_hpp_payment_request_valid): + """ + Test PaymentRequest generated to JSON + :param json_hpp_payment_request_valid: PaymentRequest + """ + assert isinstance(json_hpp_payment_request_valid, PaymentRequest) + + json_base64_request = json.loads(JsonUtils.to_json(json_hpp_payment_request_valid, 'utf-8', True)) + assert isinstance(json_base64_request, dict) + assert json_base64_request.get('TIMESTAMP') == 'MjA5OTAxMDExMjAwMDA=' + assert json_base64_request.get('ORDER_ID') == 'T3JkZXJJRA==' + assert json_base64_request.get('VAR_REF') == 'VmFyaWFibGVSZWY=' + assert json_base64_request.get('MERCHANT_ID') == 'TWVyY2hhbnRJRA==' + assert json_base64_request.get('AMOUNT') == 'MTAw' + assert json_base64_request.get('ACCOUNT') == 'bXlBY2NvdW50' + assert json_base64_request.get('PROD_ID') == 'UHJvZHVjdElE' + assert json_base64_request.get('SHA1HASH') == 'NWQ4ZjA1YWJkNjE4ZTUwZGI0ODYxYTYxY2M5NDAxMTI3ODY0NzRjZg==' + comment = 'YS16IEEtWiAwLTkgJyAiLCArIOKAnOKAnSAuXyAtICYgXCAvIEAgISA/ICUgKCApKiA6IMKjICQgJiDigqwgIyBbIF0gfC' \ + 'A9IDvDgMOBw4LDg8OEw4XDhsOHw4jDicOKw4vDjMONw47Dj8OQw5HDksOTw5TDlcOWw5fDmMOZw5rDm8Ocw53DnsOfw6DD' \ + 'ocOiw6PDpMOlw6bDp8Oow6nDqsOrw6zDrcOuw6/DsMOxw7LDs8O0w7XDtsO3w7jCpMO5w7rDu8O8w73DvsO/xZLFvcWhxZ' \ + 'PFvsW4wqU=' + assert json_base64_request.get('COMMENT1') == comment + assert json_base64_request.get('CURRENCY') == 'RVVS' + assert json_base64_request.get('SHIPPING_CODE') == 'NTZ8OTg3' + assert json_base64_request.get('CARD_PAYMENT_BUTTON') == 'U3VibWl0IFBheW1lbnQ=' + assert json_base64_request.get('HPP_LANG') == 'RU4=' + assert json_base64_request.get('AUTO_SETTLE_FLAG') == 'MQ==' + assert json_base64_request.get('SHIPPING_CO') == 'SVJFTEFORA==' + assert json_base64_request.get('BILLING_CO') == 'SVJFTEFORA==' + assert json_base64_request.get('COMMENT2') == 'Q29tbWVudCBUd28=' + assert json_base64_request.get('BILLING_CODE') == 'MTIzfDU2' + assert json_base64_request.get('CUST_NUM') == 'MTIzNDU2' + def test_from_json_hpp_payment_request_supplementary_data(self, json_hpp_payment_request_supplementary_data): """ Test PaymentRequest with supplementary data () generated from JSON @@ -60,10 +98,44 @@ def test_from_json_hpp_payment_request_supplementary_data(self, json_hpp_payment assert json_hpp_payment_request_supplementary_data.hpp_lang == "EN" assert json_hpp_payment_request_supplementary_data.card_payment_button == "Submit Payment" assert isinstance(json_hpp_payment_request_supplementary_data.supplementary_data, dict) - assert json_hpp_payment_request_supplementary_data.supplementary_data['supplementary_1'] == "Supp1" - assert json_hpp_payment_request_supplementary_data.supplementary_data['supplementary_2'] == "Supp2" - assert json_hpp_payment_request_supplementary_data.supplementary_data['supplementary_3'] == "Supp3" - assert json_hpp_payment_request_supplementary_data.supplementary_data['supplementary_4'] == "Supp4" + assert json_hpp_payment_request_supplementary_data.supplementary_data['SUPPLEMENTARY_1'] == "Supp1" + assert json_hpp_payment_request_supplementary_data.supplementary_data['SUPPLEMENTARY_2'] == "Supp2" + assert json_hpp_payment_request_supplementary_data.supplementary_data['SUPPLEMENTARY_3'] == "Supp3" + assert json_hpp_payment_request_supplementary_data.supplementary_data['SUPPLEMENTARY_4'] == "Supp4" + + def test_to_json_hpp_payment_request_supplementary_data(self, json_hpp_payment_request_supplementary_data): + """ + Test PaymentRequest with supplementary data () generated to JSON + :param json_hpp_payment_request_supplementary_data: PaymentRequest + """ + assert isinstance(json_hpp_payment_request_supplementary_data, PaymentRequest) + + json_base64_request = json.loads(JsonUtils.to_json(json_hpp_payment_request_supplementary_data, 'utf-8', True)) + assert isinstance(json_base64_request, dict) + assert json_base64_request.get('SHIPPING_CO') == 'SVJFTEFORA==' + assert json_base64_request.get('HPP_LANG') == 'RU4=' + assert json_base64_request.get('COMMENT2') == 'Q29tbWVudCBUd28=' + assert json_base64_request.get('ORDER_ID') == 'T3JkZXJJRA==' + assert json_base64_request.get('SHA1HASH') == 'NWQ4ZjA1YWJkNjE4ZTUwZGI0ODYxYTYxY2M5NDAxMTI3ODY0NzRjZg==' + assert json_base64_request.get('AUTO_SETTLE_FLAG') == 'MQ==' + comment = 'YS16IEEtWiAwLTkgJyAiLCArIOKAnOKAnSAuXyAtICYgXCAvIEAgISA/ICUgKCApKiA6IMKjICQgJiDigqwgIyBbIF0gfCA9' + assert json_base64_request.get('COMMENT1') == comment + assert json_base64_request.get('VAR_REF') == 'VmFyaWFibGVSZWY=' + assert json_base64_request.get('TIMESTAMP') == 'MjA5OTAxMDExMjAwMDA=' + assert json_base64_request.get('ACCOUNT') == 'bXlBY2NvdW50' + assert json_base64_request.get('AMOUNT') == 'MTAw' + assert json_base64_request.get('SHIPPING_CODE') == 'NTZ8OTg3' + assert json_base64_request.get('BILLING_CO') == 'SVJFTEFORA==' + assert json_base64_request.get('CUST_NUM') == 'MTIzNDU2' + assert json_base64_request.get('CURRENCY') == 'RVVS' + assert json_base64_request.get('BILLING_CODE') == 'MTIzfDU2' + assert json_base64_request.get('PROD_ID') == 'UHJvZHVjdElE' + assert json_base64_request.get('CARD_PAYMENT_BUTTON') == 'U3VibWl0IFBheW1lbnQ=' + assert json_base64_request.get('MERCHANT_ID') == 'TWVyY2hhbnRJRA==' + assert json_base64_request.get('SUPPLEMENTARY_1') == 'U3VwcDE=' + assert json_base64_request.get('SUPPLEMENTARY_2') == 'U3VwcDI=' + assert json_base64_request.get('SUPPLEMENTARY_3') == 'U3VwcDM=' + assert json_base64_request.get('SUPPLEMENTARY_4') == 'U3VwcDQ=' def test_from_json_hpp_payment_request_encoded(self, json_hpp_payment_request_encoded): """ @@ -91,7 +163,6 @@ def test_from_json_hpp_payment_request_encoded(self, json_hpp_payment_request_en assert json_hpp_payment_request_encoded.hpp_lang == "EN" assert json_hpp_payment_request_encoded.card_payment_button == "Submit Payment" assert isinstance(json_hpp_payment_request_encoded.supplementary_data, dict) - assert json_hpp_payment_request_encoded.supplementary_data['return_tss'] == "0" def test_from_json_hpp_card_storage_request(self, json_hpp_card_storage_request_valid): """ @@ -126,43 +197,118 @@ def test_from_json_hpp_card_storage_request(self, json_hpp_card_storage_request_ assert json_hpp_card_storage_request_valid.pmt_ref == "PaymentRef" assert json_hpp_card_storage_request_valid.payer_exist == "1" - def test_from_json_hpp_card_storage_request_supplementary_data(self, - json_hpp_card_storage_request_supplementary_data): + def test_to_json_hpp_card_storage_request(self, json_hpp_card_storage_request_valid): + """ + Test PaymentRequest generated to JSON + :param json_hpp_card_storage_request_valid: PaymentRequest + """ + assert isinstance(json_hpp_card_storage_request_valid, CardStorageRequest) + + json_base64_request = json.loads(JsonUtils.to_json(json_hpp_card_storage_request_valid, 'utf-8', True)) + assert isinstance(json_base64_request, dict) + assert json_base64_request.get('BILLING_CO') == 'SVJFTEFORA==' + assert json_base64_request.get('ACCOUNT') == 'bXlBY2NvdW50' + assert json_base64_request.get('VAR_REF') == 'VmFyaWFibGVSZWY=' + assert json_base64_request.get('SHIPPING_CO') == 'SVJFTEFORA==' + comment = 'YS16IEEtWiAwLTkgJyAiLCArIOKAnOKAnSAuXyAtICYgXCAvIEAgISA/ICUgKCApKiA6IMKjICQgJiDigqwgIyBbIF0gfCA9I' \ + 'DvDgMOBw4LDg8OEw4XDhsOHw4jDicOKw4vDjMONw47Dj8OQw5HDksOTw5TDlcOWw5fDmMOZw5rDm8Ocw53DnsOfw6DDocOiw6' \ + 'PDpMOlw6bDp8Oow6nDqsOrw6zDrcOuw6/DsMOxw7LDs8O0w7XDtsO3w7jCpMO5w7rDu8O8w73DvsO/xZLFvcWhxZPFvsW4wqU=' + assert json_base64_request.get('COMMENT1') == comment + assert json_base64_request.get('COMMENT2') == 'Q29tbWVudCBUd28=' + assert json_base64_request.get('CURRENCY') == 'RVVS' + assert json_base64_request.get('PAYER_EXIST') == 'MQ==' + assert json_base64_request.get('MERCHANT_ID') == 'TWVyY2hhbnRJRA==' + assert json_base64_request.get('CARD_PAYMENT_BUTTON') == 'U3VibWl0IFBheW1lbnQ=' + assert json_base64_request.get('ORDER_ID') == 'T3JkZXJJRA==' + assert json_base64_request.get('SHIPPING_CODE') == 'NTZ8OTg3' + assert json_base64_request.get('AMOUNT') == 'MTAw' + assert json_base64_request.get('SHA1HASH') == 'NWQ4ZjA1YWJkNjE4ZTUwZGI0ODYxYTYxY2M5NDAxMTI3ODY0NzRjZg==' + assert json_base64_request.get('AUTO_SETTLE_FLAG') == 'MQ==' + assert json_base64_request.get('OFFER_SAVE_CARD') == 'MQ==' + assert json_base64_request.get('BILLING_CODE') == 'MTIzfDU2' + assert json_base64_request.get('PROD_ID') == 'UHJvZHVjdElE' + assert json_base64_request.get('PAYER_REF') == 'UGF5ZXJSZWY=' + assert json_base64_request.get('CARD_STORAGE_ENABLE') == 'MQ==' + assert json_base64_request.get('TIMESTAMP') == 'MjA5OTAxMDExMjAwMDA=' + assert json_base64_request.get('CUST_NUM') == 'MTIzNDU2' + assert json_base64_request.get('PMT_REF') == 'UGF5bWVudFJlZg==' + assert json_base64_request.get('HPP_LANG') == 'RU4=' + + def test_from_json_hpp_card_storage_request_supp_data(self, json_hpp_card_storage_request_supp_data): """ Test CardStorageRequest with supplementary data () generated from JSON - :param json_hpp_card_storage_request_supplementary_data: CardStorageRequest - """ - assert isinstance(json_hpp_card_storage_request_supplementary_data, CardStorageRequest) - assert json_hpp_card_storage_request_supplementary_data.merchant_id == "MerchantID" - assert json_hpp_card_storage_request_supplementary_data.account == "myAccount" - assert json_hpp_card_storage_request_supplementary_data.order_id == "OrderID" - assert json_hpp_card_storage_request_supplementary_data.amount == "100" - assert json_hpp_card_storage_request_supplementary_data.currency == "EUR" - assert json_hpp_card_storage_request_supplementary_data.timestamp == "20990101120000" - assert json_hpp_card_storage_request_supplementary_data.sha1hash == "5d8f05abd618e50db4861a61cc940112786474cf" - assert json_hpp_card_storage_request_supplementary_data.auto_settle_flag == "1" + :param json_hpp_card_storage_request_supp_data: CardStorageRequest + """ + assert isinstance(json_hpp_card_storage_request_supp_data, CardStorageRequest) + assert json_hpp_card_storage_request_supp_data.merchant_id == "MerchantID" + assert json_hpp_card_storage_request_supp_data.account == "myAccount" + assert json_hpp_card_storage_request_supp_data.order_id == "OrderID" + assert json_hpp_card_storage_request_supp_data.amount == "100" + assert json_hpp_card_storage_request_supp_data.currency == "EUR" + assert json_hpp_card_storage_request_supp_data.timestamp == "20990101120000" + assert json_hpp_card_storage_request_supp_data.sha1hash == "5d8f05abd618e50db4861a61cc940112786474cf" + assert json_hpp_card_storage_request_supp_data.auto_settle_flag == "1" comment1 = "a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | =" - assert json_hpp_card_storage_request_supplementary_data.comment1 == comment1 - assert json_hpp_card_storage_request_supplementary_data.comment2 == "Comment Two" - assert json_hpp_card_storage_request_supplementary_data.shipping_code == "56|987" - assert json_hpp_card_storage_request_supplementary_data.shipping_co == "IRELAND" - assert json_hpp_card_storage_request_supplementary_data.billing_code == "123|56" - assert json_hpp_card_storage_request_supplementary_data.billing_co == "IRELAND" - assert json_hpp_card_storage_request_supplementary_data.cust_num == "123456" - assert json_hpp_card_storage_request_supplementary_data.var_ref == "VariableRef" - assert json_hpp_card_storage_request_supplementary_data.prod_id == "ProductID" - assert json_hpp_card_storage_request_supplementary_data.hpp_lang == "EN" - assert json_hpp_card_storage_request_supplementary_data.card_payment_button == "Submit Payment" - assert json_hpp_card_storage_request_supplementary_data.card_storage_enable == "1" - assert json_hpp_card_storage_request_supplementary_data.offer_save_card == "1" - assert json_hpp_card_storage_request_supplementary_data.payer_ref == "PayerRef" - assert json_hpp_card_storage_request_supplementary_data.pmt_ref == "PaymentRef" - assert json_hpp_card_storage_request_supplementary_data.payer_exist == "1" - assert isinstance(json_hpp_card_storage_request_supplementary_data.supplementary_data, dict) - assert json_hpp_card_storage_request_supplementary_data.supplementary_data['supplementary_1'] == "Supp1" - assert json_hpp_card_storage_request_supplementary_data.supplementary_data['supplementary_2'] == "Supp2" - assert json_hpp_card_storage_request_supplementary_data.supplementary_data['supplementary_3'] == "Supp3" - assert json_hpp_card_storage_request_supplementary_data.supplementary_data['supplementary_4'] == "Supp4" + assert json_hpp_card_storage_request_supp_data.comment1 == comment1 + assert json_hpp_card_storage_request_supp_data.comment2 == "Comment Two" + assert json_hpp_card_storage_request_supp_data.shipping_code == "56|987" + assert json_hpp_card_storage_request_supp_data.shipping_co == "IRELAND" + assert json_hpp_card_storage_request_supp_data.billing_code == "123|56" + assert json_hpp_card_storage_request_supp_data.billing_co == "IRELAND" + assert json_hpp_card_storage_request_supp_data.cust_num == "123456" + assert json_hpp_card_storage_request_supp_data.var_ref == "VariableRef" + assert json_hpp_card_storage_request_supp_data.prod_id == "ProductID" + assert json_hpp_card_storage_request_supp_data.hpp_lang == "EN" + assert json_hpp_card_storage_request_supp_data.card_payment_button == "Submit Payment" + assert json_hpp_card_storage_request_supp_data.card_storage_enable == "1" + assert json_hpp_card_storage_request_supp_data.offer_save_card == "1" + assert json_hpp_card_storage_request_supp_data.payer_ref == "PayerRef" + assert json_hpp_card_storage_request_supp_data.pmt_ref == "PaymentRef" + assert json_hpp_card_storage_request_supp_data.payer_exist == "1" + assert isinstance(json_hpp_card_storage_request_supp_data.supplementary_data, dict) + assert json_hpp_card_storage_request_supp_data.supplementary_data['SUPPLEMENTARY_1'] == "Supp1" + assert json_hpp_card_storage_request_supp_data.supplementary_data['SUPPLEMENTARY_2'] == "Supp2" + assert json_hpp_card_storage_request_supp_data.supplementary_data['SUPPLEMENTARY_3'] == "Supp3" + assert json_hpp_card_storage_request_supp_data.supplementary_data['SUPPLEMENTARY_4'] == "Supp4" + + def test_to_json_hpp_card_storage_request_supp_data(self, json_hpp_card_storage_request_supp_data): + """ + Test CardStorageRequest with supplementary data () generated to JSON + :param json_hpp_card_storage_request_supp_data: CardStorageRequest + """ + assert isinstance(json_hpp_card_storage_request_supp_data, CardStorageRequest) + json_base64_request = json.loads(JsonUtils.to_json(json_hpp_card_storage_request_supp_data, 'utf-8', True)) + assert isinstance(json_base64_request, dict) + + assert json_base64_request.get('AUTO_SETTLE_FLAG') == 'MQ==' + assert json_base64_request.get('CURRENCY') == 'RVVS' + assert json_base64_request.get('PROD_ID') == 'UHJvZHVjdElE' + assert json_base64_request.get('SHIPPING_CO') == 'SVJFTEFORA==' + assert json_base64_request.get('MERCHANT_ID') == 'TWVyY2hhbnRJRA==' + assert json_base64_request.get('ORDER_ID') == 'T3JkZXJJRA==' + assert json_base64_request.get('PAYER_EXIST') == 'MQ==' + assert json_base64_request.get('PMT_REF') == 'UGF5bWVudFJlZg==' + assert json_base64_request.get('AMOUNT') == 'MTAw' + assert json_base64_request.get('CUST_NUM') == 'MTIzNDU2' + assert json_base64_request.get('COMMENT2') == 'Q29tbWVudCBUd28=' + assert json_base64_request.get('OFFER_SAVE_CARD') == 'MQ==' + assert json_base64_request.get('SHA1HASH') == 'NWQ4ZjA1YWJkNjE4ZTUwZGI0ODYxYTYxY2M5NDAxMTI3ODY0NzRjZg==' + assert json_base64_request.get('SHIPPING_CODE') == 'NTZ8OTg3' + assert json_base64_request.get('CARD_PAYMENT_BUTTON') == 'U3VibWl0IFBheW1lbnQ=' + assert json_base64_request.get('HPP_LANG') == 'RU4=' + assert json_base64_request.get('PAYER_REF') == 'UGF5ZXJSZWY=' + assert json_base64_request.get('ACCOUNT') == 'bXlBY2NvdW50' + comment = 'YS16IEEtWiAwLTkgJyAiLCArIOKAnOKAnSAuXyAtICYgXCAvIEAgISA/ICUgKCApKiA6IMKjICQgJiDigqwgIyBbIF0gfCA9' + assert json_base64_request.get('COMMENT1') == comment + assert json_base64_request.get('VAR_REF') == 'VmFyaWFibGVSZWY=' + assert json_base64_request.get('BILLING_CODE') == 'MTIzfDU2' + assert json_base64_request.get('CARD_STORAGE_ENABLE') == 'MQ==' + assert json_base64_request.get('TIMESTAMP') == 'MjA5OTAxMDExMjAwMDA=' + assert json_base64_request.get('BILLING_CO') == 'SVJFTEFORA==' + assert json_base64_request.get('SUPPLEMENTARY_1') == 'U3VwcDE=' + assert json_base64_request.get('SUPPLEMENTARY_2') == 'U3VwcDI=' + assert json_base64_request.get('SUPPLEMENTARY_3') == 'U3VwcDM=' + assert json_base64_request.get('SUPPLEMENTARY_4') == 'U3VwcDQ=' def test_from_json_hpp_card_storage_request_encoded(self, json_hpp_card_storage_request_encoded): """ @@ -193,4 +339,3 @@ def test_from_json_hpp_card_storage_request_encoded(self, json_hpp_card_storage_ assert json_hpp_card_storage_request_encoded.offer_save_card == "1" assert json_hpp_card_storage_request_encoded.payer_exist == "0" assert isinstance(json_hpp_card_storage_request_encoded.supplementary_data, dict) - assert json_hpp_card_storage_request_encoded.supplementary_data['return_tss'] == "0" diff --git a/addonpayments/hpp/tests/utils.py b/addonpayments/hpp/tests/utils.py index 99ca80c..529b48b 100644 --- a/addonpayments/hpp/tests/utils.py +++ b/addonpayments/hpp/tests/utils.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import os MERCHANT_ID = 'merchant' diff --git a/addonpayments/hpp/utils.py b/addonpayments/hpp/utils.py index 435453d..4ac7911 100644 --- a/addonpayments/hpp/utils.py +++ b/addonpayments/hpp/utils.py @@ -1,8 +1,12 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import base64 import json +import six + from addonpayments.hpp.card_storage.requests import CardStorageRequest from addonpayments.hpp.payment.requests import PaymentRequest from addonpayments.hpp.common.responses import HppResponse @@ -39,7 +43,7 @@ def from_json_hpp_request(json_hpp_request, charset, encoded=False): :param encoded: bool :return: HppRequest """ - obj_request = json.load(json_hpp_request) + obj_request = json.loads(json_hpp_request) if encoded: obj_request = JsonUtils.decode(obj_request, charset) @@ -49,7 +53,8 @@ def from_json_hpp_request(json_hpp_request, charset, encoded=False): dict_request = {} supplementary_data = {} - for key, value in obj_request.items(): + + for key, value in six.iteritems(obj_request): key_hpp = key.lower() is_supplementary_data = False if is_card_storage: @@ -59,7 +64,7 @@ def from_json_hpp_request(json_hpp_request, charset, encoded=False): if not hasattr(PaymentRequest, key_hpp): is_supplementary_data = True if is_supplementary_data: - supplementary_data[key_hpp] = value + supplementary_data[key] = value else: dict_request[key_hpp] = value if supplementary_data: @@ -91,8 +96,8 @@ def encode(hpp_dict, charset='utf-8'): :param charset: string :return: dict """ - for key, value in hpp_dict.items(): - b64_value = base64.b64encode(bytes(str(value), charset)) + for key, value in six.iteritems(hpp_dict): + b64_value = base64.b64encode(six.binary_type(six.text_type(value).encode(charset))) hpp_dict[key] = b64_value.decode(charset) return hpp_dict @@ -103,8 +108,8 @@ def decode(hpp_dict, charset='utf-8'): :param hpp_dict: dict :param charset: string """ - for key, value in hpp_dict.items(): - hpp_dict[key] = str(base64.b64decode(value), charset) + for key, value in six.iteritems(hpp_dict): + hpp_dict[key] = six.text_type(base64.b64decode(value), charset) return hpp_dict @staticmethod @@ -114,5 +119,5 @@ def normalize_response(obj_response): :type obj_response: dict :return: HppResponse """ - obj_response = {key.lower(): value for key, value in obj_response.items()} + obj_response = {key.lower(): value for key, value in six.iteritems(obj_response)} return HppResponse(**obj_response) diff --git a/addonpayments/hpp/validators.py b/addonpayments/hpp/validators.py index ba39653..0a8d018 100644 --- a/addonpayments/hpp/validators.py +++ b/addonpayments/hpp/validators.py @@ -1,5 +1,9 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + +import six + from addonpayments.utils import ValidateUtils as Validate @@ -192,10 +196,10 @@ def supplementary_data(instance, attribute, value): try: Validate.validate_dict(attribute.name, value) # If value is a dict, convert keys and values to string - value = ''.join(['{0}{1}'.format(k, v) for k, v in value.items()]) + value = ''.join(['{0}{1}'.format(k, v) for k, v in six.iteritems(value)]) except ValueError: Validate.validate_str(attribute.name, value) - Validate.validate_length_range(attribute.name, str(value), 0, 255) + Validate.validate_length_range(attribute.name, six.text_type(value), 0, 255) Validate.validate_regex( attribute.name, value, diff --git a/addonpayments/logger.py b/addonpayments/logger.py index 4ac6e8d..5f054a5 100644 --- a/addonpayments/logger.py +++ b/addonpayments/logger.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import logging diff --git a/addonpayments/mixins.py b/addonpayments/mixins.py index cf36e75..e61d0cf 100644 --- a/addonpayments/mixins.py +++ b/addonpayments/mixins.py @@ -1,5 +1,8 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + +import six from addonpayments.utils import GenerationUtils @@ -68,4 +71,6 @@ def to_dict(self): Return the class attributes in a dictionary :return: dict """ - return {key: self.set_flags(key, value) for key, value in self.__dict__.items() if self.set_flags(key, value)} + return { + key: self.set_flags(key, value) for key, value in six.iteritems(self.__dict__) if self.set_flags(key, value) + } diff --git a/addonpayments/responses.py b/addonpayments/responses.py index d13f405..6531234 100644 --- a/addonpayments/responses.py +++ b/addonpayments/responses.py @@ -1,5 +1,9 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + +import six + from addonpayments.mixins import HashMixin @@ -30,7 +34,7 @@ def to_dict(self): return the data response as a dictionary :return: dict """ - return {key: value for key, value in self.__dict__.items()} + return {key: value for key, value in six.iteritems(self.__dict__)} def hash(self, secret): """ diff --git a/addonpayments/utils.py b/addonpayments/utils.py index 7aa15fd..bd29188 100644 --- a/addonpayments/utils.py +++ b/addonpayments/utils.py @@ -1,6 +1,9 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + import re +import six import uuid import hashlib from datetime import datetime @@ -29,9 +32,9 @@ def generate_hash(to_hash, secret): :return: string """ # Step 1: With the SHA-1 algorithm, obtain the hash value of a string composed of the requested values. - to_hash_first_pass = hashlib.sha1(bytes("{}".format(to_hash), encoding="UTF-8")).hexdigest() + to_hash_first_pass = hashlib.sha1(six.binary_type(to_hash.encode('utf-8'))).hexdigest() # Step 2: Concatenate the hash value chain with the shared secret. - return hashlib.sha1(bytes("{}.{}".format(to_hash_first_pass, secret), encoding="UTF-8")).hexdigest() + return hashlib.sha1(six.binary_type("{}.{}".format(to_hash_first_pass, secret).encode('utf-8'))).hexdigest() def generate_order_id(self): """ @@ -43,7 +46,7 @@ def generate_order_id(self): def generate_timestamp(self): """ - Generate the current datetimestamp in the string format (YYYYMMDDHHSS) required in a request. + Generate the current date timestamp in the string format (YYYYMMDDHHSS) required in a request. :return: string """ return datetime.now().strftime(self.date_format) @@ -90,7 +93,7 @@ def validate_str(name, value): :param name: string :param value: """ - if not isinstance(value, str): + if not isinstance(value, six.string_types): raise ValueError("{} must be string".format(name)) @staticmethod diff --git a/addonpayments/validators.py b/addonpayments/validators.py index 67f4a6a..e35dd6f 100644 --- a/addonpayments/validators.py +++ b/addonpayments/validators.py @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- +from __future__ import absolute_import, unicode_literals + from addonpayments.utils import ValidateUtils as Validate diff --git a/requirements.txt b/requirements.txt index 959fa03..8bc47eb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,13 +1,27 @@ --e git+git@gitlab.apsl.net:addonpayments/addonpayments-sdk-python.git@8014e0137721442a268b681f76486f13bde8776d#egg=addonpayments_sdk_python +apipkg==1.4 appdirs==1.4.2 +attr==0.2.0 attrs==16.3.0 +eradicate==0.1.6 +execnet==1.4.1 +flake8==3.3.0 +mccabe==0.6.1 packaging==16.8 pluggy==0.4.0 py==1.4.32 +pycodestyle==2.3.1 +pyflakes==1.5.0 pyparsing==2.1.10 +pytest==3.0.6 +pytest-cache==1.0 +pytest-eradicate==0.0.3 +pytest-flake8==0.8.1 +pytest-sugar==0.8.0 python-decouple==3.0 requests==2.13.0 six==1.10.0 +termcolor==1.1.0 tox==2.6.0 virtualenv==15.1.0 xmltodict==0.10.2 +future==0.16.0 diff --git a/setup.py b/setup.py index df74f68..3ca25ae 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,8 @@ -import os -import re -import codecs +# -*- encoding: utf-8 -*- + +# import os +# import re +# import codecs try: from setuptools import setup, find_packages @@ -12,24 +14,27 @@ def get_version(package): """ Return package version as listed in `__version__` in `init.py`. """ - init_py = codecs.open(os.path.join(package, '__init__.py'), encoding='utf-8').read() - return re.search("^__version__ = ['\"]([^'\"]+)['\"]", init_py, re.MULTILINE).group(1) + return "0.1" + # init_py = codecs.open(os.path.abspath(os.path.join(package, '__init__.py')), encoding='utf-8').read() + # return re.search("^__version__ = ['\"]([^'\"]+)['\"]", init_py, re.MULTILINE).group(1) def get_author(package): """ Return package author as listed in `__author__` in `init.py`. """ - init_py = codecs.open(os.path.join(package, '__init__.py'), encoding='utf-8').read() - return re.search("^__author__ = ['\"]([^'\"]+)['\"]", init_py, re.MULTILINE).group(1) + return "Marc Galofré" + # init_py = codecs.open(os.path.abspath(os.path.join(package, '__init__.py')), encoding='utf-8').read() + # return re.search("^__author__ = ['\"]([^'\"]+)['\"]", init_py, re.MULTILINE).group(1) def get_email(package): """ Return package email as listed in `__email__` in `init.py`. """ - init_py = codecs.open(os.path.join(package, '__init__.py'), encoding='utf-8').read() - return re.search("^__email__ = ['\"]([^'\"]+)['\"]", init_py, re.MULTILINE).group(1) + return "mgalofre@apsl.net" + # init_py = codecs.open(os.path.abspath(os.path.join(package, '__init__.py')), encoding='utf-8').read() + # return re.search("^__email__ = ['\"]([^'\"]+)['\"]", init_py, re.MULTILINE).group(1) setup( @@ -39,12 +44,14 @@ def get_email(package): include_package_data=True, keywords="addonpayments sdk python hpp api", description='A SDK Addonpayments implemented with Python.', - long_description=codecs.open(os.path.join(os.path.dirname(__file__), 'README.rst'), encoding='utf-8').read(), + # long_description=codecs.open(os.path.join(os.path.dirname(__file__), 'README.rst'), encoding='utf-8').read(), + long_description='', install_requires=[ 'python-decouple', 'attrs', 'xmltodict', 'requests', + 'future' ], url='https://gitlab.apsl.net/addonpayments/addonpayments-sdk-python', author=get_author('addonpayments'), diff --git a/tox.ini b/tox.ini index 2fc2ece..e822d58 100644 --- a/tox.ini +++ b/tox.ini @@ -12,8 +12,6 @@ commands = basepython = py27: python2.7 - py33: python3.3 - py34: python3.4 py35: python3.5 deps = @@ -21,6 +19,8 @@ deps = pytest-sugar==0.8.0 pytest-flake8==0.8.1 pytest-eradicate==0.0.3 + python-decouple==3.0.0 + future==0.16.0 [testenv:flake8] basepython = python3.5