Skip to content

Commit a54703b

Browse files
Knet Updates. Workflow updates (#269)
1 parent cec8d6a commit a54703b

File tree

10 files changed

+165
-0
lines changed

10 files changed

+165
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Checkout\Payments;
4+
5+
class PaymentMethodDetails
6+
{
7+
/**
8+
* @var string
9+
*/
10+
public $display_name;
11+
12+
/**
13+
* @var string
14+
*/
15+
public $type;
16+
17+
/**
18+
* @var string
19+
*/
20+
public $network;
21+
}

lib/Checkout/Payments/Previous/Source/Apm/RequestKnetSource.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Checkout\Payments\Previous\Source\Apm;
44

55
use Checkout\Common\PaymentSourceType;
6+
use Checkout\Payments\PaymentMethodDetails;
67
use Checkout\Payments\Previous\Source\AbstractRequestSource;
8+
use Checkout\Tokens\ApplePayTokenData;
79

810
class RequestKnetSource extends AbstractRequestSource
911
{
@@ -51,4 +53,19 @@ public function __construct()
5153
* @var string
5254
*/
5355
public $ptlf;
56+
57+
/**
58+
* @var string
59+
*/
60+
public $token_type;
61+
62+
/**
63+
* @var ApplePayTokenData
64+
*/
65+
public $token_data;
66+
67+
/**
68+
* @var PaymentMethodDetails
69+
*/
70+
public $payment_method_details;
5471
}

lib/Checkout/Payments/Request/Source/Apm/RequestKnetSource.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Checkout\Payments\Request\Source\Apm;
44

55
use Checkout\Common\PaymentSourceType;
6+
use Checkout\Payments\PaymentMethodDetails;
67
use Checkout\Payments\Previous\Source\AbstractRequestSource;
8+
use Checkout\Tokens\ApplePayTokenData;
79

810
class RequestKnetSource extends AbstractRequestSource
911
{
@@ -51,4 +53,19 @@ public function __construct()
5153
* @var string
5254
*/
5355
public $ptlf;
56+
57+
/**
58+
* @var string
59+
*/
60+
public $token_type;
61+
62+
/**
63+
* @var ApplePayTokenData
64+
*/
65+
public $token_data;
66+
67+
/**
68+
* @var PaymentMethodDetails
69+
*/
70+
public $payment_method_details;
5471
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Checkout\Workflows\Events;
4+
5+
class EventTypesRequest
6+
{
7+
/**
8+
* @var array of string
9+
*/
10+
public $event_types;
11+
}

lib/Checkout/Workflows/UpdateWorkflowRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,14 @@ class UpdateWorkflowRequest
1313
* @var bool
1414
*/
1515
public $active;
16+
17+
/**
18+
* @var array of WorkflowConditionRequest
19+
*/
20+
public $conditions;
21+
22+
/**
23+
* @var array of WorkflowActionRequest
24+
*/
25+
public $actions;
1626
}

lib/Checkout/Workflows/WorkflowsClient.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Checkout\Client;
1010
use Checkout\Workflows\Actions\WorkflowActionRequest;
1111
use Checkout\Workflows\Conditions\WorkflowConditionRequest;
12+
use Checkout\Workflows\Events\EventTypesRequest;
1213
use Checkout\Workflows\Reflows\ReflowRequest;
1314

1415
class WorkflowsClient extends Client
@@ -21,6 +22,7 @@ class WorkflowsClient extends Client
2122
const SUBJECT_PATH = "subject";
2223
const REFLOW_PATH = "reflow";
2324
const WORKFLOW_PATH = "workflow";
25+
const TEST_PATH = "test";
2426

2527
public function __construct(ApiClient $apiClient, CheckoutConfiguration $configuration)
2628
{
@@ -174,6 +176,21 @@ public function removeWorkflowCondition($workflowId, $conditionId)
174176
);
175177
}
176178

179+
/**
180+
* @param $workflowId
181+
* @param EventTypesRequest $eventTypesRequest
182+
* @return array
183+
* @throws CheckoutApiException
184+
*/
185+
public function testWorkflow($workflowId, EventTypesRequest $eventTypesRequest)
186+
{
187+
return $this->apiClient->post(
188+
$this->buildPath(self::WORKFLOWS_PATH, $workflowId, self::TEST_PATH),
189+
$eventTypesRequest,
190+
$this->sdkAuthorization()
191+
);
192+
}
193+
177194
/**
178195
* @return array
179196
* @throws CheckoutApiException

test/Checkout/Tests/Payments/Previous/RequestApmPaymentsIntegrationTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Checkout\Common\AccountHolder;
66
use Checkout\Common\Country;
77
use Checkout\Common\Currency;
8+
use Checkout\Payments\PaymentMethodDetails;
89
use Checkout\Payments\Previous\PaymentRequest;
910
use Checkout\Payments\Previous\Source\Apm\IntegrationType;
1011
use Checkout\Payments\Previous\Source\Apm\RequestAlipaySource;
@@ -486,8 +487,14 @@ function () use (&$paymentResponse1) {
486487
*/
487488
public function shouldMakeKnetPayment()
488489
{
490+
$paymentMethodDetails = new PaymentMethodDetails();
491+
$paymentMethodDetails->display_name = "name";
492+
$paymentMethodDetails->type = "type";
493+
$paymentMethodDetails->network = "card_network";
494+
489495
$requestSource = new RequestKnetSource();
490496
$requestSource->language = "en";
497+
$requestSource->payment_method_details = $paymentMethodDetails;
491498

492499
$paymentRequest = new PaymentRequest();
493500
$paymentRequest->source = $requestSource;

test/Checkout/Tests/Payments/RequestApmPaymentsIntegrationTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Checkout\Tests\Payments;
44

5+
use Checkout\Payments\PaymentMethodDetails;
56
use Closure;
67
use Exception;
78
use Checkout\CheckoutSdk;
@@ -489,8 +490,14 @@ public function shouldMakePrzelewy24Payment()
489490
*/
490491
public function shouldMakeKnetPayment()
491492
{
493+
$paymentMethodDetails = new PaymentMethodDetails();
494+
$paymentMethodDetails->display_name = "name";
495+
$paymentMethodDetails->type = "type";
496+
$paymentMethodDetails->network = "card_network";
497+
492498
$requestSource = new RequestKnetSource();
493499
$requestSource->language = "en";
500+
$requestSource->payment_method_details = $paymentMethodDetails;
494501

495502
$paymentRequest = new PaymentRequest();
496503
$paymentRequest->source = $requestSource;

test/Checkout/Tests/Workflows/WorkflowsClientTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Checkout\Workflows\Actions\WebhookWorkflowActionRequest;
99
use Checkout\Workflows\Conditions\EntityWorkflowConditionRequest;
1010
use Checkout\Workflows\CreateWorkflowRequest;
11+
use Checkout\Workflows\Events\EventTypesRequest;
1112
use Checkout\Workflows\Reflows\ReflowByEventsRequest;
1213
use Checkout\Workflows\UpdateWorkflowRequest;
1314
use Checkout\Workflows\WorkflowsClient;
@@ -179,6 +180,20 @@ public function shouldRemoveWorkflowCondition()
179180
$this->assertNotNull($response);
180181
}
181182

183+
/**
184+
* @test
185+
* @throws CheckoutApiException
186+
*/
187+
public function shouldTestWorkflow()
188+
{
189+
$this->apiClient
190+
->method("post")
191+
->willReturn("response");
192+
193+
$response = $this->client->testWorkflow("workflow_id", new EventTypesRequest());
194+
$this->assertNotNull($response);
195+
}
196+
182197
/**
183198
* @test
184199
* @throws CheckoutApiException

test/Checkout/Tests/Workflows/WorkflowsIntegrationTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Checkout\Workflows\Actions\WebhookWorkflowActionRequest;
88
use Checkout\Workflows\Conditions\EventWorkflowConditionRequest;
99
use Checkout\Workflows\Conditions\WorkflowConditionType;
10+
use Checkout\Workflows\Events\EventTypesRequest;
1011
use Checkout\Workflows\UpdateWorkflowRequest;
1112
use PHPUnit\Framework\AssertionFailedError;
1213

@@ -248,4 +249,46 @@ public function shouldUpdateWorkflowCondition()
248249

249250
self::assertTrue(sizeof($workflowUpdated["conditions"]) == 3);
250251
}
252+
253+
/**
254+
* @test
255+
* @throws CheckoutApiException
256+
*/
257+
public function shouldCreateAndTestWorkflows()
258+
{
259+
$this->markTestSkipped("unstable");
260+
$workflow = $this->createWorkflow();
261+
262+
$eventTypesRequest = new EventTypesRequest();
263+
$eventTypesRequest->event_types = [
264+
'payment_approved',
265+
'payment_declined',
266+
'card_verification_declined',
267+
'card_verified',
268+
'payment_authorization_incremented',
269+
'payment_authorization_increment_declined',
270+
'payment_capture_declined',
271+
'payment_captured',
272+
'payment_refund_declined',
273+
'payment_refunded',
274+
'payment_void_declined',
275+
'payment_voided',
276+
'dispute_canceled',
277+
'dispute_evidence_required',
278+
'dispute_expired',
279+
'dispute_lost',
280+
'dispute_resolved',
281+
'dispute_won'
282+
];
283+
284+
$testWorkflowResponse = $this->checkoutApi->getWorkflowsClient()->testWorkflow(
285+
$workflow["id"],
286+
$eventTypesRequest
287+
);
288+
289+
self::assertNotNull($testWorkflowResponse);
290+
291+
self::assertArrayHasKey("http_metadata", $testWorkflowResponse);
292+
self::assertEquals(200, $testWorkflowResponse["http_metadata"]->getStatusCode());
293+
}
251294
}

0 commit comments

Comments
 (0)