From 9719ba5d0d07250c694e99295746d53adcf9303a Mon Sep 17 00:00:00 2001 From: Lubos Matl Date: Sun, 3 Jan 2021 14:37:44 +0100 Subject: [PATCH 1/2] Used zeep library --- .travis.yml | 8 +++++--- thepay/config.py | 2 +- thepay/data_api.py | 17 +++++++++++------ thepay/payment.py | 5 +++-- thepay/tests.py | 24 ++++++++++++++++-------- thepay/utils.py | 9 ++++----- 6 files changed, 40 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index 58c5973..642183c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,15 @@ language: python python: - - "2.7" + - "3.6" + - "3.7" + - "3.8" + - "3.9" # does not have headers provided, please ask https://launchpad.net/~pypy/+archive/ppa # maintainers to fix their pypy-dev package. # command to install dependencies install: - - pip install six - pip install pytz - - pip install suds + - pip install zeep - pip install coverage - pip install coveralls # command to run tests diff --git a/thepay/config.py b/thepay/config.py index 1925772..5d0e179 100644 --- a/thepay/config.py +++ b/thepay/config.py @@ -1,4 +1,4 @@ -class Config(object): +class Config: # ThePay API gate_url = 'https://www.thepay.cz/demo-gate/' diff --git a/thepay/data_api.py b/thepay/data_api.py index f41d22b..c3517fd 100644 --- a/thepay/data_api.py +++ b/thepay/data_api.py @@ -1,10 +1,11 @@ from collections import OrderedDict -import suds.client +from zeep import Client, Transport from thepay.utils import SignatureMixin class DataApi(SignatureMixin): + def __init__(self, config): """ @@ -16,21 +17,24 @@ def __init__(self, config): self.connect() def connect(self): - self.client = suds.client.Client(self.config.data_web_services_wsdl) + self.client = Client(self.config.data_web_services_wsdl, transport=self._get_transport()) + + def _get_transport(self): + return Transport() def get_payment_methods(self): params = self._sign_params(OrderedDict(( ('merchantId', self.config.merchant_id), ('accountId', self.config.account_id), )), self.config.data_api_password) - return self.client.service.getPaymentMethods(**params).methods[0] + return self.client.service.getPaymentMethods(**params).methods.method def get_payment_state(self, payment_id): params = self._sign_params(OrderedDict(( ('merchantId', self.config.merchant_id), ('paymentId', payment_id), )), self.config.data_api_password) - return int(self.client.service.getPaymentState(**params).state) + return self.client.service.getPaymentState(**params).state def get_payment(self, payment_id): params = self._sign_params(OrderedDict(( @@ -88,9 +92,10 @@ def get_payments(self, account_ids=None, value_from=None, value_to=None, created signed_params = self._sign_params(params, self.config.data_api_password) + factory = self.client.type_factory('ns0') + if params.get('searchParams', {}).get('accountId'): - account_id_array = self.client.factory.create('idArray') - account_id_array.id = params['searchParams']['accountId'] + account_id_array = factory.idArray(id=params['searchParams']['accountId']) params['searchParams']['accountId'] = account_id_array return self.client.service.getPayments(**signed_params) diff --git a/thepay/payment.py b/thepay/payment.py index 43513ee..810c196 100644 --- a/thepay/payment.py +++ b/thepay/payment.py @@ -1,6 +1,7 @@ from collections import OrderedDict import hashlib -from six.moves import urllib +from urllib.parse import urlencode + from decimal import Decimal from thepay.utils import SignatureMixin from thepay.exceptions import InvalidSignature, MissingParameter @@ -82,7 +83,7 @@ def get_create_url(self): :return: url-encoded string """ params = self._sign_params(self.get_params(), self.config.password) - return "{}?{}".format(self.config.gate_url, urllib.parse.urlencode(params)) + return "{}?{}".format(self.config.gate_url, urlencode(params)) class ReturnPayment(SignatureMixin): diff --git a/thepay/tests.py b/thepay/tests.py index ae8d06f..cd811e3 100644 --- a/thepay/tests.py +++ b/thepay/tests.py @@ -1,35 +1,41 @@ -from __future__ import print_function - from datetime import datetime, date from pytz import timezone +from urllib.parse import parse_qs + import unittest from thepay.config import Config from thepay.data_api import DataApi from thepay.payment import Payment, ReturnPayment -from six.moves import urllib from decimal import Decimal class DataApiTests(unittest.TestCase): + def setUp(self): super(DataApiTests, self).setUp() self.config = Config() self.data_api = DataApi(self.config) def test_methods(self): - self.assertEqual(self.data_api.get_payment_methods()[0].name, 'Platba kartou') + self.assertEqual(self.data_api.get_payment_methods()[0].name, 'Platba24') def test_payment_statue(self): - self.assertEqual(self.data_api.get_payment_state(1), 2) + id = self.data_api.get_payments().payments.payment[0].id + self.assertEqual(self.data_api.get_payment_state(id), 1) def test_payment(self): - self.assertEqual(self.data_api.get_payment(1).id, '1') + id = self.data_api.get_payments().payments.payment[0].id + self.assertEqual( + self.data_api.get_payment(id).id, + id + ) def test_payment_info(self): - self.data_api.get_payment_instructions(1) + id = self.data_api.get_payments().payments.payment[0].id + self.data_api.get_payment_instructions(id) def test_credentials(self): self.config.set_credentials(42, 43, 'test', 'test2') @@ -52,6 +58,7 @@ def test_payments(self): class PaymentTests(unittest.TestCase): + def setUp(self): self.config = Config() self.payment = Payment(self.config) @@ -85,12 +92,13 @@ def test_url(self): class ReturnPaymentTests(unittest.TestCase): + def setUp(self): self.config = Config() def test_data(self): params_str = 'merchantId=1&accountId=1&value=123.00¤cy=CZK&methodId=1&description=Order+123+payment&merchantData=Order+123&status=2&paymentId=34886&ipRating=&isOffline=0&needConfirm=0&signature=f38ff15cc17752a6d4035044a93deb06' - params = urllib.parse.parse_qs(params_str, keep_blank_values=True) + params = parse_qs(params_str, keep_blank_values=True) params = {key: value[0] for key, value in params.items()} payment = ReturnPayment(self.config, params) diff --git a/thepay/utils.py b/thepay/utils.py index 39f752d..167a4a6 100644 --- a/thepay/utils.py +++ b/thepay/utils.py @@ -1,9 +1,8 @@ import hashlib -import six from collections import OrderedDict -class SignatureMixin(object): +class SignatureMixin: def _build_query(self, params): results = [] @@ -11,10 +10,10 @@ def _build_query(self, params): if isinstance(val, dict): val = self._hash_param(self._build_query(val).encode('utf-8')) elif isinstance(val, (list, tuple)): - val = '|'.join(map(six.text_type, val)) + val = '|'.join(map(str, val)) else: - val = six.text_type(val) - results.append('='.join((six.text_type(key), val))) + val = str(val) + results.append('='.join((str(key), val))) return '&'.join(results) def _sign_params(self, params, password): From 60a31896945b6f35e443ea6a28f15751df13b0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Kulat=C3=BD?= Date: Tue, 25 Mar 2025 08:46:48 +0100 Subject: [PATCH 2/2] Fix InvalidConfigError error --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index b88034e..08aedd7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,2 @@ [metadata] -description-file = README.md +description_file = README.md