Skip to content

Commit 5b21089

Browse files
Knet Updates. Workflow updates (#170)
1 parent 5c5fe23 commit 5b21089

10 files changed

+140
-7
lines changed

checkout_sdk/payments/payment_apm.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
from checkout_sdk.common.common import Address, AccountHolder
66
from checkout_sdk.common.enums import PaymentSourceType, Country, Currency
7-
from checkout_sdk.payments.payments import PaymentRequestSource, BillingPlan
7+
from checkout_sdk.payments.payments import PaymentRequestSource, BillingPlan, PaymentMethodDetails
8+
from checkout_sdk.tokens.tokens import ApplePayTokenData
89

910

1011
class RequestIdealSource(PaymentRequestSource):
@@ -151,6 +152,9 @@ class RequestKnetSource(PaymentRequestSource):
151152
user_defined_field5: str
152153
card_token: str
153154
ptlf: str
155+
token_type: str
156+
token_data: ApplePayTokenData
157+
payment_method_details: PaymentMethodDetails
154158

155159
def __init__(self):
156160
super().__init__(PaymentSourceType.KNET)

checkout_sdk/payments/payments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,9 @@ class FawryProduct:
598598
quantity: int
599599
price: int
600600
description: str
601+
602+
603+
class PaymentMethodDetails:
604+
display_name: str
605+
type: str
606+
network: str

checkout_sdk/payments/payments_apm_previous.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from enum import Enum
55

66
from checkout_sdk.common.enums import Country, PaymentSourceType
7-
from checkout_sdk.payments.payments import Payer
7+
from checkout_sdk.payments.payments import Payer, PaymentMethodDetails
88
from checkout_sdk.payments.payments_previous import RequestSource
9+
from checkout_sdk.tokens.tokens import ApplePayTokenData
910

1011

1112
class IntegrationType(str, Enum):
@@ -131,6 +132,9 @@ class RequestKnetSource(RequestSource):
131132
user_defined_field5: str
132133
card_token: str
133134
ptlf: str
135+
token_type: str
136+
token_data: ApplePayTokenData
137+
payment_method_details: PaymentMethodDetails
134138

135139
def __init__(self):
136140
super().__init__(PaymentSourceType.KNET)

checkout_sdk/workflows/workflows.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class CreateWorkflowRequest:
7070
class UpdateWorkflowRequest:
7171
name: str
7272
active: bool
73+
conditions: list # WorkflowConditionRequest
74+
actions: list # WorkflowActionRequest
7375

7476

7577
class ReflowRequest:
@@ -82,3 +84,7 @@ class ReflowByEventsRequest(ReflowRequest):
8284

8385
class ReflowBySubjectsRequest(ReflowRequest):
8486
subjects: list
87+
88+
89+
class EventTypesRequest:
90+
event_types: list

checkout_sdk/workflows/workflows_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from checkout_sdk.checkout_configuration import CheckoutConfiguration
66
from checkout_sdk.client import Client
77
from checkout_sdk.workflows.workflows import CreateWorkflowRequest, UpdateWorkflowRequest, WorkflowActionRequest, \
8-
WorkflowConditionRequest, ReflowRequest
8+
WorkflowConditionRequest, ReflowRequest, EventTypesRequest
99

1010

1111
class WorkflowsClient(Client):
@@ -17,6 +17,7 @@ class WorkflowsClient(Client):
1717
__SUBJECT_PATH = 'subject'
1818
__REFLOW_PATH = 'reflow'
1919
__WORKFLOW_PATH = 'workflow'
20+
__TEST_PATH = 'test'
2021

2122
def __init__(self, api_client: ApiClient, configuration: CheckoutConfiguration):
2223
super().__init__(api_client=api_client,
@@ -78,6 +79,11 @@ def remove_workflow_condition(self, workflow_id: str, condition_id: str):
7879
self.build_path(self.__WORKFLOWS_PATH, workflow_id, self.__CONDITIONS_PATH, condition_id),
7980
self._sdk_authorization())
8081

82+
def test_workflow(self, workflow_id: str, event_types_request: EventTypesRequest):
83+
return self._api_client.post(self.build_path(self.__WORKFLOWS_PATH, workflow_id, self.__TEST_PATH),
84+
self._sdk_authorization(),
85+
event_types_request)
86+
8187
def get_event_types(self):
8288
return self._api_client.get(self.build_path(self.__WORKFLOWS_PATH, self.__EVENT_TYPES_PATH),
8389
self._sdk_authorization())

tests/exception_test.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import pytest
2+
from unittest.mock import Mock
3+
from checkout_sdk.exception import (
4+
CheckoutException,
5+
CheckoutArgumentException,
6+
CheckoutAuthorizationException,
7+
CheckoutApiException
8+
)
9+
from checkout_sdk.authorization_type import AuthorizationType
10+
11+
12+
def test_checkout_exception():
13+
with pytest.raises(CheckoutException):
14+
raise CheckoutException("Test message")
15+
16+
17+
def test_checkout_argument_exception():
18+
with pytest.raises(CheckoutArgumentException):
19+
raise CheckoutArgumentException("Argument error occurred")
20+
21+
22+
def test_checkout_authorization_exception():
23+
with pytest.raises(CheckoutAuthorizationException):
24+
raise CheckoutAuthorizationException("Authorization error occurred")
25+
26+
27+
def test_invalid_authorization():
28+
auth_type = Mock(spec=AuthorizationType)
29+
auth_type.name = "SECRET_KEY"
30+
with pytest.raises(CheckoutAuthorizationException, match="SECRET_KEY authorization type"):
31+
CheckoutAuthorizationException.invalid_authorization(auth_type)
32+
33+
34+
def test_invalid_key():
35+
key_type = Mock(spec=AuthorizationType)
36+
key_type.name = "PUBLIC_KEY"
37+
with pytest.raises(CheckoutAuthorizationException, match="PUBLIC_KEY is required for this operation"):
38+
CheckoutAuthorizationException.invalid_key(key_type)
39+
40+
41+
def test_checkout_api_exception():
42+
response = Mock()
43+
response.status_code = 400
44+
response.text = '{"error_type": "request_invalid", "error_codes": ["invalid_field"]}'
45+
response.json.return_value = {
46+
"error_type": "request_invalid",
47+
"error_codes": ["invalid_field"]
48+
}
49+
50+
exception_instance = CheckoutApiException(response)
51+
52+
with pytest.raises(CheckoutApiException) as exc_info:
53+
raise exception_instance
54+
55+
exception = exc_info.value
56+
assert exception.http_metadata.status_code == 400
57+
assert exception.error_type == "request_invalid"
58+
assert exception.error_details == ["invalid_field"]

tests/payments/previous/request_apm_payments_previous_integration_test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from checkout_sdk.common.enums import Country, Currency
6-
from checkout_sdk.payments.payments import FawryProduct
6+
from checkout_sdk.payments.payments import FawryProduct, PaymentMethodDetails
77
from checkout_sdk.payments.payments_apm_previous import IntegrationType, \
88
RequestBoletoSource, RequestFawrySource, RequestGiropaySource, RequestIdealSource, RequestOxxoSource, \
99
RequestPagoFacilSource, RequestRapiPagoSource, RequestSofortSource, RequestAlipaySource, \
@@ -303,8 +303,14 @@ def test_should_request_sofort_payment(previous_api):
303303

304304

305305
def test_should_make_knet_payment(previous_api):
306+
payment_method_details = PaymentMethodDetails()
307+
payment_method_details.display_name = "name"
308+
payment_method_details.type = "type"
309+
payment_method_details.network = "card_network"
310+
306311
request_source = RequestKnetSource()
307312
request_source.language = "en"
313+
request_source.payment_method_details = payment_method_details
308314

309315
payment_request = PaymentRequest()
310316
payment_request.source = request_source

tests/payments/request_apm_payments_integration_test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
RequestKlarnaSource, RequestFawrySource, RequestTrustlySource, RequestCvConnectSource, RequestIllicadoSource, \
1515
RequestSepaSource, RequestGiropaySource
1616
from checkout_sdk.payments.payments import PaymentRequest, ProcessingSettings, FawryProduct, PaymentCustomerRequest, \
17-
ShippingDetails
17+
ShippingDetails, PaymentMethodDetails
1818
from checkout_sdk.payments.payments_apm_previous import RequestSofortSource
1919
from tests.checkout_test_utils import assert_response, SUCCESS_URL, FAILURE_URL, retriable, address, FIRST_NAME, \
2020
LAST_NAME, phone, check_error_item, PAYEE_NOT_ONBOARDED, APM_SERVICE_UNAVAILABLE, random_email, new_uuid, \
@@ -245,8 +245,14 @@ def test_should_make_przelewy24_payment(default_api):
245245

246246

247247
def test_should_make_knet_payment(default_api):
248+
payment_method_details = PaymentMethodDetails()
249+
payment_method_details.display_name = "name"
250+
payment_method_details.type = "type"
251+
payment_method_details.network = "card_network"
252+
248253
request_source = RequestKnetSource()
249254
request_source.language = "en"
255+
request_source.payment_method_details = payment_method_details
250256

251257
payment_request = PaymentRequest()
252258
payment_request.source = request_source

tests/workflows/workflow_integration_test.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from checkout_sdk.workflows.workflows import UpdateWorkflowRequest, WebhookWorkflowActionRequest, WebhookSignature, \
4-
EventWorkflowConditionRequest
4+
EventWorkflowConditionRequest, EventTypesRequest
55
from tests.checkout_test_utils import assert_response
66
from tests.workflows.workflows_test_utils import create_workflow, clean_workflows, add_action
77

@@ -205,3 +205,36 @@ def test__should_update_workflow_condition(default_api):
205205
assert condition_event_updated is not None
206206

207207
clean_workflows(default_api)
208+
209+
210+
@pytest.mark.skip(reason='unstable')
211+
def test__should_create_and_test_workflow(default_api):
212+
workflow = create_workflow(default_api)
213+
214+
event_types_request = EventTypesRequest()
215+
event_types_request.event_types = [
216+
"payment_approved",
217+
"payment_declined",
218+
"card_verification_declined",
219+
"card_verified",
220+
"payment_authorization_incremented",
221+
"payment_authorization_increment_declined",
222+
"payment_capture_declined",
223+
"payment_captured",
224+
"payment_refund_declined",
225+
"payment_refunded",
226+
"payment_void_declined",
227+
"payment_voided",
228+
"dispute_canceled",
229+
"dispute_evidence_required",
230+
"dispute_expired",
231+
"dispute_lost",
232+
"dispute_resolved",
233+
"dispute_won"
234+
]
235+
236+
get_workflow_response = default_api.workflows.test_workflow(workflow.id, event_types_request)
237+
238+
assert get_workflow_response is not None
239+
240+
clean_workflows(default_api)

tests/workflows/workflows_client_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from checkout_sdk.workflows.workflows import CreateWorkflowRequest, UpdateWorkflowRequest, \
4-
WebhookWorkflowActionRequest, EventWorkflowConditionRequest, ReflowRequest
4+
WebhookWorkflowActionRequest, EventWorkflowConditionRequest, ReflowRequest, EventTypesRequest
55
from checkout_sdk.workflows.workflows_client import WorkflowsClient
66

77

@@ -57,6 +57,10 @@ def test_remove_workflow_condition(self, mocker, client: WorkflowsClient):
5757
mocker.patch('checkout_sdk.api_client.ApiClient.delete', return_value='response')
5858
assert client.remove_workflow_condition('workflow_id', 'condition_id') == 'response'
5959

60+
def test_test_workflow(self, mocker, client: WorkflowsClient):
61+
mocker.patch('checkout_sdk.api_client.ApiClient.post', return_value='response')
62+
assert client.test_workflow('workflow_id', EventTypesRequest()) == 'response'
63+
6064
def test_get_event_types(self, mocker, client: WorkflowsClient):
6165
mocker.patch('checkout_sdk.api_client.ApiClient.get', return_value='response')
6266
assert client.get_event_types() == 'response'

0 commit comments

Comments
 (0)