From 80251fd54db9b34ac38d5a72b36ac333a1433c6f Mon Sep 17 00:00:00 2001 From: mehmet-yoti <111424390+mehmet-yoti@users.noreply.github.com> Date: Mon, 24 Jun 2024 18:47:35 +0300 Subject: [PATCH] Sdk 2357 php failure receipt error details (#355) added failure receipt error details --- .gitignore | 1 + .php-cs-fixer.cache | 2 +- .../app/Http/Controllers/HomeController.php | 2 +- src/Identity/ErrorReason.php | 37 +++++++++ src/Identity/Receipt.php | 17 +++-- src/Identity/ReceiptBuilder.php | 10 +++ src/Identity/ReceiptParser.php | 1 + src/Identity/RequirementNotMetDetails.php | 75 +++++++++++++++++++ src/Identity/WrappedReceipt.php | 13 ++++ tests/Identity/ReceiptTest.php | 12 ++- 10 files changed, 158 insertions(+), 12 deletions(-) create mode 100644 src/Identity/ErrorReason.php create mode 100644 src/Identity/RequirementNotMetDetails.php diff --git a/.gitignore b/.gitignore index 7173c995..b83fe4bd 100755 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ coverage .scannerwork .DS_Store +.php-cs-fixer.cache diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache index 10acb8ef..f684c0c8 100644 --- a/.php-cs-fixer.cache +++ b/.php-cs-fixer.cache @@ -1 +1 @@ -{"php":"8.1.29","version":"3.59.3:v3.59.3#30ba9ecc2b0e5205e578fe29973c15653d9bfd29","indent":" ","lineEnding":"\n","rules":{"array_syntax":{"syntax":"short"},"no_unused_imports":true,"ordered_imports":{"imports_order":["const","class","function"]},"php_unit_fqcn_annotation":true,"phpdoc_return_self_reference":true,"phpdoc_scalar":true},"hashes":{"\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder861\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"6df4324fbc01516f544e380a2fcdad1d","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder3196\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"81fbf5d555938c2c1693fa70c5d2f06b","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder10280\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"6df4324fbc01516f544e380a2fcdad1d","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder2372\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"81fbf5d555938c2c1693fa70c5d2f06b","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder12059\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"01fd3c6b4102578a5cbe7b9ca5a9620b","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder4216\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"2b29b8fd1369f029fdd2626aff9574a1","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder7923\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"a92ce4d8cf8cba9fc31b0b862a238e7d","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder9888\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"99cf5679ad3fbe693f1318efc4c7562e","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder7837\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"29258793b15beceaafceef4b742beca0","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder5368\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/FailureReasonResponse.php":"9f3471f97753fd479ff323dbab8f8ff8","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder9615\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/FailureReasonResponse.php":"fa7416c72cb9a21e375a580d0711b4a3","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder2220\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/FailureReasonResponse.php":"3f1b675e645966f11d6fe283ff3d1a5c","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder10144\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/FailureReasonResponse.php":"9f3471f97753fd479ff323dbab8f8ff8","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder7956\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"29258793b15beceaafceef4b742beca0"}} \ No newline at end of file +{"php":"8.1.29","version":"3.59.3:v3.59.3#30ba9ecc2b0e5205e578fe29973c15653d9bfd29","indent":" ","lineEnding":"\n","rules":{"array_syntax":{"syntax":"short"},"no_unused_imports":true,"ordered_imports":{"imports_order":["const","class","function"]},"php_unit_fqcn_annotation":true,"phpdoc_return_self_reference":true,"phpdoc_scalar":true},"hashes":{"\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder861\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"6df4324fbc01516f544e380a2fcdad1d","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder3196\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"81fbf5d555938c2c1693fa70c5d2f06b","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder10280\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"6df4324fbc01516f544e380a2fcdad1d","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder2372\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"81fbf5d555938c2c1693fa70c5d2f06b","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder12059\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"01fd3c6b4102578a5cbe7b9ca5a9620b","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder4216\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"2b29b8fd1369f029fdd2626aff9574a1","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder7923\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"a92ce4d8cf8cba9fc31b0b862a238e7d","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder9888\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"99cf5679ad3fbe693f1318efc4c7562e","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder7837\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"29258793b15beceaafceef4b742beca0","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder5368\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/FailureReasonResponse.php":"9f3471f97753fd479ff323dbab8f8ff8","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder9615\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/FailureReasonResponse.php":"fa7416c72cb9a21e375a580d0711b4a3","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder2220\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/FailureReasonResponse.php":"3f1b675e645966f11d6fe283ff3d1a5c","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder10144\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/FailureReasonResponse.php":"9f3471f97753fd479ff323dbab8f8ff8","\/private\/var\/folders\/hs\/kw0d0_0d2kj8xl5yd5_t2rz40000gn\/T\/PHP CS Fixertemp_folder7956\/src\/DocScan\/Session\/Retrieve\/IdentityProfile\/RequirementNotMetDetails.php":"29258793b15beceaafceef4b742beca0"}} diff --git a/examples/doc-scan/app/Http/Controllers/HomeController.php b/examples/doc-scan/app/Http/Controllers/HomeController.php index c00c723e..9bd67d01 100644 --- a/examples/doc-scan/app/Http/Controllers/HomeController.php +++ b/examples/doc-scan/app/Http/Controllers/HomeController.php @@ -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']) diff --git a/src/Identity/ErrorReason.php b/src/Identity/ErrorReason.php new file mode 100644 index 00000000..787fbf1e --- /dev/null +++ b/src/Identity/ErrorReason.php @@ -0,0 +1,37 @@ +> $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; + } +} diff --git a/src/Identity/Receipt.php b/src/Identity/Receipt.php index 57458bc7..162761f2 100644 --- a/src/Identity/Receipt.php +++ b/src/Identity/Receipt.php @@ -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, @@ -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; @@ -43,6 +38,7 @@ public function __construct( $this->rememberMeId = $rememberMeId; $this->parentRememberMeId = $parentRememberMeId; $this->error = $error; + $this->errorReason = $errorReason; } public function getId(): string @@ -94,4 +90,9 @@ public function getError(): ?string { return $this->error; } + + public function getErrorReason(): ?ErrorReason + { + return $this->errorReason; + } } diff --git a/src/Identity/ReceiptBuilder.php b/src/Identity/ReceiptBuilder.php index 9bed933f..7a091388 100644 --- a/src/Identity/ReceiptBuilder.php +++ b/src/Identity/ReceiptBuilder.php @@ -25,6 +25,8 @@ class ReceiptBuilder private ?string $parentRememberMeId = null; private ?string $error = null; + private ?ErrorReason $errorReason = null; + public function withId(string $id): self { @@ -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( @@ -93,6 +102,7 @@ public function build(): Receipt $this->rememberMeId, $this->parentRememberMeId, $this->error, + $this->errorReason ); } } diff --git a/src/Identity/ReceiptParser.php b/src/Identity/ReceiptParser.php index 5847a438..375249da 100644 --- a/src/Identity/ReceiptParser.php +++ b/src/Identity/ReceiptParser.php @@ -89,6 +89,7 @@ public function createFailure(WrappedReceipt $wrappedReceipt): Receipt ->withSessionId($wrappedReceipt->getSessionId()) ->withTimestamp($wrappedReceipt->getTimestamp()) ->withError($wrappedReceipt->getError()) + ->withErrorReason($wrappedReceipt->getErrorReason()) ->build(); } diff --git a/src/Identity/RequirementNotMetDetails.php b/src/Identity/RequirementNotMetDetails.php new file mode 100644 index 00000000..bcd3e40e --- /dev/null +++ b/src/Identity/RequirementNotMetDetails.php @@ -0,0 +1,75 @@ +> $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; + } +} diff --git a/src/Identity/WrappedReceipt.php b/src/Identity/WrappedReceipt.php index 8d7c04c4..7d1f4b74 100644 --- a/src/Identity/WrappedReceipt.php +++ b/src/Identity/WrappedReceipt.php @@ -28,6 +28,7 @@ class WrappedReceipt private ?string $parentRememberMeId = null; private ?string $error = null; + private ?ErrorReason $errorReason = null; /** * @param array $sessionData @@ -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 @@ -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); diff --git a/tests/Identity/ReceiptTest.php b/tests/Identity/ReceiptTest.php index adbc392e..73c3b29e 100644 --- a/tests/Identity/ReceiptTest.php +++ b/tests/Identity/ReceiptTest.php @@ -4,6 +4,7 @@ use Yoti\Identity\Content\ApplicationContent; use Yoti\Identity\Content\UserContent; +use Yoti\Identity\ErrorReason; use Yoti\Identity\Receipt; use Yoti\Identity\ReceiptBuilder; use Yoti\Profile\ApplicationProfile; @@ -20,6 +21,7 @@ class ReceiptTest extends TestCase * @covers ::getProfile * @covers ::getId * @covers ::getError + * @covers ::getErrorReason * @covers ::getApplicationContent * @covers ::getTimestamp * @covers ::getParentRememberMeId @@ -38,6 +40,7 @@ public function testShouldBuildCorrectly() $rememberId = 'SOME_REMEMBER_ID'; $parentRememberId = 'SOME_PARENT_REMEMBER_ID'; $someError = 'SOME_ERROR'; + $someErrorReason = $this->createMock(ErrorReason::class); $receipt = new Receipt( $someId, @@ -47,7 +50,8 @@ public function testShouldBuildCorrectly() $userContent, $rememberId, $parentRememberId, - $someError + $someError, + $someErrorReason ); $this->assertEquals($someId, $receipt->getId()); @@ -58,10 +62,12 @@ public function testShouldBuildCorrectly() $this->assertEquals($rememberId, $receipt->getRememberMeId()); $this->assertEquals($parentRememberId, $receipt->getParentRememberMeId()); $this->assertEquals($someError, $receipt->getError()); + $this->assertEquals($someErrorReason, $receipt->getErrorReason()); } /** * @covers \Yoti\Identity\ReceiptBuilder::withError + * @covers \Yoti\Identity\ReceiptBuilder::withErrorReason * @covers \Yoti\Identity\ReceiptBuilder::withApplicationContent * @covers \Yoti\Identity\ReceiptBuilder::withId * @covers \Yoti\Identity\ReceiptBuilder::withTimestamp @@ -81,6 +87,7 @@ public function testShouldBuildCorrectlyThroughBuilder() $rememberId = 'SOME_REMEMBER_ID'; $parentRememberId = 'SOME_PARENT_REMEMBER_ID'; $someError = 'SOME_ERROR'; + $someErrorReason = $this->createMock(ErrorReason::class); $receipt = (new ReceiptBuilder()) ->withId($someId) @@ -91,9 +98,9 @@ public function testShouldBuildCorrectlyThroughBuilder() ->withRememberMeId($rememberId) ->withParentRememberMeId($parentRememberId) ->withError($someError) + ->withErrorReason($someErrorReason) ->build(); - $this->assertEquals($someId, $receipt->getId()); $this->assertEquals($sessionId, $receipt->getSessionId()); $this->assertEquals($someTime, $receipt->getTimestamp()); @@ -102,5 +109,6 @@ public function testShouldBuildCorrectlyThroughBuilder() $this->assertEquals($rememberId, $receipt->getRememberMeId()); $this->assertEquals($parentRememberId, $receipt->getParentRememberMeId()); $this->assertEquals($someError, $receipt->getError()); + $this->assertEquals($someErrorReason, $receipt->getErrorReason()); } }