Skip to content

Commit

Permalink
Knet Updates. Workflow updates
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko committed Sep 26, 2024
1 parent 5c5fe23 commit 795be1b
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 7 deletions.
6 changes: 5 additions & 1 deletion checkout_sdk/payments/payment_apm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from checkout_sdk.common.common import Address, AccountHolder
from checkout_sdk.common.enums import PaymentSourceType, Country, Currency
from checkout_sdk.payments.payments import PaymentRequestSource, BillingPlan
from checkout_sdk.payments.payments import PaymentRequestSource, BillingPlan, PaymentMethodDetails
from checkout_sdk.tokens.tokens import ApplePayTokenData


class RequestIdealSource(PaymentRequestSource):
Expand Down Expand Up @@ -151,6 +152,9 @@ class RequestKnetSource(PaymentRequestSource):
user_defined_field5: str
card_token: str
ptlf: str
token_type: str
token_data: ApplePayTokenData
payment_method_details: PaymentMethodDetails

def __init__(self):
super().__init__(PaymentSourceType.KNET)
Expand Down
6 changes: 6 additions & 0 deletions checkout_sdk/payments/payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,9 @@ class FawryProduct:
quantity: int
price: int
description: str


class PaymentMethodDetails:
display_name: str
type: str
network: str
6 changes: 5 additions & 1 deletion checkout_sdk/payments/payments_apm_previous.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from enum import Enum

from checkout_sdk.common.enums import Country, PaymentSourceType
from checkout_sdk.payments.payments import Payer
from checkout_sdk.payments.payments import Payer, PaymentMethodDetails
from checkout_sdk.payments.payments_previous import RequestSource
from checkout_sdk.tokens.tokens import ApplePayTokenData


class IntegrationType(str, Enum):
Expand Down Expand Up @@ -131,6 +132,9 @@ class RequestKnetSource(RequestSource):
user_defined_field5: str
card_token: str
ptlf: str
token_type: str
token_data: ApplePayTokenData
payment_method_details: PaymentMethodDetails

def __init__(self):
super().__init__(PaymentSourceType.KNET)
Expand Down
6 changes: 6 additions & 0 deletions checkout_sdk/workflows/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class CreateWorkflowRequest:
class UpdateWorkflowRequest:
name: str
active: bool
conditions: list # WorkflowConditionRequest
actions: list # WorkflowActionRequest


class ReflowRequest:
Expand All @@ -82,3 +84,7 @@ class ReflowByEventsRequest(ReflowRequest):

class ReflowBySubjectsRequest(ReflowRequest):
subjects: list


class EventTypesRequest:
event_types: list
8 changes: 7 additions & 1 deletion checkout_sdk/workflows/workflows_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from checkout_sdk.checkout_configuration import CheckoutConfiguration
from checkout_sdk.client import Client
from checkout_sdk.workflows.workflows import CreateWorkflowRequest, UpdateWorkflowRequest, WorkflowActionRequest, \
WorkflowConditionRequest, ReflowRequest
WorkflowConditionRequest, ReflowRequest, EventTypesRequest


class WorkflowsClient(Client):
Expand All @@ -17,6 +17,7 @@ class WorkflowsClient(Client):
__SUBJECT_PATH = 'subject'
__REFLOW_PATH = 'reflow'
__WORKFLOW_PATH = 'workflow'
__TEST_PATH = 'test'

def __init__(self, api_client: ApiClient, configuration: CheckoutConfiguration):
super().__init__(api_client=api_client,
Expand Down Expand Up @@ -78,6 +79,11 @@ def remove_workflow_condition(self, workflow_id: str, condition_id: str):
self.build_path(self.__WORKFLOWS_PATH, workflow_id, self.__CONDITIONS_PATH, condition_id),
self._sdk_authorization())

def test_workflow(self, workflow_id: str, event_types_request: EventTypesRequest):
return self._api_client.post(self.build_path(self.__WORKFLOWS_PATH, workflow_id, self.__TEST_PATH),
self._sdk_authorization(),
event_types_request)

def get_event_types(self):
return self._api_client.get(self.build_path(self.__WORKFLOWS_PATH, self.__EVENT_TYPES_PATH),
self._sdk_authorization())
Expand Down
56 changes: 56 additions & 0 deletions tests/exception_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pytest
from unittest.mock import Mock
from checkout_sdk.exception import (
CheckoutException,
CheckoutArgumentException,
CheckoutAuthorizationException,
CheckoutApiException
)
from checkout_sdk.authorization_type import AuthorizationType


def test_checkout_exception():
with pytest.raises(CheckoutException):
raise CheckoutException("Test message")


def test_checkout_argument_exception():
with pytest.raises(CheckoutArgumentException):
raise CheckoutArgumentException("Argument error occurred")


def test_checkout_authorization_exception():
with pytest.raises(CheckoutAuthorizationException):
raise CheckoutAuthorizationException("Authorization error occurred")


def test_invalid_authorization():
auth_type = Mock(spec=AuthorizationType)
auth_type.name = "SECRET_KEY"
with pytest.raises(CheckoutAuthorizationException, match="SECRET_KEY authorization type"):
CheckoutAuthorizationException.invalid_authorization(auth_type)


def test_invalid_key():
key_type = Mock(spec=AuthorizationType)
key_type.name = "PUBLIC_KEY"
with pytest.raises(CheckoutAuthorizationException, match="PUBLIC_KEY is required for this operation"):
CheckoutAuthorizationException.invalid_key(key_type)


def test_checkout_api_exception():
response = Mock()
response.status_code = 400
response.text = '{"error_type": "request_invalid", "error_codes": ["invalid_field"]}'
response.json.return_value = {
"error_type": "request_invalid",
"error_codes": ["invalid_field"]
}

with pytest.raises(CheckoutApiException) as exc_info:
raise CheckoutApiException(response)

exception = exc_info.value

Check warning

Code scanning / CodeQL

Unreachable code Warning test

This statement is unreachable.
assert exception.http_metadata.status_code == 400
assert exception.error_type == "request_invalid"
assert exception.error_details == ["invalid_field"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

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


def test_should_make_knet_payment(previous_api):
payment_method_details = PaymentMethodDetails()
payment_method_details.display_name = "name"
payment_method_details.type = "type"
payment_method_details.description = "description"

request_source = RequestKnetSource()
request_source.language = "en"
request_source.payment_method_details = payment_method_details

payment_request = PaymentRequest()
payment_request.source = request_source
Expand Down
8 changes: 7 additions & 1 deletion tests/payments/request_apm_payments_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
RequestKlarnaSource, RequestFawrySource, RequestTrustlySource, RequestCvConnectSource, RequestIllicadoSource, \
RequestSepaSource, RequestGiropaySource
from checkout_sdk.payments.payments import PaymentRequest, ProcessingSettings, FawryProduct, PaymentCustomerRequest, \
ShippingDetails
ShippingDetails, PaymentMethodDetails
from checkout_sdk.payments.payments_apm_previous import RequestSofortSource
from tests.checkout_test_utils import assert_response, SUCCESS_URL, FAILURE_URL, retriable, address, FIRST_NAME, \
LAST_NAME, phone, check_error_item, PAYEE_NOT_ONBOARDED, APM_SERVICE_UNAVAILABLE, random_email, new_uuid, \
Expand Down Expand Up @@ -245,8 +245,14 @@ def test_should_make_przelewy24_payment(default_api):


def test_should_make_knet_payment(default_api):
payment_method_details = PaymentMethodDetails()
payment_method_details.display_name = "name"
payment_method_details.type = "type"
payment_method_details.description = "description"

request_source = RequestKnetSource()
request_source.language = "en"
request_source.payment_method_details = payment_method_details

payment_request = PaymentRequest()
payment_request.source = request_source
Expand Down
35 changes: 34 additions & 1 deletion tests/workflows/workflow_integration_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from checkout_sdk.workflows.workflows import UpdateWorkflowRequest, WebhookWorkflowActionRequest, WebhookSignature, \
EventWorkflowConditionRequest
EventWorkflowConditionRequest, EventTypesRequest
from tests.checkout_test_utils import assert_response
from tests.workflows.workflows_test_utils import create_workflow, clean_workflows, add_action

Expand Down Expand Up @@ -205,3 +205,36 @@ def test__should_update_workflow_condition(default_api):
assert condition_event_updated is not None

clean_workflows(default_api)


@pytest.mark.skip(reason='unstable')
def test__should_create_and_test_workflow(default_api):
workflow = create_workflow(default_api)

event_types_request = EventTypesRequest()
event_types_request.event_types = [
"payment_approved",
"payment_declined",
"card_verification_declined",
"card_verified",
"payment_authorization_incremented",
"payment_authorization_increment_declined",
"payment_capture_declined",
"payment_captured",
"payment_refund_declined",
"payment_refunded",
"payment_void_declined",
"payment_voided",
"dispute_canceled",
"dispute_evidence_required",
"dispute_expired",
"dispute_lost",
"dispute_resolved",
"dispute_won"
]

get_workflow_response = default_api.workflows.test_workflow(workflow.id, event_types_request)

assert get_workflow_response is not None

clean_workflows(default_api)
6 changes: 5 additions & 1 deletion tests/workflows/workflows_client_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from checkout_sdk.workflows.workflows import CreateWorkflowRequest, UpdateWorkflowRequest, \
WebhookWorkflowActionRequest, EventWorkflowConditionRequest, ReflowRequest
WebhookWorkflowActionRequest, EventWorkflowConditionRequest, ReflowRequest, EventTypesRequest
from checkout_sdk.workflows.workflows_client import WorkflowsClient


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

def test_test_workflow(self, mocker, client: WorkflowsClient):
mocker.patch('checkout_sdk.api_client.ApiClient.post', return_value='response')
assert client.test_workflow('workflow_id', EventTypesRequest()) == 'response'

def test_get_event_types(self, mocker, client: WorkflowsClient):
mocker.patch('checkout_sdk.api_client.ApiClient.get', return_value='response')
assert client.get_event_types() == 'response'
Expand Down

0 comments on commit 795be1b

Please sign in to comment.