From 4a4a6dff259e96f596875343b66ab908a3649985 Mon Sep 17 00:00:00 2001 From: paularabatzis Date: Tue, 8 Jun 2021 16:04:01 -0400 Subject: [PATCH 1/2] US53062 belk updates to allow headers and remove username/password --- opp/core.py | 29 ++++++++++++++++------------- opp/facade.py | 30 ++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/opp/core.py b/opp/core.py index 1229f8a..7428976 100644 --- a/opp/core.py +++ b/opp/core.py @@ -76,7 +76,7 @@ def delete(self, **kwargs): class API(object): - def __init__(self, **auth_params): + def __init__(self, headers=None, **auth_params): """ @@ -84,7 +84,7 @@ def __init__(self, **auth_params): :type auth_params: object """ url = opp.config.config.current_url - self.http_client = HTTPClient(url, auth_params) + self.http_client = HTTPClient(url, auth_params, headers) def payments(self, payment_id=None): return Payments(http_client=self.http_client, payment_id=payment_id) @@ -97,13 +97,14 @@ def registrations(self, registration_id=None): class HTTPClient(object): - def __init__(self, base_url, auth_params): + def __init__(self, base_url, auth_params, headers=None): """Initialize a new opp connection. Requires user name and password.""" logger.debug("START: OPP API connection with BASE_URL: {0}".format(base_url)) self.base_url = base_url self.session = Session() self.session.verify = opp.config.config.ssl_verify self.auth_params = auth_params + self.headers = headers self.operations = dict(GET=self.get, POST=self.post, PUT=self.put, DELETE=self.delete) # for internal usage self.response = None @@ -126,7 +127,7 @@ def __call__(self, request_type, params, url, return_type): if self.auth_params: params.update(self.auth_params) try: - result = self.operations[request_type](params, url, return_type) + result = self.operations[request_type](params, url, return_type, headers=self.headers) logger.debug("SUCCESS: {0} {1}".format(request_type, url)) return result except ValueError as v: @@ -138,7 +139,7 @@ def __call__(self, request_type, params, url, return_type): else: raise ValueError() - def put(self, params, url, return_type): + def put(self, params, url, return_type, headers=None): """ :param params: @@ -148,9 +149,10 @@ def put(self, params, url, return_type): """ return self._check_response(self.session.put(self.base_url + url, params, timeout=opp.config.config.request_timeout, - hooks=dict(response=self._request_callback), ).json(), return_type) + hooks=dict(response=self._request_callback), headers=headers).json(), + return_type) - def post(self, params, url, return_type): + def post(self, params, url, return_type, headers=None): """ :param params: @@ -159,10 +161,10 @@ def post(self, params, url, return_type): :return: """ json = self.session.post(self.base_url + url, params, timeout=opp.config.config.request_timeout, - hooks=dict(response=self._request_callback)).json() + hooks=dict(response=self._request_callback), headers=headers).json() return self._check_response(json, return_type) - def delete(self, params, url, return_type): + def delete(self, params, url, return_type, headers=None): """ :param params: @@ -172,10 +174,10 @@ def delete(self, params, url, return_type): """ return self._check_response(self.session.delete(self.base_url + url, params=params, timeout=opp.config.config.request_timeout, - hooks=dict(response=self._request_callback)).json(), - return_type) + hooks=dict(response=self._request_callback), + headers=headers).json(), return_type) - def get(self, params, url, return_type): + def get(self, params, url, return_type, headers=None): """ :param params: @@ -185,7 +187,8 @@ def get(self, params, url, return_type): """ return self._check_response(self.session.get(self.base_url + url, params=params, timeout=opp.config.config.request_timeout, - hooks=dict(response=self._request_callback)).json(), return_type) + hooks=dict(response=self._request_callback), + headers=headers).json(), return_type) def _request_callback(self, r, *args, **kwargs): """ diff --git a/opp/facade.py b/opp/facade.py index e48d90a..a112d13 100644 --- a/opp/facade.py +++ b/opp/facade.py @@ -8,23 +8,31 @@ class Authentication(object): - def __init__(self, user_id=None, password=None, entity_id=None): + def __init__(self, entity_id=None): """ :rtype : object - :param user_id: - :param password: :param entity_id: """ - self.user_id = user_id - self.password = password self.entity_id = entity_id def to_params(self): - return {"authentication.userId": self.user_id, - "authentication.password": self.password, - "authentication.entityId": self.entity_id} + return {"entityId": self.entity_id} + + +class Headers(object): + def __init__(self, bearer_token=None): + """ + + :rtype: object + :param bearer_token: + """'' + self.bearer_token = bearer_token + + def to_params(self): + return {"Authorization": self.bearer_token} + class BasicPayment(object): @@ -771,15 +779,17 @@ def delete(self): class API(object): - def __init__(self, authentication=None): + def __init__(self, authentication=None, headers=None): """ :param authentication: + :param headers: :rtype : object """ self.authentication = authentication - self.core = opp.core.API(**authentication.to_params()) + self.headers = headers + self.core = opp.core.API(headers.to_params(), **authentication.to_params()) def refunds(self, payment_id=None): return Refunds(payment_id=payment_id, core=self.core) From d0b5f17355566709faa311935392626811e8aa1a Mon Sep 17 00:00:00 2001 From: paularabatzis Date: Mon, 21 Jun 2021 09:57:36 -0400 Subject: [PATCH 2/2] Updating version number --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index ad6a970..59bf726 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='opp', - version='1.3.1', + version='1.3.2', description='Python wrapper for OPP', author='PAY.ON', author_email='opp@payon.com', @@ -30,5 +30,5 @@ 'Topic :: Software Development :: Libraries :: Python Modules', ], install_requires=install_requires, - download_url='https://github.com/OpenPaymentPlatform/python/tarball/1.3.1' + download_url='https://github.com/OpenPaymentPlatform/python/tarball/1.3.2' )