Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knet Updates. Workflow updates #269

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/Checkout/Payments/PaymentMethodDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Checkout\Payments;

class PaymentMethodDetails
{
/**
* @var string
*/
public $display_name;

/**
* @var string
*/
public $type;

/**
* @var string
*/
public $network;
}
17 changes: 17 additions & 0 deletions lib/Checkout/Payments/Previous/Source/Apm/RequestKnetSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Checkout\Payments\Previous\Source\Apm;

use Checkout\Common\PaymentSourceType;
use Checkout\Payments\PaymentMethodDetails;
use Checkout\Payments\Previous\Source\AbstractRequestSource;
use Checkout\Tokens\ApplePayTokenData;

class RequestKnetSource extends AbstractRequestSource
{
Expand Down Expand Up @@ -51,4 +53,19 @@ public function __construct()
* @var string
*/
public $ptlf;

/**
* @var string
*/
public $token_type;

/**
* @var ApplePayTokenData
*/
public $token_data;

/**
* @var PaymentMethodDetails
*/
public $payment_method_details;
}
17 changes: 17 additions & 0 deletions lib/Checkout/Payments/Request/Source/Apm/RequestKnetSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Checkout\Payments\Request\Source\Apm;

use Checkout\Common\PaymentSourceType;
use Checkout\Payments\PaymentMethodDetails;
use Checkout\Payments\Previous\Source\AbstractRequestSource;
use Checkout\Tokens\ApplePayTokenData;

class RequestKnetSource extends AbstractRequestSource
{
Expand Down Expand Up @@ -51,4 +53,19 @@ public function __construct()
* @var string
*/
public $ptlf;

/**
* @var string
*/
public $token_type;

/**
* @var ApplePayTokenData
*/
public $token_data;

/**
* @var PaymentMethodDetails
*/
public $payment_method_details;
}
11 changes: 11 additions & 0 deletions lib/Checkout/Workflows/Events/EventTypesRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Checkout\Workflows\Events;

class EventTypesRequest
{
/**
* @var array of string
*/
public $event_types;
}
10 changes: 10 additions & 0 deletions lib/Checkout/Workflows/UpdateWorkflowRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ class UpdateWorkflowRequest
* @var bool
*/
public $active;

/**
* @var array of WorkflowConditionRequest
*/
public $conditions;

/**
* @var array of WorkflowActionRequest
*/
public $actions;
}
17 changes: 17 additions & 0 deletions lib/Checkout/Workflows/WorkflowsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Checkout\Client;
use Checkout\Workflows\Actions\WorkflowActionRequest;
use Checkout\Workflows\Conditions\WorkflowConditionRequest;
use Checkout\Workflows\Events\EventTypesRequest;
use Checkout\Workflows\Reflows\ReflowRequest;

class WorkflowsClient extends Client
Expand All @@ -21,6 +22,7 @@ class WorkflowsClient extends Client
const SUBJECT_PATH = "subject";
const REFLOW_PATH = "reflow";
const WORKFLOW_PATH = "workflow";
const TEST_PATH = "test";

public function __construct(ApiClient $apiClient, CheckoutConfiguration $configuration)
{
Expand Down Expand Up @@ -174,6 +176,21 @@ public function removeWorkflowCondition($workflowId, $conditionId)
);
}

/**
* @param $workflowId
* @param EventTypesRequest $eventTypesRequest
* @return array
* @throws CheckoutApiException
*/
public function testWorkflow($workflowId, EventTypesRequest $eventTypesRequest)
{
return $this->apiClient->post(
$this->buildPath(self::WORKFLOWS_PATH, $workflowId, self::TEST_PATH),
$eventTypesRequest,
$this->sdkAuthorization()
);
}

/**
* @return array
* @throws CheckoutApiException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Checkout\Tests\Payments;

use Checkout\Payments\PaymentMethodDetails;
use Closure;
use Exception;
use Checkout\CheckoutSdk;
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions test/Checkout/Tests/Workflows/WorkflowsClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions test/Checkout/Tests/Workflows/WorkflowsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
}
Loading