Skip to content

Commit a7bdefb

Browse files
feature/INT-1632 SDK update - Latests changes in payments and other updates (#210)
* Python payments update * Small swagger alignments * New tests * get_access_token failures protect * Flake8 fixes * Python fields review and payment types update
1 parent 9573d30 commit a7bdefb

21 files changed

Lines changed: 961 additions & 15 deletions

‎checkout_sdk/accounts/accounts.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ class EntityFileRequest:
427427
purpose: FilePurpose
428428

429429

430+
class EntityRequirementUpdateRequest:
431+
value: object
432+
433+
430434
class EtagHeader:
431435
etag: str
432436

‎checkout_sdk/accounts/accounts_client.py‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from checkout_sdk.accounts.accounts import (
66
EtagHeader, OnboardEntityRequest, UpdateScheduleRequest, AccountsPaymentInstrument,
77
PaymentInstrumentRequest, PaymentInstrumentsQuery, UpdatePaymentInstrumentRequest,
8-
ReserveRuleRequest, EntityFileRequest
8+
ReserveRuleRequest, EntityFileRequest, EntityRequirementUpdateRequest
99
)
1010
from checkout_sdk.api_client import ApiClient
1111
from checkout_sdk.authorization_type import AuthorizationType
@@ -24,6 +24,7 @@ class AccountsClient(Client):
2424
__PAYMENT_INSTRUMENTS_PATH = 'payment-instruments'
2525
__MEMBERS_PATH = 'members'
2626
__RESERVE_RULES_PATH = 'reserve-rules'
27+
__REQUIREMENTS_PATH = 'requirements'
2728

2829
def __init__(self, api_client: ApiClient,
2930
files_client: ApiClient,
@@ -148,6 +149,24 @@ def update_reserve_rule(self, entity_id: str, reserve_rule_id: str, etag: str, u
148149
entity_id, self.__RESERVE_RULES_PATH, reserve_rule_id)
149150
return self._api_client.put(path, self._sdk_authorization(), update_request, headers=headers)
150151

152+
def get_entity_requirements(self, entity_id: str):
153+
return self._api_client.get(
154+
self.build_path(self.__ACCOUNTS_PATH, self.__ENTITIES_PATH, entity_id, self.__REQUIREMENTS_PATH),
155+
self._sdk_authorization())
156+
157+
def get_entity_requirement_details(self, entity_id: str, requirement_id: str):
158+
return self._api_client.get(
159+
self.build_path(self.__ACCOUNTS_PATH, self.__ENTITIES_PATH, entity_id,
160+
self.__REQUIREMENTS_PATH, requirement_id),
161+
self._sdk_authorization())
162+
163+
def resolve_entity_requirement(self, entity_id: str, requirement_id: str,
164+
request: EntityRequirementUpdateRequest):
165+
return self._api_client.put(
166+
self.build_path(self.__ACCOUNTS_PATH, self.__ENTITIES_PATH, entity_id,
167+
self.__REQUIREMENTS_PATH, requirement_id),
168+
self._sdk_authorization(), request)
169+
151170
def upload_entity_file(self, entity_id: str, entity_file_request: EntityFileRequest):
152171
return self.__files_client.post(
153172
self.build_path(self.__ENTITIES_PATH, entity_id, self.__FILES_PATH),

‎checkout_sdk/checkout_api.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from checkout_sdk.identities.applicants.applicants_client import ApplicantsClient
3737
from checkout_sdk.identities.identityverification.identityverification_client import IdentityVerificationClient
3838
from checkout_sdk.networktokens.network_tokens_client import NetworkTokensClient
39+
from checkout_sdk.onboardingsimulator.onboarding_simulator_client import OnboardingSimulatorClient
3940
from checkout_sdk.paymentmethods.payment_methods_client import PaymentMethodsClient
4041

4142

@@ -115,3 +116,5 @@ def __init__(self, configuration: CheckoutConfiguration):
115116
configuration=configuration)
116117
self.network_tokens = NetworkTokensClient(api_client=base_api_client, configuration=configuration)
117118
self.payment_methods = PaymentMethodsClient(api_client=base_api_client, configuration=configuration)
119+
self.onboarding_simulator = OnboardingSimulatorClient(api_client=base_api_client,
120+
configuration=configuration)

‎checkout_sdk/instruments/instruments.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,19 @@ def __init__(self):
7777
super().__init__(InstrumentType.BANK_ACCOUNT)
7878

7979

80+
class ProvisionNetworkToken:
81+
provision: bool
82+
83+
8084
class CreateCardInstrumentRequest(CreateInstrumentRequest):
8185
number: str
8286
expiry_month: int
8387
expiry_year: int
84-
network_token: str
85-
processing_channel_id: str
86-
entity_id: str
8788
account_holder: AccountHolder
89+
customer: CreateCustomerInstrumentRequest
90+
entity_id: str
91+
processing_channel_id: str
92+
network_token: ProvisionNetworkToken
8893

8994
def __init__(self):
9095
super().__init__(InstrumentType.CARD)

‎checkout_sdk/instruments/instruments_client.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def update(self, instrument_id: str, update_instrument_request: UpdateInstrument
3333
def delete(self, instrument_id: str):
3434
return self._api_client.delete(self.build_path(self.__INSTRUMENTS, instrument_id), self._sdk_authorization())
3535

36+
def revoke(self, instrument_id: str):
37+
return self._api_client.patch(
38+
self.build_path(self.__INSTRUMENTS, instrument_id, 'revoke'),
39+
self._sdk_authorization())
40+
3641
def get_bank_account_field_formatting(self, country: Country, currency: Currency,
3742
bank_account_field_query: BankAccountFieldQuery):
3843
return self._api_client.get(self.build_path(self.__BANK_VALIDATION_PATH, country, currency),

‎checkout_sdk/oauth_credentials.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ def get_access_token(self):
7777
auth=(self.__client_id, self.__client_secret))
7878
response.raise_for_status()
7979
except HTTPError as err:
80-
errors = json.loads(err.response.text)
81-
message = 'OAuth client_credentials authentication failed with error: ({})'.format(errors['error'])
80+
try:
81+
errors = json.loads(err.response.text)
82+
message = 'OAuth client_credentials authentication failed with error: ({})'.format(errors['error'])
83+
except (json.JSONDecodeError, KeyError):
84+
message = 'OAuth client_credentials authentication failed with status: ({})'.format(
85+
err.response.status_code)
8286
raise CheckoutAuthorizationException(message) from err
8387
except ConnectionError as err:
8488
raise CheckoutAuthorizationException(

‎checkout_sdk/onboardingsimulator/__init__.py‎

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import absolute_import
2+
3+
from enum import Enum
4+
5+
6+
class SimulatorEntityStatus(str, Enum):
7+
DRAFT = 'draft'
8+
REQUIREMENTS_DUE = 'requirements_due'
9+
PENDING = 'pending'
10+
ACTIVE = 'active'
11+
RESTRICTED = 'restricted'
12+
REJECTED = 'rejected'
13+
INACTIVE = 'inactive'
14+
15+
16+
class SimulatorSetRequirementsDueRequest:
17+
fields: list # list of str
18+
19+
20+
class SimulatorSetStatusRequest:
21+
status: SimulatorEntityStatus
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from __future__ import absolute_import
2+
3+
from checkout_sdk.api_client import ApiClient
4+
from checkout_sdk.authorization_type import AuthorizationType
5+
from checkout_sdk.checkout_configuration import CheckoutConfiguration
6+
from checkout_sdk.client import Client
7+
from checkout_sdk.onboardingsimulator.onboarding_simulator import (
8+
SimulatorSetRequirementsDueRequest,
9+
SimulatorSetStatusRequest
10+
)
11+
12+
13+
class OnboardingSimulatorClient(Client):
14+
__SIMULATE_PATH = 'simulate'
15+
__ENTITIES_PATH = 'entities'
16+
__REQUIREMENTS_DUE_PATH = 'requirements-due'
17+
__SCENARIOS_PATH = 'scenarios'
18+
__STATUS_PATH = 'status'
19+
20+
def __init__(self, api_client: ApiClient, configuration: CheckoutConfiguration):
21+
super().__init__(api_client=api_client,
22+
configuration=configuration,
23+
authorization_type=AuthorizationType.OAUTH)
24+
25+
def set_requirements_due(self, entity_id: str, request: SimulatorSetRequirementsDueRequest):
26+
return self._api_client.post(
27+
self.build_path(self.__SIMULATE_PATH, self.__ENTITIES_PATH, entity_id,
28+
self.__REQUIREMENTS_DUE_PATH),
29+
self._sdk_authorization(), request)
30+
31+
def run_scenario(self, entity_id: str, scenario_id: str):
32+
return self._api_client.post(
33+
self.build_path(self.__SIMULATE_PATH, self.__ENTITIES_PATH, entity_id,
34+
self.__SCENARIOS_PATH, scenario_id),
35+
self._sdk_authorization())
36+
37+
def set_entity_status(self, entity_id: str, request: SimulatorSetStatusRequest):
38+
return self._api_client.post(
39+
self.build_path(self.__SIMULATE_PATH, self.__ENTITIES_PATH, entity_id,
40+
self.__STATUS_PATH),
41+
self._sdk_authorization(), request)
42+
43+
def list_available_requirements(self):
44+
return self._api_client.get(
45+
self.build_path(self.__SIMULATE_PATH, self.__REQUIREMENTS_DUE_PATH),
46+
self._sdk_authorization())
47+
48+
def list_scenarios(self):
49+
return self._api_client.get(
50+
self.build_path(self.__SIMULATE_PATH, self.__SCENARIOS_PATH),
51+
self._sdk_authorization())

‎checkout_sdk/payments/sessions/sessions.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,16 @@ class PaymentSessionWithPaymentRequest:
284284
capture_on: datetime
285285

286286

287+
class PaymentInterfacesProcessingBase:
288+
pan_preference: str
289+
provision_network_token: bool
290+
291+
287292
class SubmitPaymentSessionRequest:
288293
session_data: str
289294
amount: int
290295
currency: Currency
291296
reference: str
292-
description: str
293297
items: list # Item
294298
three_ds: ThreeDsRequest
295299
ip_address: str
@@ -308,3 +312,4 @@ class SubmitPaymentSessionRequest:
308312
sender: PaymentSender
309313
shipping: ShippingDetails
310314
success_url: str
315+
processing: PaymentInterfacesProcessingBase

0 commit comments

Comments
 (0)