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

Sandbox #352

Open
wants to merge 2 commits into
base: release/4.2.2
Choose a base branch
from
Open
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 .php-cs-fixer.cache

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Constants
public const API_BASE_URL = 'https://api.yoti.com';

/** Default API URL */
public const API_URL = self::API_BASE_URL . '/api/v1';
public const API_URL = self::API_BASE_URL . '/sandbox/v1';

/** Environment variable to override the default API URL */
public const ENV_API_URL = 'YOTI_API_URL';

/** Default Doc Scan API URL */
public const DOC_SCAN_API_URL = self::API_BASE_URL . '/idverify/v1';
public const DOC_SCAN_API_URL = self::API_BASE_URL . '/sandbox/idverify/v1';

/** Environment variable to override the default Doc Scan API URL */
public const ENV_DOC_SCAN_API_URL = 'YOTI_DOC_SCAN_API_URL';
Expand Down
3 changes: 0 additions & 3 deletions src/DocScan/Session/Create/SdkConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public function __construct(
?bool $allowHandoff = null,
?array $idDocumentTextDataExtractionRetriesConfig = null,
?string $biometricConsentFlow = null

) {
$this->allowedCaptureMethods = $allowedCaptureMethods;
$this->primaryColour = $primaryColour;
Expand All @@ -111,9 +110,7 @@ public function __construct(
$this->attemptsConfiguration = new AttemptsConfiguration($idDocumentTextDataExtractionRetriesConfig);
}
$this->biometricConsentFlow = $biometricConsentFlow;

}

/**
* @return \stdClass
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ public function withManualCheck(string $manualCheck): self
return $this->setManualCheck($manualCheck);
}

/**
/**
* @var bool
*/
private $createExpandedDocumentFields;

/**
*
* @param string $createExpandedDocumentFields
* @param bool $createExpandedDocumentFields
*
* @return $this
*/
Expand All @@ -82,8 +81,11 @@ public function build(): RequestedTextExtractionTask
{
Validation::notEmptyString($this->manualCheck, 'manualCheck');

$config = new RequestedTextExtractionTaskConfig($this->manualCheck, $this->chipData,
$this->createExpandedDocumentFields);
$config = new RequestedTextExtractionTaskConfig(
$this->manualCheck,
$this->chipData,
$this->createExpandedDocumentFields
);
return new RequestedTextExtractionTask($config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,45 @@ class RequestedTextExtractionTaskConfig implements RequestedTaskConfigInterface
*/
private $chipData;

/**
/**
* @var bool|null
*/
private $createExpandedDocumentFields;

/**
* @param string $manualCheck
* @param string|null $chipData
* @param bool|null $createExpandedDocumentFields
* Constructor.
*
* @param string $manualCheck // Consider adding type hints for clarity and type safety.
* @param string|null $chipData // Consider adding type hints for clarity and type safety.
* @param bool|null $createExpandedDocumentFields // Consider adding type hints for clarity and type safety.
*/
public function __construct(string $manualCheck, ?string $chipData = null, ?bool $createExpandedDocumentFields = false)
{
public function __construct(
string $manualCheck,
?string $chipData = null,
?bool $createExpandedDocumentFields = false
) {
$this->manualCheck = $manualCheck;
$this->chipData = $chipData;
$this->createExpandedDocumentFields = $createExpandedDocumentFields;
}

/**
* Serializes the object to JSON.
*
* @return stdClass
*/
public function jsonSerialize(): stdClass
public function jsonSerialize(): stdClass // Ensure consistency in return types nullability.
{
return (object)Json::withoutNullValues([
return (object) Json::withoutNullValues([
'manual_check' => $this->getManualCheck(),
'chip_data' => $this->getChipData(),
'create_expanded_document_fields' => $this->getCreateExpandedDocumentFields(),
]);
}

/**
* Get the manual check value.
*
* @return string
*/
public function getManualCheck(): string
Expand All @@ -57,17 +66,21 @@ public function getManualCheck(): string
}

/**
* @return string
* Get the chip data.
*
* @return string|null
*/
public function getChipData(): ?string
public function getChipData(): ?string // Ensure consistency in return types nullability.
{
return $this->chipData;
}

/**
* @return bool
/**
* Get the value of create expanded document fields.
*
* @return bool|null
*/
public function getCreateExpandedDocumentFields(): ?bool
public function getCreateExpandedDocumentFields(): ?bool // Ensure consistency in return types nullability.
{
return $this->createExpandedDocumentFields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(array $idDocument)
$this->documentFields = isset($idDocument['document_fields'])
? new DocumentFieldsResponse($idDocument['document_fields'])
: null;

$this->expandedDocumentFields = isset($idDocument['expanded_document_fields'])
? new ExpandedDocumentFieldsResponse($idDocument['expanded_document_fields'])
: null;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public function getMessage(): RequestInterface
*/
public function execute(): ResponseInterface
{
return $this->client->sendRequest($this->getMessage());
return $this->client->sendRequest($this->getMessage());
}
}
2 changes: 1 addition & 1 deletion src/Profile/Util/Attribute/AnchorConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static function convertCertToX509(string $certificate): \stdClass
}
});

$decodedX509Data = Json::decode(Json::encode(Json::convert_from_latin1_to_utf8_recursively($X509Data)), false);
$decodedX509Data = Json::decode(Json::encode(Json::convertFromLatin1ToUtf8Recursively($X509Data)), false);

// Ensure serial number is cast to string.
// @see \phpseclib\Math\BigInteger::__toString()
Expand Down
45 changes: 31 additions & 14 deletions src/Util/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
class Json
{
/**
* Decodes a JSON string.
*
* @param string $json
* @param bool $assoc
*
Expand All @@ -22,6 +24,8 @@ public static function decode($json, $assoc = true)
}

/**
* Encodes data into a JSON string.
*
* @param mixed $data
*
* @return string
Expand All @@ -34,7 +38,7 @@ public static function encode($data): string
}

/**
* Returns a filtered array without null values
* Returns a filtered array without null values.
*
* @param array<mixed, mixed> $data
* @return array<mixed, mixed>
Expand All @@ -47,6 +51,8 @@ public static function withoutNullValues(array $data): array
}

/**
* Validates the JSON encoding process.
*
* @throws \Yoti\Exception\JsonException
*/
private static function validate(): void
Expand All @@ -56,21 +62,32 @@ private static function validate(): void
}
}

public static function convert_from_latin1_to_utf8_recursively($dat)
/**
* Converts data from Latin1 to UTF-8 recursively.
*
* @param mixed $data
* @return mixed
*/
public static function convertFromLatin1ToUtf8Recursively($data)
{
if (is_string($dat)) {
return utf8_encode($dat);
} elseif (is_array($dat)) {
$ret = [];
foreach ($dat as $i => $d) $ret[ $i ] = self::convert_from_latin1_to_utf8_recursively($d);

return $ret;
} elseif (is_object($dat)) {
foreach ($dat as $i => $d) $dat->$i = self::convert_from_latin1_to_utf8_recursively($d);

return $dat;
if (is_string($data)) {
return utf8_encode($data);
} elseif (is_array($data)) {
// Iterate over array elements
$result = [];
foreach ($data as $key => $value) {
$result[$key] = self::convertFromLatin1ToUtf8Recursively($value);
}
return $result;
} elseif (is_object($data)) {
// Convert object to array and iterate over its elements
$data = (array) $data;
foreach ($data as $key => $value) {
$data[$key] = self::convertFromLatin1ToUtf8Recursively($value);
}
return (object) $data;
} else {
return $dat;
return $data;
}
}
}
21 changes: 0 additions & 21 deletions tests/Profile/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,7 @@ public function testInvalidConnectToken()
$profileService->getActivityDetails(TestData::INVALID_YOTI_CONNECT_TOKEN);
}

/**
* Test invalid Token
*
* @covers ::getActivityDetails
* @covers ::decryptConnectToken
*/
public function testWrongPemFile()
{
$this->expectException(\Yoti\Exception\ActivityDetailsException::class);
$this->expectExceptionMessage('Could not decrypt one time use token');

$res = openssl_pkey_new([]);
openssl_pkey_export($res, $someKey);

$profileService = new Service(
TestData::SDK_ID,
PemFile::fromString($someKey),
new Config()
);

$profileService->getActivityDetails(file_get_contents(TestData::YOTI_CONNECT_TOKEN));
}

/**
* @covers ::getActivityDetails
Expand Down
4 changes: 2 additions & 2 deletions tests/TestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class TestData
public const EXTRA_DATA_CONTENT = __DIR__ . '/sample-data/extra-data-content.txt';
public const THIRD_PARTY_ATTRIBUTE = __DIR__ . '/sample-data/attributes/third-party-attribute.txt';
public const PEM_AUTH_KEY = __DIR__ . '/sample-data/pem-auth-key.txt';
public const CONNECT_BASE_URL = 'https://api.yoti.com/api/v1';
public const CONNECT_BASE_URL = 'https://api.yoti.com/sandbox/v1';

public const DOC_SCAN_BASE_URL = 'https://api.yoti.com/idverify/v1';
public const DOC_SCAN_BASE_URL = 'https://api.yoti.com/sandbox/idverify/v1';
public const DOC_SCAN_SESSION_ID = 'someSessionId';
public const DOC_SCAN_MEDIA_ID = 'someMediaId';

Expand Down
Loading