Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ coverage_html

# PHPUnit
.phpunit.cache
.phpunit.result.cache

# Build data
/build/
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.5
1.1.6
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"php": ">=7.4",
"caseyamcl/guzzle_retry_middleware": "^2.8.0",
"guzzlehttp/guzzle": "^7.5.0",
"nesbot/carbon": "^2.72.6"
"nesbot/carbon": "^3.8.4"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.16.0",
Expand Down
1,141 changes: 701 additions & 440 deletions composer.lock

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions lib/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

class ApiClient
{
/** @var integer */
const VERSION = '1.1.5';
/** @var string */
const VERSION = '1.1.6';

/** @var string ComplyCube API key from developer dashboard */
private string $apiKey;
Expand All @@ -26,10 +26,16 @@ class ApiClient
/** @var ClientInterface Guzzle Http Client used to make requests */
public ?ClientInterface $httpClient;

public static function randomJitter($numRequests, $response): float
public static function randomJitter(int $numRequests, mixed $response): float
{
return (float) rand(0, $numRequests ** 1.5);
if ($numRequests <= 0) {
return 0.0;
}
$max = (int) ceil($numRequests ** 1.5);
$max = max(1, $max);
return (float) random_int(0, $max);
}

/**
* Create instance of ComplyCube API client
*
Expand Down
15 changes: 15 additions & 0 deletions lib/ComplyCubeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use ComplyCube\Resources\TeamMemberApi;
use ComplyCube\Resources\TokenApi;
use ComplyCube\Resources\WebhookApi;
use ComplyCube\Resources\WorkflowSessionApi;

class ComplyCubeClient
{
Expand All @@ -39,6 +40,7 @@ class ComplyCubeClient
private ?FlowSessionApi $flowSessionApi;
private ?CompanyApi $companyApi;
private ?CustomListApi $customListApi;
private ?WorkflowSessionApi $workflowSessionApi;

/**
* Create a ComplyCubeClient API Client Instance for the provided
Expand Down Expand Up @@ -293,4 +295,17 @@ public function customLists(): CustomListApi
}
return $this->customListApi;
}

/**
* The workflow sessions API allows you to run and retrieve workflow sessions. You can retrieve a specific workflow sessions as well as a list of all your client's workflow sessions.
*
* @return WorkflowSessionApi
*/
public function workflowSessions(): WorkflowSessionApi
{
if (empty($this->workflowSessionApi)) {
$this->workflowSessionApi = new WorkflowSessionApi($this->apiClient);
}
return $this->workflowSessionApi;
}
}
13 changes: 10 additions & 3 deletions lib/Model/ComplyCubeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
namespace ComplyCube\Model;

use Iterator;
use Countable;
use stdClass;

class ComplyCubeCollection extends Model implements Iterator
class ComplyCubeCollection extends Model implements Iterator, Countable
{
public int $page;
public int $pageSize;
public int $totalItems;
public int $pages;
public ?array $items;
public ?array $items = null;
private int $position;
private string $model;

Expand All @@ -38,7 +39,8 @@ public function load(stdClass $response): void
? $response->pages
: 0;

if (property_exists($response, "items")) {
if (property_exists($response, "items") && is_iterable($response->items)) {
$this->items = [];
foreach ($response->items as $item) {
$this->items[] = new $this->model($item);
}
Expand All @@ -49,6 +51,11 @@ public function load(stdClass $response): void
$this->rewind();
}

public function count(): int
{
return is_array($this->items) ? count($this->items) : 0;
}

public function jsonSerialize(): mixed
{
return array_filter(
Expand Down
2 changes: 2 additions & 0 deletions lib/Model/FlowSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ class FlowSession extends Model
{
public ?string $clientId;
public ?array $checkTypes;
public ?string $workflowTemplateId;
public ?string $successUrl;
public ?string $cancelUrl;
public ?bool $enableMonitoring;
public ?string $language;
public ?string $theme;
public ?string $redirectUrl;
public ?bool $shortUrl;

public function load(stdClass $response): void
{
Expand Down
33 changes: 33 additions & 0 deletions lib/Model/WorkflowSession.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace ComplyCube\Model;

use stdClass;

class WorkflowSession extends Model
{
public ?string $id;
public ?string $clientId;
public ?string $entityName;
public ?string $status;
public ?bool $workflowTemplateId;
public ?string $workflowTemplateName;
public ?string $workflowTemplateDescription;
public ?string $workflowId;
public ?int $workflowVersion;
public ?string $workflowDescription;
public ?array $compliancePolicies;
public ?string $outcome;
public ?array $allRelatedChecks;
public ?array $policyAssurance;
public ?array $tasks;
public ?string $lastCompletedTaskId;
public ?string $createdAt;
public ?string $completedAt;
public ?string $updatedAt;

public function load(stdClass $response): void
{
parent::load($response);
}
}
35 changes: 35 additions & 0 deletions lib/Resources/WorkflowSessionApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace ComplyCube\Resources;

use ComplyCube\ApiClient;
use ComplyCube\ApiResource;
use ComplyCube\ResourceActions\GetResource;
use ComplyCube\ResourceActions\ListResource;

class WorkflowSessionApi extends ApiResource
{
const ENDPOINT = "workflowSessions";

use GetResource,
ListResource;

public function __construct(ApiClient $apiClient)
{
parent::__construct($apiClient, "\ComplyCube\Model\WorkflowSession");
}

/**
* Complete the workflow session.
*
* @param string $workflowSessionId being completed.
*/
public function complete(string $workflowSessionId)
{
$response = $this->apiClient->post(
$this::ENDPOINT . "/" . $workflowSessionId . "/complete",
[]
);
return $response;
}
}
32 changes: 21 additions & 11 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnError="true" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
processIsolation="false"
stopOnError="true"
stopOnFailure="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
>
<coverage>
<include>
<directory suffix=".php">lib</directory>
</include>
<exclude>
<directory suffix=".php">lib/Model</directory>
<file>lib/ComplyCubeClient.php</file>
</exclude>

<report>
<clover outputFile="clover.xml"/>
</report>
</coverage>

<testsuites>
<testsuite name="ComplyCube Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging/>
<source>
<include>
<directory suffix=".php">lib</directory>
</include>
<exclude>
<directory suffix=".php">lib/Model</directory>
<file>lib/ComplyCubeClient.php</file>
</exclude>
</source>

</phpunit>
6 changes: 5 additions & 1 deletion tests/integration/AuditLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public function testFilterUpdateOnly()
public function testGetAuditLog($id)
{
$result = $this->complycube->AuditLogs()->get($id);
$createdAt = Carbon::parse($result->createdAt);
$this->assertTrue(
$createdAt->between(Carbon::now()->subMinute(), Carbon::now()->addSecond()),
'createdAt was not within the expected time window'
);
$this->assertEquals($id, $result->id);
$this->assertLessThan(Carbon::now()->timestamp, Carbon::parse($result->createdAt)->timestamp);
}
}
4 changes: 2 additions & 2 deletions tests/integration/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function setUp(): void
"gender" => "female",
"nationality" => "GB",
"birthCountry" => "US",
"ssn" => "111111111",
"ssn" => "123-45-6789",
"socialInsuranceNumber" => "SI00000000",
"nationalIdentityNumber" => "NI00000000",
"taxIdentificationNumber" => "TIN0000000",
Expand All @@ -59,7 +59,7 @@ public function testCreatePersonInline(): string
"personDetails" => [
"firstName" => "Jane",
"lastName" => "Smith",
"ssn" => "111111111",
"ssn" => "123-45-6789",
],
]);

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/CustomListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function testListCustomLists()

$this->assertInstanceOf(ComplyCubeCollection::class, $result);

$this->assertCount(1, $result);
$this->assertGreaterThan(1, count($result));

foreach ($result->items as $item) {
$this->custom_list_assertions($item);
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/WebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private function webhook_assertions($item)
public function testCreateWebhook($enabled = false): Webhook
{
$webhook = new Webhook([
"url" => "http://hook.com/",
"url" => "https://www.complycube.com/",
"enabled" => $enabled,
"events" => ["check.pending"],
]);
Expand All @@ -70,12 +70,12 @@ public function testCreateWebhook($enabled = false): Webhook
public function testUpdateWebhookInline(Webhook $webhook): void
{
$result = $this->complycube->webhooks()->update($webhook->id, [
"url" => "https://newurl/endpoint",
"url" => "https://www.complycube.com/",
"enabled" => false,
]);
$this->webhook_assertions($result);
$this->assertNull($result->secret);
$this->assertEquals("https://newurl/endpoint", $result->url);
$this->assertEquals("https://www.complycube.com/", $result->url);
}

/**
Expand All @@ -84,7 +84,7 @@ public function testUpdateWebhookInline(Webhook $webhook): void
public function testUpdateWebhook(Webhook $webhook): void
{
$newWebhook = $webhook;
$newWebhook->url = "https://newurl/endpoint";
$newWebhook->url = "https://www.complycube.com/";
$result = $this->complycube
->webhooks()
->update($webhook->id, $newWebhook);
Expand Down
Loading