From a54703b86a43bf9ba996e64cceb253b6b5483f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:57:27 +0200 Subject: [PATCH] Knet Updates. Workflow updates (#269) --- .../Payments/PaymentMethodDetails.php | 21 +++++++++ .../Previous/Source/Apm/RequestKnetSource.php | 17 ++++++++ .../Request/Source/Apm/RequestKnetSource.php | 17 ++++++++ .../Workflows/Events/EventTypesRequest.php | 11 +++++ .../Workflows/UpdateWorkflowRequest.php | 10 +++++ lib/Checkout/Workflows/WorkflowsClient.php | 17 ++++++++ .../RequestApmPaymentsIntegrationTest.php | 7 +++ .../RequestApmPaymentsIntegrationTest.php | 7 +++ .../Tests/Workflows/WorkflowsClientTest.php | 15 +++++++ .../Workflows/WorkflowsIntegrationTest.php | 43 +++++++++++++++++++ 10 files changed, 165 insertions(+) create mode 100644 lib/Checkout/Payments/PaymentMethodDetails.php create mode 100644 lib/Checkout/Workflows/Events/EventTypesRequest.php diff --git a/lib/Checkout/Payments/PaymentMethodDetails.php b/lib/Checkout/Payments/PaymentMethodDetails.php new file mode 100644 index 00000000..982ff07b --- /dev/null +++ b/lib/Checkout/Payments/PaymentMethodDetails.php @@ -0,0 +1,21 @@ +apiClient->post( + $this->buildPath(self::WORKFLOWS_PATH, $workflowId, self::TEST_PATH), + $eventTypesRequest, + $this->sdkAuthorization() + ); + } + /** * @return array * @throws CheckoutApiException diff --git a/test/Checkout/Tests/Payments/Previous/RequestApmPaymentsIntegrationTest.php b/test/Checkout/Tests/Payments/Previous/RequestApmPaymentsIntegrationTest.php index 34b569c2..13a99673 100644 --- a/test/Checkout/Tests/Payments/Previous/RequestApmPaymentsIntegrationTest.php +++ b/test/Checkout/Tests/Payments/Previous/RequestApmPaymentsIntegrationTest.php @@ -5,6 +5,7 @@ use Checkout\Common\AccountHolder; use Checkout\Common\Country; use Checkout\Common\Currency; +use Checkout\Payments\PaymentMethodDetails; use Checkout\Payments\Previous\PaymentRequest; use Checkout\Payments\Previous\Source\Apm\IntegrationType; use Checkout\Payments\Previous\Source\Apm\RequestAlipaySource; @@ -486,8 +487,14 @@ function () use (&$paymentResponse1) { */ public function shouldMakeKnetPayment() { + $paymentMethodDetails = new PaymentMethodDetails(); + $paymentMethodDetails->display_name = "name"; + $paymentMethodDetails->type = "type"; + $paymentMethodDetails->network = "card_network"; + $requestSource = new RequestKnetSource(); $requestSource->language = "en"; + $requestSource->payment_method_details = $paymentMethodDetails; $paymentRequest = new PaymentRequest(); $paymentRequest->source = $requestSource; diff --git a/test/Checkout/Tests/Payments/RequestApmPaymentsIntegrationTest.php b/test/Checkout/Tests/Payments/RequestApmPaymentsIntegrationTest.php index 68e63f58..1fe6fcaf 100644 --- a/test/Checkout/Tests/Payments/RequestApmPaymentsIntegrationTest.php +++ b/test/Checkout/Tests/Payments/RequestApmPaymentsIntegrationTest.php @@ -2,6 +2,7 @@ namespace Checkout\Tests\Payments; +use Checkout\Payments\PaymentMethodDetails; use Closure; use Exception; use Checkout\CheckoutSdk; @@ -489,8 +490,14 @@ public function shouldMakePrzelewy24Payment() */ public function shouldMakeKnetPayment() { + $paymentMethodDetails = new PaymentMethodDetails(); + $paymentMethodDetails->display_name = "name"; + $paymentMethodDetails->type = "type"; + $paymentMethodDetails->network = "card_network"; + $requestSource = new RequestKnetSource(); $requestSource->language = "en"; + $requestSource->payment_method_details = $paymentMethodDetails; $paymentRequest = new PaymentRequest(); $paymentRequest->source = $requestSource; diff --git a/test/Checkout/Tests/Workflows/WorkflowsClientTest.php b/test/Checkout/Tests/Workflows/WorkflowsClientTest.php index b8f9ec04..c20ce3b4 100644 --- a/test/Checkout/Tests/Workflows/WorkflowsClientTest.php +++ b/test/Checkout/Tests/Workflows/WorkflowsClientTest.php @@ -8,6 +8,7 @@ use Checkout\Workflows\Actions\WebhookWorkflowActionRequest; use Checkout\Workflows\Conditions\EntityWorkflowConditionRequest; use Checkout\Workflows\CreateWorkflowRequest; +use Checkout\Workflows\Events\EventTypesRequest; use Checkout\Workflows\Reflows\ReflowByEventsRequest; use Checkout\Workflows\UpdateWorkflowRequest; use Checkout\Workflows\WorkflowsClient; @@ -179,6 +180,20 @@ public function shouldRemoveWorkflowCondition() $this->assertNotNull($response); } + /** + * @test + * @throws CheckoutApiException + */ + public function shouldTestWorkflow() + { + $this->apiClient + ->method("post") + ->willReturn("response"); + + $response = $this->client->testWorkflow("workflow_id", new EventTypesRequest()); + $this->assertNotNull($response); + } + /** * @test * @throws CheckoutApiException diff --git a/test/Checkout/Tests/Workflows/WorkflowsIntegrationTest.php b/test/Checkout/Tests/Workflows/WorkflowsIntegrationTest.php index 9229094a..28d44dcd 100644 --- a/test/Checkout/Tests/Workflows/WorkflowsIntegrationTest.php +++ b/test/Checkout/Tests/Workflows/WorkflowsIntegrationTest.php @@ -7,6 +7,7 @@ use Checkout\Workflows\Actions\WebhookWorkflowActionRequest; use Checkout\Workflows\Conditions\EventWorkflowConditionRequest; use Checkout\Workflows\Conditions\WorkflowConditionType; +use Checkout\Workflows\Events\EventTypesRequest; use Checkout\Workflows\UpdateWorkflowRequest; use PHPUnit\Framework\AssertionFailedError; @@ -248,4 +249,46 @@ public function shouldUpdateWorkflowCondition() self::assertTrue(sizeof($workflowUpdated["conditions"]) == 3); } + + /** + * @test + * @throws CheckoutApiException + */ + public function shouldCreateAndTestWorkflows() + { + $this->markTestSkipped("unstable"); + $workflow = $this->createWorkflow(); + + $eventTypesRequest = new EventTypesRequest(); + $eventTypesRequest->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' + ]; + + $testWorkflowResponse = $this->checkoutApi->getWorkflowsClient()->testWorkflow( + $workflow["id"], + $eventTypesRequest + ); + + self::assertNotNull($testWorkflowResponse); + + self::assertArrayHasKey("http_metadata", $testWorkflowResponse); + self::assertEquals(200, $testWorkflowResponse["http_metadata"]->getStatusCode()); + } }