Skip to content

Commit

Permalink
SDK-2377 added failure reasons to idv (#356)
Browse files Browse the repository at this point in the history
added failure reasons to idv
added failure receipt error details
  • Loading branch information
mehmet-yoti authored Jun 24, 2024
1 parent 5b3c526 commit 399e849
Show file tree
Hide file tree
Showing 17 changed files with 294 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ coverage
.scannerwork

.DS_Store
.php-cs-fixer.cache
2 changes: 1 addition & 1 deletion .php-cs-fixer.cache

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/doc-scan/app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function show(Request $request, DocScanClient $client)
->withSources($searchProfileSources)
->withShareUrl(false)
->withRemoveDeceased(true)
->withApiKey('qiKTHG7Mgqj31mK2d21F7QPpaVBp9zKc')
->withApiKey('api-key')
->withClientRef("string")
->withMonitoring(true)
->withTags(['tag1'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,32 @@ class FailureReasonResponse
/**
* @var string
*/
private $stringCode;

private $reasonCode;
/**
* @var RequirementNotMetDetails
*/
private $requirementsNotMetDetails;
/**
* @param string $stringCode
* @param array<string, mixed> $data
*/
public function __construct(string $stringCode)
public function __construct(array $data)
{
$this->stringCode = $stringCode;
$this->reasonCode = $data["reason_code"];
$this->requirementsNotMetDetails = new RequirementNotMetDetails($data["requirements_not_met_details"]);
}

/**
* @return string
*/
public function getStringCode(): string
public function getReasonCode(): string
{
return $this->reasonCode;
}
/**
* @return RequirementNotMetDetails
*/
public function getRequirementNotMetDetails(): RequirementNotMetDetails
{
return $this->stringCode;
return $this->requirementsNotMetDetails;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Yoti\DocScan\Session\Retrieve\IdentityProfile;

class RequirementNotMetDetails
{
/**
* @var string
*/
private $failureType;
/**
* @var string
*/
private $documentType;
/**
* @var string
*/
private $documentCountryIsoCode;
/**
* @var string
*/
private $auditId;
/**
* @var string
*/
private $details;

/**
* @param array<int, array<string, string>> $data
*/
public function __construct(array $data)
{
$this->failureType = $data[0]["failure_type"] ?? '';
$this->details = $data[0]["details"] ?? '';
$this->auditId = $data[0]["audit_id"] ?? '';
$this->documentCountryIsoCode = $data[0]["document_country_iso_code"] ?? '';
$this->documentType = $data[0]["document_type"] ?? '';
}

/**
* @return string
*/
public function getFailureType(): string
{
return $this->failureType;
}
/**
* @return string
*/
public function getDetails(): string
{
return $this->details;
}
/**
* @return string
*/
public function getAuditId(): string
{
return $this->auditId;
}
/**
* @return string
*/
public function getDocumentCountryIsoCode(): string
{
return $this->documentCountryIsoCode;
}
/**
* @return string
*/
public function getDocumentType(): string
{
return $this->documentType;
}
}
2 changes: 1 addition & 1 deletion src/DocScan/Session/Retrieve/IdentityProfileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(array $sessionData)
$this->result = $sessionData['result'];

if (isset($sessionData['failure_reason'])) {
$this->failureReason = new FailureReasonResponse($sessionData['failure_reason']['reason_code']);
$this->failureReason = new FailureReasonResponse($sessionData['failure_reason']);
}

if (isset($sessionData['identity_profile_report'])) {
Expand Down
37 changes: 37 additions & 0 deletions src/Identity/ErrorReason.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Yoti\Identity;

class ErrorReason
{
/**
* @var RequirementNotMetDetails
*/
private $requirementNotMetDetails;

/**
* @param array<int, array<string, string>> $data
*/
public function __construct(array $data)
{
if (isset($data[0])) {
$this->requirementNotMetDetails = new RequirementNotMetDetails($data);
} else {
$this->requirementNotMetDetails = new RequirementNotMetDetails([[
"failure_type" => '',
"details" => '',
"audit_id" => '',
"document_country_iso_code" => '',
"document_type" => ''
]]);
}
}

/**
* @return RequirementNotMetDetails
*/
public function getRequirementNotMetDetails(): RequirementNotMetDetails
{
return $this->requirementNotMetDetails;
}
}
17 changes: 9 additions & 8 deletions src/Identity/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@
class Receipt
{
private string $id;

private string $sessionId;

private \DateTime $timestamp;

private ApplicationContent $applicationContent;

private UserContent $userContent;

private ?string $rememberMeId;

private ?string $parentRememberMeId;

private ?string $error;
private ?ErrorReason $errorReason;

public function __construct(
string $id,
Expand All @@ -33,7 +27,8 @@ public function __construct(
UserContent $userContent,
?string $rememberMeId,
?string $parentRememberMeId,
?string $error
?string $error,
?ErrorReason $errorReason
) {
$this->id = $id;
$this->sessionId = $sessionId;
Expand All @@ -43,6 +38,7 @@ public function __construct(
$this->rememberMeId = $rememberMeId;
$this->parentRememberMeId = $parentRememberMeId;
$this->error = $error;
$this->errorReason = $errorReason;
}

public function getId(): string
Expand Down Expand Up @@ -94,4 +90,9 @@ public function getError(): ?string
{
return $this->error;
}

public function getErrorReason(): ?ErrorReason
{
return $this->errorReason;
}
}
10 changes: 10 additions & 0 deletions src/Identity/ReceiptBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ReceiptBuilder
private ?string $parentRememberMeId = null;

private ?string $error = null;
private ?ErrorReason $errorReason = null;


public function withId(string $id): self
{
Expand Down Expand Up @@ -82,6 +84,13 @@ public function withError(string $error = null): self
return $this;
}

public function withErrorReason(ErrorReason $errorReason = null): self
{
$this->errorReason = $errorReason;

return $this;
}

public function build(): Receipt
{
return new Receipt(
Expand All @@ -93,6 +102,7 @@ public function build(): Receipt
$this->rememberMeId,
$this->parentRememberMeId,
$this->error,
$this->errorReason
);
}
}
1 change: 1 addition & 0 deletions src/Identity/ReceiptParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function createFailure(WrappedReceipt $wrappedReceipt): Receipt
->withSessionId($wrappedReceipt->getSessionId())
->withTimestamp($wrappedReceipt->getTimestamp())
->withError($wrappedReceipt->getError())
->withErrorReason($wrappedReceipt->getErrorReason())
->build();
}

Expand Down
75 changes: 75 additions & 0 deletions src/Identity/RequirementNotMetDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Yoti\Identity;

class RequirementNotMetDetails
{
/**
* @var string
*/
private $failureType;
/**
* @var string
*/
private $documentType;
/**
* @var string
*/
private $documentCountryIsoCode;
/**
* @var string
*/
private $auditId;
/**
* @var string
*/
private $details;

/**
* @param array<int, array<string, string>> $data
*/
public function __construct(array $data)
{
$this->failureType = $data[0]["failure_type"] ?? '';
$this->details = $data[0]["details"] ?? '';
$this->auditId = $data[0]["audit_id"] ?? '';
$this->documentCountryIsoCode = $data[0]["document_country_iso_code"] ?? '';
$this->documentType = $data[0]["document_type"] ?? '';
}

/**
* @return string
*/
public function getFailureType(): string
{
return $this->failureType;
}
/**
* @return string
*/
public function getDetails(): string
{
return $this->details;
}
/**
* @return string
*/
public function getAuditId(): string
{
return $this->auditId;
}
/**
* @return string
*/
public function getDocumentCountryIsoCode(): string
{
return $this->documentCountryIsoCode;
}
/**
* @return string
*/
public function getDocumentType(): string
{
return $this->documentType;
}
}
13 changes: 13 additions & 0 deletions src/Identity/WrappedReceipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WrappedReceipt
private ?string $parentRememberMeId = null;

private ?string $error = null;
private ?ErrorReason $errorReason = null;

/**
* @param array<string, mixed> $sessionData
Expand Down Expand Up @@ -62,6 +63,13 @@ public function __construct(array $sessionData)
if (isset($sessionData['error'])) {
$this->error = $sessionData['error'];
}
if (isset($sessionData['errorDetails'])) {
if (isset($sessionData["error_details"]["error_reason"]["requirements_not_met_details"])) {
$this->errorReason = new ErrorReason(
$sessionData['errorDetails']['error_reason']['requirements_not_met_details']
);
}
}
}

public function getId(): string
Expand Down Expand Up @@ -132,6 +140,11 @@ public function getError(): ?string
return $this->error;
}

public function getErrorReason(): ?ErrorReason
{
return $this->errorReason;
}

private function base64decode(string $encoded): string
{
$decoded = base64_decode($encoded, true);
Expand Down
2 changes: 1 addition & 1 deletion tests/DocScan/DocScanClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ public function testParseIdentityProfileResponse()
$this->assertEquals('someStringHere', $sessionResult->getIdentityProfile()->getSubjectId());
$this->assertEquals(
'MANDATORY_DOCUMENT_COULD_NOT_BE_PROVIDED',
$sessionResult->getIdentityProfile()->getFailureReason()->getStringCode()
$sessionResult->getIdentityProfile()->getFailureReason()->getReasonCode()
);

$this->assertEquals(
Expand Down
Loading

0 comments on commit 399e849

Please sign in to comment.