-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1aa285c
commit c8d0316
Showing
18 changed files
with
1,256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yoti\Sandbox\Aml; | ||
|
||
use stdClass; | ||
use Yoti\Util\Json; | ||
|
||
class SandboxAddress implements \JsonSerializable | ||
{ | ||
private const POSTCODE_ATTR = 'post_code'; | ||
private const COUNTRY_ATTR = 'country'; | ||
|
||
/** | ||
* @var ?string | ||
*/ | ||
private $postcode; | ||
|
||
/** | ||
* @var \Yoti\Sandbox\Aml\SandboxCountry | ||
*/ | ||
private $country; | ||
|
||
/** | ||
* AmlAddress constructor. | ||
* | ||
* @param \Yoti\Sandbox\Aml\SandboxCountry $country | ||
* @param null|string $postcode | ||
*/ | ||
public function __construct(SandboxCountry $country, ?string $postcode = null) | ||
{ | ||
$this->country = $country; | ||
$this->postcode = $postcode; | ||
} | ||
|
||
/** | ||
* @return \Yoti\Sandbox\Aml\SandboxCountry | ||
*/ | ||
public function getCountry(): SandboxCountry | ||
{ | ||
return $this->country; | ||
} | ||
|
||
/** | ||
* @return null|string | ||
*/ | ||
public function getPostcode(): ?string | ||
{ | ||
return $this->postcode; | ||
} | ||
|
||
/** | ||
* Get address data. | ||
* | ||
* @return stdClass | ||
*/ | ||
public function jsonSerialize(): stdClass | ||
{ | ||
return (object) [ | ||
self::POSTCODE_ATTR => $this->getPostcode(), | ||
self::COUNTRY_ATTR => $this->getCountry(), | ||
]; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString(): string | ||
{ | ||
return Json::encode($this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yoti\Sandbox\Aml; | ||
|
||
class SandboxCountry implements \JsonSerializable | ||
{ | ||
/** | ||
* Country code. | ||
* | ||
* @var string | ||
*/ | ||
private $code; | ||
|
||
/** | ||
* @param string $code | ||
*/ | ||
public function __construct(string $code) | ||
{ | ||
$this->code = $code; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCode(): string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function jsonSerialize(): string | ||
{ | ||
return $this->getCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yoti\Sandbox\Aml; | ||
|
||
use stdClass; | ||
use Yoti\Util\Json; | ||
|
||
class SandboxProfile implements \JsonSerializable | ||
{ | ||
private const GIVEN_NAMES_ATTR = 'given_names'; | ||
private const FAMILY_NAME_ATTR = 'family_name'; | ||
private const SSN_ATTR = 'ssn'; | ||
private const ADDRESS_ATTR = 'address'; | ||
|
||
/** | ||
* Given Names. | ||
* | ||
* @var string | ||
*/ | ||
private $givenNames; | ||
|
||
/** | ||
* Family Name. | ||
* | ||
* @var string | ||
*/ | ||
private $familyName; | ||
|
||
/** | ||
* Social Security number. | ||
* | ||
* @var null|string | ||
*/ | ||
private $ssn; | ||
|
||
/** | ||
* Full address. | ||
* | ||
* @var \Yoti\Sandbox\Aml\Address | ||
*/ | ||
private $amlAddress; | ||
|
||
/** | ||
* Profile constructor. | ||
* | ||
* @param string $givenNames | ||
* @param string $familyName | ||
* @param \Yoti\Aml\Address $amlAddress | ||
* @param null|string $ssn | ||
*/ | ||
public function __construct($givenNames, $familyName, SandboxAddress $amlAddress, string $ssn = null) | ||
{ | ||
$this->givenNames = $givenNames; | ||
$this->familyName = $familyName; | ||
$this->ssn = $ssn; | ||
$this->amlAddress = $amlAddress; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getGivenNames(): string | ||
{ | ||
return $this->givenNames; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getFamilyName(): string | ||
{ | ||
return $this->familyName; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getSsn(): ?string | ||
{ | ||
return $this->ssn; | ||
} | ||
|
||
/** | ||
* @return \Yoti\Sandbox\Aml\SandboxAddress | ||
*/ | ||
public function getAmlAddress(): SandboxAddress | ||
{ | ||
return $this->amlAddress; | ||
} | ||
|
||
/** | ||
* Get Aml profile data. | ||
* | ||
* @return stdClass | ||
*/ | ||
public function jsonSerialize(): stdClass | ||
{ | ||
return (object) [ | ||
self::GIVEN_NAMES_ATTR => $this->getGivenNames(), | ||
self::FAMILY_NAME_ATTR => $this->getFamilyName(), | ||
self::SSN_ATTR => $this->getSsn(), | ||
self::ADDRESS_ATTR => $this->getAmlAddress(), | ||
]; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString(): string | ||
{ | ||
return Json::encode($this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yoti\Sandbox\Aml; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Yoti\Sandbox\Exception\SandboxAmlException; | ||
use Yoti\Util\Json; | ||
|
||
class SandboxResult | ||
{ | ||
private const ON_PEP_LIST_KEY = 'on_pep_list'; | ||
private const ON_FRAUD_LIST_KEY = 'on_fraud_list'; | ||
private const ON_WATCH_LIST_KEY = 'on_watch_list'; | ||
|
||
/** | ||
* Politically exposed person. | ||
* | ||
* @var bool | ||
*/ | ||
private $onPepList; | ||
|
||
/** | ||
* Fraud list. | ||
* | ||
* @var bool | ||
*/ | ||
private $onFraudList; | ||
|
||
/** | ||
* Watch list. | ||
* | ||
* @var bool | ||
*/ | ||
private $onWatchList; | ||
|
||
/** | ||
* Raw result. | ||
* | ||
* @var array<string, mixed> | ||
*/ | ||
private $rawResult; | ||
|
||
/** | ||
* AmlResult constructor. | ||
* | ||
* @param array<string, bool> $result | ||
* @param ResponseInterface $response | ||
* | ||
* @throws \Yoti\Sandbox\Exception\SandboxAmlException | ||
*/ | ||
public function __construct(array $result, ResponseInterface $response) | ||
{ | ||
$this->rawResult = $result; | ||
$this->setAttributes($response); | ||
} | ||
|
||
/** | ||
* Check if user is a politically exposed person. | ||
* | ||
* @return bool | ||
*/ | ||
public function isOnPepList(): bool | ||
{ | ||
return $this->onPepList; | ||
} | ||
|
||
/** | ||
* Check if user is on a fraud list. | ||
* | ||
* @return bool | ||
*/ | ||
public function isOnFraudList(): bool | ||
{ | ||
return $this->onFraudList; | ||
} | ||
|
||
/** | ||
* Check if user is on a watch list. | ||
* | ||
* @return bool | ||
*/ | ||
public function isOnWatchList(): bool | ||
{ | ||
return $this->onWatchList; | ||
} | ||
|
||
/** | ||
* Set attribute values. | ||
* | ||
* @param ResponseInterface $response | ||
* | ||
* @throws \Yoti\Sandbox\Exception\SandboxAmlException | ||
*/ | ||
private function setAttributes(ResponseInterface $response): void | ||
{ | ||
$result = $this->rawResult; | ||
// Check if no attribute is missing from the result | ||
self::checkAttributes($result, $response); | ||
|
||
$this->onPepList = (bool) $result[self::ON_PEP_LIST_KEY]; | ||
$this->onFraudList = (bool) $result[self::ON_FRAUD_LIST_KEY]; | ||
$this->onWatchList = (bool) $result[self::ON_WATCH_LIST_KEY]; | ||
} | ||
|
||
/** | ||
* Check if all the attributes are included in the result. | ||
* | ||
* @param array<string, bool> $result | ||
* @param ResponseInterface $response | ||
* | ||
* @throws \Yoti\Sandbox\Exception\SandboxAmlException | ||
*/ | ||
public static function checkAttributes(array $result, ResponseInterface $response): void | ||
{ | ||
$expectedAttributes = [ | ||
self::ON_PEP_LIST_KEY, | ||
self::ON_WATCH_LIST_KEY, | ||
self::ON_WATCH_LIST_KEY, | ||
]; | ||
$providedAttributes = array_keys($result); | ||
$missingAttr = array_diff($expectedAttributes, $providedAttributes); | ||
|
||
// Throw an error if any expected attribute is missing. | ||
if (count($missingAttr) > 0) { | ||
throw new SandboxAmlException('Missing attributes from the result: ' . implode(',', $missingAttr), $response); | ||
} | ||
} | ||
|
||
/** | ||
* Returns json string of the raw data. | ||
* | ||
* @return string | ||
*/ | ||
public function __toString(): string | ||
{ | ||
return Json::encode($this->rawResult); | ||
} | ||
} |
Oops, something went wrong.