Skip to content

Commit

Permalink
Merge pull request #88 from jyothish6190/msue-123
Browse files Browse the repository at this point in the history
feat: Update client libraries with PSP Merchant Management API
  • Loading branch information
sbogolii-sift authored Nov 7, 2022
2 parents a281d6f + af23596 commit 1d247b5
Show file tree
Hide file tree
Showing 4 changed files with 407 additions and 126 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
5.2.0 2022-11-07
- Update PSP Merchant Management API

5.1.0 2022-06-22
- Added return_route_info query parameter
- Fixed decimal amount json serialization bug
Expand Down
114 changes: 114 additions & 0 deletions sift/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,112 @@ def apply_content_decision(self, user_id, content_id, properties, timeout=None):
except requests.exceptions.RequestException as e:
raise ApiException(str(e), url)

def create_psp_merchant_profile(self, properties, timeout=None):
"""Create a new PSP Merchant profile
Args:
properties: A dict of merchant profile data.
Returns
A sift.client.Response object if the call succeeded, else raises an ApiException
"""

if timeout is None:
timeout = self.timeout

url = self._psp_merchant_url(self.account_id)

try:
return Response(self.session.post(
url,
data=json.dumps(properties),
auth=requests.auth.HTTPBasicAuth(self.api_key, ''),
headers={'Content-type': 'application/json',
'Accept': '*/*',
'User-Agent': self._user_agent()},
timeout=timeout))

except requests.exceptions.RequestException as e:
raise ApiException(str(e), url)

def update_psp_merchant_profile(self, merchant_id, properties, timeout=None):
"""Update already existing PSP Merchant profile
Args:
merchant_id: id of merchant
properties: A dict of merchant profile data.
Returns
A sift.client.Response object if the call succeeded, else raises an ApiException
"""

if timeout is None:
timeout = self.timeout

url = self._psp_merchant_id_url(self.account_id, merchant_id)

try:
return Response(self.session.put(
url,
data=json.dumps(properties),
auth=requests.auth.HTTPBasicAuth(self.api_key, ''),
headers={'Content-type': 'application/json',
'Accept': '*/*',
'User-Agent': self._user_agent()},
timeout=timeout))

except requests.exceptions.RequestException as e:
raise ApiException(str(e), url)

def get_psp_merchant_profiles(self, batch_token=None, batch_size=None, timeout=None):
"""Gets all PSP merchant profiles.
Returns:
A sift.client.Response object if the call succeeded.
Otherwise, raises an ApiException.
"""

if timeout is None:
timeout = self.timeout

url = self._psp_merchant_url(self.account_id)
params = {}

if batch_size:
params['batch_size'] = batch_size

if batch_token:
params['batch_token'] = batch_token
try:
return Response(self.session.get(
url,
auth=requests.auth.HTTPBasicAuth(self.api_key, ''),
headers={'User-Agent': self._user_agent()},
params=params,
timeout=timeout))

except requests.exceptions.RequestException as e:
raise ApiException(str(e), url)

def get_a_psp_merchant_profile(self, merchant_id, timeout=None):
"""Gets a PSP merchant profile using merchant id.
Returns:
A sift.client.Response object if the call succeeded.
Otherwise, raises an ApiException.
"""

if timeout is None:
timeout = self.timeout

url = self._psp_merchant_id_url(self.account_id, merchant_id)

try:
return Response(self.session.get(
url,
auth=requests.auth.HTTPBasicAuth(self.api_key, ''),
headers={'User-Agent': self._user_agent()},
timeout=timeout))
except requests.exceptions.RequestException as e:
raise ApiException(str(e), url)


def _user_agent(self):
return 'SiftScience/v%s sift-python/%s' % (sift.version.API_VERSION, sift.version.VERSION)

Expand Down Expand Up @@ -786,6 +892,14 @@ def _content_apply_decisions_url(self, account_id, user_id, content_id):
return (API3_URL + '/v3/accounts/%s/users/%s/content/%s/decisions' %
(_quote_path(account_id), _quote_path(user_id), _quote_path(content_id)))

def _psp_merchant_url(self, account_id):
return (self.url + '/v3/accounts/%s/psp_management/merchants' %
(_quote_path(account_id)))

def _psp_merchant_id_url(self, account_id, merchant_id):
return (self.url + '/v3/accounts/%s/psp_management/merchants/%s' %
(_quote_path(account_id), _quote_path(merchant_id)))


class Response(object):

Expand Down
2 changes: 1 addition & 1 deletion sift/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION = '5.1.0'
VERSION = '5.2.0'
API_VERSION = '205'
Loading

0 comments on commit 1d247b5

Please sign in to comment.