Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mgalofre committed Mar 6, 2017
2 parents 82bd601 + 14955e0 commit 3d6b8bc
Show file tree
Hide file tree
Showing 45 changed files with 353 additions and 97 deletions.
2 changes: 2 additions & 0 deletions addonpayments/api/card_storage/requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import attr
from attr import ib as Field

Expand Down
4 changes: 3 additions & 1 deletion addonpayments/api/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import requests
import attr
from decouple import config
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/common/requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import attr
from attr import ib as Field

Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/common/responses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

from addonpayments.responses import SdkResponse


Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/dcc/requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import attr
from attr import ib as Field

Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/elements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import attr
from attr import ib as Field

Expand Down
5 changes: 4 additions & 1 deletion addonpayments/api/mixins.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/payment/requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import attr
from attr import ib as Field

Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import pytest
from decouple import config

Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/tests/tests/test_card_storage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import pytest

from addonpayments.api.tests.conftest import BaseTest
Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/tests/tests/test_dcc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import pytest

from addonpayments.api.tests.conftest import BaseTest
Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/tests/tests/test_payment.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/tests/tests/test_three_ds.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import pytest

from addonpayments.api.tests.conftest import BaseTest
Expand Down
3 changes: 3 additions & 0 deletions addonpayments/api/tests/tests/test_transaction_management.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import pytest

from addonpayments.api.tests.conftest import BaseTest
Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/three_ds/requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import attr
from attr import ib as Field

Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/three_ds/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

from addonpayments.utils import ValidateUtils as Validate


Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/transaction_management/requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import attr
from attr import ib as Field

Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/transaction_management/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

from addonpayments.utils import ValidateUtils as Validate


Expand Down
5 changes: 4 additions & 1 deletion addonpayments/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import six
import xmltodict
import json

Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions addonpayments/api/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

from addonpayments.utils import ValidateUtils as Validate


Expand Down
2 changes: 2 additions & 0 deletions addonpayments/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals


class SdkError(Exception):
"""
Expand Down
2 changes: 2 additions & 0 deletions addonpayments/hpp/card_storage/requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import attr
from attr import ib as Field

Expand Down
2 changes: 2 additions & 0 deletions addonpayments/hpp/card_storage/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

from addonpayments.utils import ValidateUtils as Validate


Expand Down
19 changes: 11 additions & 8 deletions addonpayments/hpp/common/requests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions addonpayments/hpp/common/responses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

from addonpayments.responses import SdkResponse


Expand Down
5 changes: 4 additions & 1 deletion addonpayments/hpp/hpp.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
2 changes: 2 additions & 0 deletions addonpayments/hpp/payment/requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import attr

from addonpayments.hpp.common.requests import HppRequest
Expand Down
29 changes: 16 additions & 13 deletions addonpayments/hpp/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"AUTO_SETTLE_FLAG": "MQ==",
"COMMENT1": "Q29tbWVudCBUd28=",
"COMMENT2": "Q29tbWVudCBUd28=",
"RETURN_TSS": "MA==",
"SHIPPING_CODE": "NTZ8OTg3",
"SHIPPING_CO": "SVJFTEFORA==",
"BILLING_CODE": "MTIzfDU2",
Expand Down
1 change: 0 additions & 1 deletion addonpayments/hpp/tests/samples/hpp_payment_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions addonpayments/hpp/tests/tests/test_generation_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import re

from addonpayments.utils import GenerationUtils
Expand Down
2 changes: 2 additions & 0 deletions addonpayments/hpp/tests/tests/test_hpp_request.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-

from __future__ import absolute_import, unicode_literals


class TestHppRequest:
secret = "mysecret"
Expand Down
Loading

0 comments on commit 3d6b8bc

Please sign in to comment.