Skip to content

Commit

Permalink
SDK-2357 Added Error Reason to Digital Identity
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmet-yoti committed Jun 20, 2024
1 parent a46dd7e commit d2f500c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.cache

Large diffs are not rendered by default.

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 ?string $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,
?string $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(): ?string
{
return $this->errorReason;
}
}
11 changes: 11 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 ?string $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(string $errorReason = null): self
{
$this->errorReason = $errorReason;

return $this;
}

public function build(): Receipt
{
return new Receipt(
Expand All @@ -93,6 +102,8 @@ 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
9 changes: 9 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 ?string $errorReason = null;

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

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

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

private function base64decode(string $encoded): string
{
$decoded = base64_decode($encoded, true);
Expand Down
11 changes: 9 additions & 2 deletions tests/Identity/ReceiptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ReceiptTest extends TestCase
* @covers ::getProfile
* @covers ::getId
* @covers ::getError
* @covers ::getErrorReason
* @covers ::getApplicationContent
* @covers ::getTimestamp
* @covers ::getParentRememberMeId
Expand All @@ -38,6 +39,7 @@ public function testShouldBuildCorrectly()
$rememberId = 'SOME_REMEMBER_ID';
$parentRememberId = 'SOME_PARENT_REMEMBER_ID';
$someError = 'SOME_ERROR';
$someErrorReason = 'SOME_ERROR_REASON';

$receipt = new Receipt(
$someId,
Expand All @@ -47,7 +49,8 @@ public function testShouldBuildCorrectly()
$userContent,
$rememberId,
$parentRememberId,
$someError
$someError,
$someErrorReason
);

$this->assertEquals($someId, $receipt->getId());
Expand All @@ -58,10 +61,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
Expand All @@ -81,6 +86,7 @@ public function testShouldBuildCorrectlyThroughBuilder()
$rememberId = 'SOME_REMEMBER_ID';
$parentRememberId = 'SOME_PARENT_REMEMBER_ID';
$someError = 'SOME_ERROR';
$someErrorReason = 'SOME_ERROR_REASON';

$receipt = (new ReceiptBuilder())
->withId($someId)
Expand All @@ -91,9 +97,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());
Expand All @@ -102,5 +108,6 @@ public function testShouldBuildCorrectlyThroughBuilder()
$this->assertEquals($rememberId, $receipt->getRememberMeId());
$this->assertEquals($parentRememberId, $receipt->getParentRememberMeId());
$this->assertEquals($someError, $receipt->getError());
$this->assertEquals($someErrorReason, $receipt->getErrorReason());
}
}

0 comments on commit d2f500c

Please sign in to comment.