Skip to content

Commit 1d247b5

Browse files
Merge pull request #88 from jyothish6190/msue-123
feat: Update client libraries with PSP Merchant Management API
2 parents a281d6f + af23596 commit 1d247b5

File tree

4 files changed

+407
-126
lines changed

4 files changed

+407
-126
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
5.2.0 2022-11-07
2+
- Update PSP Merchant Management API
3+
14
5.1.0 2022-06-22
25
- Added return_route_info query parameter
36
- Fixed decimal amount json serialization bug

sift/client.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,112 @@ def apply_content_decision(self, user_id, content_id, properties, timeout=None):
736736
except requests.exceptions.RequestException as e:
737737
raise ApiException(str(e), url)
738738

739+
def create_psp_merchant_profile(self, properties, timeout=None):
740+
"""Create a new PSP Merchant profile
741+
Args:
742+
properties: A dict of merchant profile data.
743+
Returns
744+
A sift.client.Response object if the call succeeded, else raises an ApiException
745+
"""
746+
747+
if timeout is None:
748+
timeout = self.timeout
749+
750+
url = self._psp_merchant_url(self.account_id)
751+
752+
try:
753+
return Response(self.session.post(
754+
url,
755+
data=json.dumps(properties),
756+
auth=requests.auth.HTTPBasicAuth(self.api_key, ''),
757+
headers={'Content-type': 'application/json',
758+
'Accept': '*/*',
759+
'User-Agent': self._user_agent()},
760+
timeout=timeout))
761+
762+
except requests.exceptions.RequestException as e:
763+
raise ApiException(str(e), url)
764+
765+
def update_psp_merchant_profile(self, merchant_id, properties, timeout=None):
766+
"""Update already existing PSP Merchant profile
767+
Args:
768+
merchant_id: id of merchant
769+
properties: A dict of merchant profile data.
770+
Returns
771+
A sift.client.Response object if the call succeeded, else raises an ApiException
772+
"""
773+
774+
if timeout is None:
775+
timeout = self.timeout
776+
777+
url = self._psp_merchant_id_url(self.account_id, merchant_id)
778+
779+
try:
780+
return Response(self.session.put(
781+
url,
782+
data=json.dumps(properties),
783+
auth=requests.auth.HTTPBasicAuth(self.api_key, ''),
784+
headers={'Content-type': 'application/json',
785+
'Accept': '*/*',
786+
'User-Agent': self._user_agent()},
787+
timeout=timeout))
788+
789+
except requests.exceptions.RequestException as e:
790+
raise ApiException(str(e), url)
791+
792+
def get_psp_merchant_profiles(self, batch_token=None, batch_size=None, timeout=None):
793+
"""Gets all PSP merchant profiles.
794+
795+
Returns:
796+
A sift.client.Response object if the call succeeded.
797+
Otherwise, raises an ApiException.
798+
"""
799+
800+
if timeout is None:
801+
timeout = self.timeout
802+
803+
url = self._psp_merchant_url(self.account_id)
804+
params = {}
805+
806+
if batch_size:
807+
params['batch_size'] = batch_size
808+
809+
if batch_token:
810+
params['batch_token'] = batch_token
811+
try:
812+
return Response(self.session.get(
813+
url,
814+
auth=requests.auth.HTTPBasicAuth(self.api_key, ''),
815+
headers={'User-Agent': self._user_agent()},
816+
params=params,
817+
timeout=timeout))
818+
819+
except requests.exceptions.RequestException as e:
820+
raise ApiException(str(e), url)
821+
822+
def get_a_psp_merchant_profile(self, merchant_id, timeout=None):
823+
"""Gets a PSP merchant profile using merchant id.
824+
825+
Returns:
826+
A sift.client.Response object if the call succeeded.
827+
Otherwise, raises an ApiException.
828+
"""
829+
830+
if timeout is None:
831+
timeout = self.timeout
832+
833+
url = self._psp_merchant_id_url(self.account_id, merchant_id)
834+
835+
try:
836+
return Response(self.session.get(
837+
url,
838+
auth=requests.auth.HTTPBasicAuth(self.api_key, ''),
839+
headers={'User-Agent': self._user_agent()},
840+
timeout=timeout))
841+
except requests.exceptions.RequestException as e:
842+
raise ApiException(str(e), url)
843+
844+
739845
def _user_agent(self):
740846
return 'SiftScience/v%s sift-python/%s' % (sift.version.API_VERSION, sift.version.VERSION)
741847

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

895+
def _psp_merchant_url(self, account_id):
896+
return (self.url + '/v3/accounts/%s/psp_management/merchants' %
897+
(_quote_path(account_id)))
898+
899+
def _psp_merchant_id_url(self, account_id, merchant_id):
900+
return (self.url + '/v3/accounts/%s/psp_management/merchants/%s' %
901+
(_quote_path(account_id), _quote_path(merchant_id)))
902+
789903

790904
class Response(object):
791905

sift/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VERSION = '5.1.0'
1+
VERSION = '5.2.0'
22
API_VERSION = '205'

0 commit comments

Comments
 (0)