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
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,62 @@ if ($webhook->status === \VerifyMyContent\SDK\IdentityVerification\IdentityVerif
}
```

### Start a Re-Identification

Use the `createReIdentification` of the `VerifyMyContent\SDK\ReIdentification\ReIdentificationClient` abstraction inside `VerifyMyContent\VerifyMyContent` passing a `VerifyMyContent\SDK\ReIdentification\Entity\Requests\CreateReIdentificationRequest` and receiving a `VerifyMyContent\SDK\ReIdentification\Entity\Responses\CreateReIdentificationResponse`.

```php
<?php
require(__DIR__ . "/vendor/autoload.php");

$vmc = new VerifyMyContent\VerifyMyContent(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET'));
//$vmc->useSandbox();

$response = $vmc->reIdentification()->createReIdentification(
new \VerifyMyContent\SDK\ReIdentification\Entity\Requests\CreateReIdentificationRequest([
"customer" => [
"id" => "YOUR-CUSTOMER-UNIQUE-ID",
"email" => "[email protected]",
],
"redirect_uri" => "https://example.com/callback",
"webhook" => "https://example.com/webhook",
])
);

// save $response->id if you want to track this re-identification

// redirect user to re-identify
header("Location: {$response->redirect_uri}");
```

### Retrieve Re-Identification by ID

```php
<?php
require(__DIR__ . "/vendor/autoload.php");

$vmc = new VerifyMyContent\VerifyMyContent(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET'));
//$vmc->useSandbox();

$response = $vmc->reIdentification()->getReIdentification("YOUR-RE-IDENTIFICATION-ID");

// Printing current status
echo "Status: {$response->status}";
```

### Receive a Re-Identification Webhook

```php
<?php
require(__DIR__ . "/vendor/autoload.php");

$data = json_decode(file_get_contents('php://input'), true);
$webhook = new \VerifyMyContent\SDK\ReIdentification\Entity\Requests\WebhookReIdentificationRequest($data);

// Printing current status
echo "Status: {$webhook->status} received from re-identification {$webhook->id}";
```

### Create a Static Content Moderation

Use the `createStaticContentModeration` of the `VerifyMyContent\SDK\ContentModeration\ContentModerationClient` abstraction inside `VerifyMyContent\VerifyMyContent` passing an `VerifyMyContent\SDK\ContentModeration\Entity\Requests\CreateStaticContentModerationRequest` and receiving an `VerifyMyContent\SDK\ContentModeration\Entity\Responses\CreateStaticContentModerationResponse`.
Expand Down
41 changes: 41 additions & 0 deletions examples/re-identification/create-re-identification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use VerifyMyContent\SDK\ReIdentification\Entity\Requests\CreateReIdentificationRequest;
use VerifyMyContent\SDK\ReIdentification\ReIdentificationStatus;
use VerifyMyContent\SDK\VerifyMyContent;

require_once __DIR__ . "/../../vendor/autoload.php";

# Getting env variables
$API_KEY = getenv("API_KEY");
$API_SECRET = getenv("API_SECRET");

# Setup SDK
$vmc = new VerifyMyContent($API_KEY, $API_SECRET);
$vmc->useSandbox();

// Create Re-Identification
$request = new CreateReIdentificationRequest([
"customer" => [
"id" => "example-php",
"email" => "[email protected]",
],
"redirect_uri" => "https://example.com/callback",
"webhook" => "https://example.com/webhook",
]);
$response = $vmc->reIdentification()->createReIdentification($request);

echo "To re-identify, please access: {$response->redirect_uri}\n";

// Wait until verification is approved
while (true) {
echo "Checking status...";
$response = $vmc->reIdentification()->getReIdentification($response->id);
if ($response->status == ReIdentificationStatus::APPROVED) {
echo "\n\nVerification {$response->id} for user {$response->customer->id} is approved!\n";
break;
}

echo " " . $response->status . "\n";
sleep(5);
}
36 changes: 36 additions & 0 deletions examples/re-identification/receiving-webhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use VerifyMyContent\SDK\ReIdentification\Entity\Requests\WebhookReIdentificationRequest;

require_once __DIR__ . "/../../vendor/autoload.php";

$method = $_SERVER['REQUEST_METHOD'];
if ($method !== 'POST') {
http_response_code(405);
exit;
}

try {
$body = file_get_contents("php://input");
$request = new WebhookReIdentificationRequest(json_decode($body, true));

$webhooks = [];
if (file_exists(__DIR__ . "/webhook.log")) {
$webhooks = json_decode(file_get_contents(__DIR__ . "/webhook.log"), true);
}

file_put_contents("webhook.log", json_encode(array_merge($webhooks, [$request->toArray()])));
http_response_code(204);
exit;
}

catch (InvalidArgumentException $e) {
http_response_code(400);
echo "Invalid request: " . $e->getMessage();
exit;
}
catch (Exception $e) {
http_response_code(400);
echo "Invalid JSON";
exit;
}
2 changes: 1 addition & 1 deletion src/ContentModeration/ContentModerationClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getStaticContentModeration(string $id): GetStaticContentModerati
* @return void
* @throws InvalidStatusCodeException
*/
public function startLiveContentModeration(string $id, StartLiveContentModerationRequest $request = null): void;
public function startLiveContentModeration(string $id, ?StartLiveContentModerationRequest $request = null): void;

/**
* @param CreateLiveContentModerationRequest $request
Expand Down
2 changes: 1 addition & 1 deletion src/ContentModeration/ContentModerationClientV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function getStaticContentModeration(string $id): GetStaticContentModerati
* @return void
* @throws InvalidStatusCodeException
*/
public function startLiveContentModeration(string $id, StartLiveContentModerationRequest $request = null): void
public function startLiveContentModeration(string $id, ?StartLiveContentModerationRequest $request = null): void
{
$uri = sprintf(self::ENDPOINT_START_LIVE_CONTENT_MODERATION, $id);
$req = null;
Expand Down
28 changes: 28 additions & 0 deletions src/ReIdentification/Entity/Customer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace VerifyMyContent\SDK\ReIdentification\Entity;

use VerifyMyContent\SDK\Core\DTO;
use VerifyMyContent\SDK\Core\Validator\RequiredValidator;
use VerifyMyContent\SDK\Core\Validator\StringValidator;

/**
* Class Customer
* @package VerifyMyContent\SDK\ReIdentification\Entity
* @property-read string $id
* @property-read string|null $email
*/
final class Customer extends DTO
{
protected $fillable = ['id', 'email'];

protected $validate = [
'id' => [
RequiredValidator::class,
StringValidator::class,
],
'email' => [
StringValidator::class,
],
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace VerifyMyContent\SDK\ReIdentification\Entity\Requests;

use VerifyMyContent\SDK\Core\DTO;
use VerifyMyContent\SDK\Core\Validator\ArrayValidator;
use VerifyMyContent\SDK\Core\Validator\RequiredValidator;
use VerifyMyContent\SDK\Core\Validator\UrlValidator;
use VerifyMyContent\SDK\ReIdentification\Entity\Customer;

/**
* Class CreateReIdentificationRequest
* @package VerifyMyContent\SDK\ReIdentification\Entity\Requests
* @property-read Customer $customer
* @property-read string $redirect_uri
* @property-read string $webhook
*/
final class CreateReIdentificationRequest extends DTO
{
protected $fillable = ['customer', 'redirect_uri', 'webhook'];

protected $validate = [
'customer' => [
RequiredValidator::class,
ArrayValidator::class,
],
'redirect_uri' => UrlValidator::class,
'webhook' => UrlValidator::class,
];

protected $casts = [
'customer' => Customer::class
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace VerifyMyContent\SDK\ReIdentification\Entity\Requests;

use VerifyMyContent\SDK\Core\DTO;
use VerifyMyContent\SDK\Core\Validator\RequiredValidator;
use VerifyMyContent\SDK\Core\Validator\StringValidator;

/**
* Class WebhookReIdentificationRequest
* @package VerifyMyContent\SDK\ReIdentification\Entity\Requests
* @property-read string $id
* @property-read string $customer_id
* @property-read string $status
*/
final class WebhookReIdentificationRequest extends DTO
{
protected $fillable = ['id', 'customer_id', 'status'];

protected $validate = [
'id' => [
RequiredValidator::class,
StringValidator::class,
],
'customer_id' => [
RequiredValidator::class,
StringValidator::class,
],
'status' => [
RequiredValidator::class,
StringValidator::class,
],
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace VerifyMyContent\SDK\ReIdentification\Entity\Responses;

use VerifyMyContent\SDK\Core\DTO;
use VerifyMyContent\SDK\Core\Validator\ArrayValidator;
use VerifyMyContent\SDK\Core\Validator\RequiredValidator;
use VerifyMyContent\SDK\Core\Validator\StringValidator;
use VerifyMyContent\SDK\Core\Validator\UrlValidator;
use VerifyMyContent\SDK\ReIdentification\Entity\Customer;

/**
* Class CreateReIdentificationResponse
* @package VerifyMyContent\SDK\ReIdentification\Entity\Responses
* @property-read string $id
* @property-read string $redirect_uri
* @property-read string $webhook
* @property-read Customer $customer
*/
final class CreateReIdentificationResponse extends DTO
{
protected $fillable = ['id', 'customer', 'redirect_uri', 'webhook'];

protected $validate = [
'id' => [
RequiredValidator::class,
StringValidator::class,
],
'customer' => [
RequiredValidator::class,
ArrayValidator::class,
],
'redirect_uri' => UrlValidator::class,
'webhook' => UrlValidator::class,
];

protected $casts = [
'customer' => Customer::class
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace VerifyMyContent\SDK\ReIdentification\Entity\Responses;

use VerifyMyContent\SDK\Core\DTO;
use VerifyMyContent\SDK\Core\Validator\ArrayValidator;
use VerifyMyContent\SDK\Core\Validator\RequiredValidator;
use VerifyMyContent\SDK\Core\Validator\StringValidator;
use VerifyMyContent\SDK\Core\Validator\UrlValidator;
use VerifyMyContent\SDK\ReIdentification\Entity\Customer;

/**
* Class GetReIdentificationResponse
* @package VerifyMyContent\SDK\ReIdentification\Entity\Responses
* @property-read string $id
* @property-read string $status
* @property-read string $redirect_uri
* @property-read string $webhook
* @property-read Customer $customer
*/
final class GetReIdentificationResponse extends DTO
{
protected $fillable = ['id', 'customer', 'redirect_uri', 'webhook', 'status'];

protected $validate = [
'id' => [
RequiredValidator::class,
StringValidator::class,
],
'customer' => [
RequiredValidator::class,
ArrayValidator::class,
],
'redirect_uri' => UrlValidator::class,
'webhook' => UrlValidator::class,
'status' => [
RequiredValidator::class,
StringValidator::class,
],
];

protected $casts = [
'customer' => Customer::class,
];
}
13 changes: 13 additions & 0 deletions src/ReIdentification/Exception/FeatureNotEnabledException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace VerifyMyContent\SDK\ReIdentification\Exception;

use RuntimeException;

class FeatureNotEnabledException extends RuntimeException
{
public function __construct()
{
parent::__construct('re-identification feature not enabled', 403);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace VerifyMyContent\SDK\ReIdentification\Exception;

use RuntimeException;

class NoApprovedVerificationFoundException extends RuntimeException
{
public function __construct()
{
parent::__construct('no approved verification found for customer', 404);
}
}
Loading
Loading