From 2d8218f2bb2a6edcfcbd02fd8cacebb2ca3ebd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:09:12 +0200 Subject: [PATCH] Knet Updates. Workflow updates (#150) --- .../payments/payment_method_details.rb | 17 +++++++++++++++++ lib/checkout_sdk/payments/payments.rb | 1 + .../payments/previous/source/apm/knet_source.rb | 11 ++++++++++- .../payments/source/apm/knet_source.rb | 11 ++++++++++- lib/checkout_sdk/workflows/patch_workflow.rb | 8 +++++++- lib/checkout_sdk/workflows/workflows_client.rb | 9 ++++++++- .../request_apm_payments_integration_spec.rb | 6 ++++++ .../request_apm_payments_integration_spec.rb | 6 ++++++ .../workflows/workflows_integration_spec.rb | 16 +++++++++++++++- 9 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 lib/checkout_sdk/payments/payment_method_details.rb diff --git a/lib/checkout_sdk/payments/payment_method_details.rb b/lib/checkout_sdk/payments/payment_method_details.rb new file mode 100644 index 0000000..7ed8cfb --- /dev/null +++ b/lib/checkout_sdk/payments/payment_method_details.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module CheckoutSdk + module Payments + # @!attribute display_name + # @return [String] + # @!attribute type + # @return [String] + # @!attribute network + # @return [String] + class PaymentMethodDetails + attr_accessor :display_name, + :type, + :network + end + end +end diff --git a/lib/checkout_sdk/payments/payments.rb b/lib/checkout_sdk/payments/payments.rb index 3cae103..e20cdb7 100644 --- a/lib/checkout_sdk/payments/payments.rb +++ b/lib/checkout_sdk/payments/payments.rb @@ -14,6 +14,7 @@ require 'checkout_sdk/payments/authorization_type' require 'checkout_sdk/payments/os_type' require 'checkout_sdk/payments/payment_instruction' +require 'checkout_sdk/payments/payment_method_details' require 'checkout_sdk/payments/refund_request' require 'checkout_sdk/payments/product' require 'checkout_sdk/payments/capture_type' diff --git a/lib/checkout_sdk/payments/previous/source/apm/knet_source.rb b/lib/checkout_sdk/payments/previous/source/apm/knet_source.rb index 400446b..411bf44 100644 --- a/lib/checkout_sdk/payments/previous/source/apm/knet_source.rb +++ b/lib/checkout_sdk/payments/previous/source/apm/knet_source.rb @@ -19,6 +19,12 @@ module Payments # @return [String] # @!attribute ptlf # @return [String] + # @!attribute token_type + # @return [String] + # @!attribute token_data + # @return [ApplePayTokenData] + # @!attribute payment_method_details + # @return [PaymentMethodDetails] class KnetSource < PaymentSource attr_accessor :language, :user_defined_field1, @@ -27,7 +33,10 @@ class KnetSource < PaymentSource :user_defined_field4, :user_defined_field5, :card_token, - :ptlf + :ptlf, + :token_type, + :token_data, + :payment_method_details def initialize super CheckoutSdk::Common::PaymentSourceType::KNET diff --git a/lib/checkout_sdk/payments/source/apm/knet_source.rb b/lib/checkout_sdk/payments/source/apm/knet_source.rb index 88b8625..2c7d089 100644 --- a/lib/checkout_sdk/payments/source/apm/knet_source.rb +++ b/lib/checkout_sdk/payments/source/apm/knet_source.rb @@ -18,6 +18,12 @@ module Payments # @return [String] # @!attribute ptlf # @return [String] + # @!attribute token_type + # @return [String] + # @!attribute token_data + # @return [ApplePayTokenData] + # @!attribute payment_method_details + # @return [PaymentMethodDetails] class KnetSource < PaymentSource attr_accessor :language, :user_defined_field1, @@ -26,7 +32,10 @@ class KnetSource < PaymentSource :user_defined_field4, :user_defined_field5, :card_token, - :ptlf + :ptlf, + :token_type, + :token_data, + :payment_method_details def initialize super CheckoutSdk::Common::PaymentSourceType::KNET diff --git a/lib/checkout_sdk/workflows/patch_workflow.rb b/lib/checkout_sdk/workflows/patch_workflow.rb index 347a7b2..9e354aa 100644 --- a/lib/checkout_sdk/workflows/patch_workflow.rb +++ b/lib/checkout_sdk/workflows/patch_workflow.rb @@ -6,9 +6,15 @@ module Workflows # @return [String] # @!attribute active # @return [TrueClass, FalseClass] + # @!attribute conditions + # @return [Array(WorkflowCondition)] + # @!attribute actions + # @return [Array(WorkflowAction)] class PatchWorkflow attr_accessor :name, - :active + :active, + :conditions, + :actions end end end diff --git a/lib/checkout_sdk/workflows/workflows_client.rb b/lib/checkout_sdk/workflows/workflows_client.rb index 352f033..fcef4d0 100644 --- a/lib/checkout_sdk/workflows/workflows_client.rb +++ b/lib/checkout_sdk/workflows/workflows_client.rb @@ -12,8 +12,9 @@ class WorkflowsClient < Client REFLOW = 'reflow' SUBJECT = 'subject' WORKFLOW_ID = 'workflowId' + TEST = 'test' private_constant :WORKFLOWS, :WORKFLOW, :ACTIONS, :CONDITIONS, :EVENT_TYPES, :EVENTS, :REFLOW, - :SUBJECT, :WORKFLOW_ID + :SUBJECT, :WORKFLOW_ID, :TEST # @param [ApiClient] api_client # @param [CheckoutConfiguration] configuration @@ -86,6 +87,12 @@ def remove_workflow_condition(workflow_id, condition_id) api_client.invoke_delete(build_path(WORKFLOWS, workflow_id, CONDITIONS, condition_id), sdk_authorization) end + # @param [String] workflow_id + # @param [Hash] event_types_request + def test_workflow(workflow_id, event_types_request) + api_client.invoke_post(build_path(WORKFLOWS, workflow_id, TEST), sdk_authorization, event_types_request) + end + def retrieve_event_types api_client.invoke_get(build_path(WORKFLOWS, EVENT_TYPES), sdk_authorization) end diff --git a/spec/checkout_sdk/payments/previous/request_apm_payments_integration_spec.rb b/spec/checkout_sdk/payments/previous/request_apm_payments_integration_spec.rb index a53a8da..f7951f1 100644 --- a/spec/checkout_sdk/payments/previous/request_apm_payments_integration_spec.rb +++ b/spec/checkout_sdk/payments/previous/request_apm_payments_integration_spec.rb @@ -203,8 +203,14 @@ context 'when requesting Knet source payment' do it 'requests payment correctly' do + payment_method_details = CheckoutSdk::Payments::PaymentMethodDetails.new + payment_method_details.display_name = "name" + payment_method_details.type = "type" + payment_method_details.network = "card_network" + source = CheckoutSdk::Previous::Payments::KnetSource.new source.language = 'en' + source.payment_method_details = payment_method_details request = CheckoutSdk::Previous::Payments::PaymentRequest.new request.source = source diff --git a/spec/checkout_sdk/payments/request_apm_payments_integration_spec.rb b/spec/checkout_sdk/payments/request_apm_payments_integration_spec.rb index 3224f6e..0d8e9c3 100644 --- a/spec/checkout_sdk/payments/request_apm_payments_integration_spec.rb +++ b/spec/checkout_sdk/payments/request_apm_payments_integration_spec.rb @@ -147,8 +147,14 @@ context 'when requesting Knet source payment' do it 'raises an error (payee_not_onboarded)' do + payment_method_details = CheckoutSdk::Payments::PaymentMethodDetails.new + payment_method_details.display_name = "name" + payment_method_details.type = "type" + payment_method_details.network = "card_network" + source = CheckoutSdk::Payments::KnetSource.new source.language = 'en' + source.payment_method_details = payment_method_details request = CheckoutSdk::Payments::PaymentRequest.new request.source = source diff --git a/spec/checkout_sdk/workflows/workflows_integration_spec.rb b/spec/checkout_sdk/workflows/workflows_integration_spec.rb index 77bc2e2..40563d2 100644 --- a/spec/checkout_sdk/workflows/workflows_integration_spec.rb +++ b/spec/checkout_sdk/workflows/workflows_integration_spec.rb @@ -7,7 +7,7 @@ end after(:all) do - #delete_workflow @workflow.id + # delete_workflow @workflow.id end describe '.retrieve_workflows' do @@ -124,4 +124,18 @@ end end end + + describe '.test_workflow' do + context 'when having a workflow' do + it 'should test workflow' do + event_types_request = { + "event_types": %w[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] + } + + workflow_response = default_sdk.workflows.test_workflow(@workflow.id, event_types_request) + + expect(workflow_response).not_to be_nil + end + end + end end