Skip to content

Commit

Permalink
Merge pull request #13 from elnurvl/master
Browse files Browse the repository at this point in the history
  • Loading branch information
madmatt authored Sep 5, 2021
2 parents 78689c4 + e6308da commit 8d92059
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Gateway/GlobalAuthenticationGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class GlobalAuthenticationGateway extends ID3GlobalBaseGateway
{
public function AuthenticateSP(string $profileID, string $profileVersion, string $customerReference, Identity $identity)
public function AuthenticateSP(string $profileID, int $profileVersion, ?string $customerReference, Identity $identity)
{
$request = new AuthenticateSPRequest();
$request->setCustomerReference($customerReference);
Expand Down
4 changes: 4 additions & 0 deletions src/Identity/PersonalDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public function setGender(?string $gender): PersonalDetails
*/
public function setDateOfBirth(?DateTime $birthday): PersonalDetails
{
if ($birthday == null) {
return $this;
}

$this->dateOfBirth = $birthday;

$this->DOBDay = $birthday->format('d') ?? null;
Expand Down
30 changes: 17 additions & 13 deletions src/Service/GlobalAuthenticationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace ID3Global\Service;

use Exception;
use LogicException;
use ID3Global\Exceptions\IdentityVerificationFailureException;
use ID3Global\Gateway\GlobalAuthenticationGateway;
use ID3Global\Identity\Identity;
use LogicException;
use SoapClient;
use stdClass;

Expand All @@ -18,27 +18,29 @@ class GlobalAuthenticationService extends ID3BaseService
private GlobalAuthenticationGateway $gateway;

/**
* @var string The Profile ID to be used when verifying identities via $this->verifyIdentity().
* @var string The Profile ID to be used when verifying identities via->verifyIdentity().
*
* @see self::setProfileId()
*/
private string $profileId = '';

/**
* @var int The version of the Profile ID to be used when verifying identities via $this->verifyIdentity().
* The special value of 0 is treated specially by ID3global and represents the 'most recent version of the profile'.
* @var int The version of the Profile ID to be used when verifying identities via->verifyIdentity().
* The special value of 0 is treated specially by ID3global and represents the 'most recent version of the profile'.
*
* @see self::setProfileVersion()
*/
private int $profileVersion = 0;

/**
* @var Identity The most recent Identity object to be verified by the ID3global API (regardless of the outcome of
* the API request).
* the API request).
*/
private Identity $lastIdentity;

/**
* @var string|null The most recent customer reference to be verified by the ID3global API (regardless of the
* outcome of the API request).
* outcome of the API request).
*/
private ?string $lastCustomerReference;

Expand Down Expand Up @@ -85,19 +87,21 @@ public function __construct(GlobalAuthenticationGateway $gateway, array $soapOpt
* necessary for compliance purposes.
*
* @throws IdentityVerificationFailureException Thrown specifically if the SOAP response was 'valid' according to
* SOAP but does not conform to the expected response (missing BandText or Score elements of the response).
* @throws Exception May throw a generic Exception or SoapFault if any part of the SOAP callstack fails.
* SOAP but does not conform to the expected response (missing BandText or Score elements of the response).
* @throws Exception May throw a generic Exception or SoapFault if any part of the SOAP callstack fails.
*
* @return string The raw BandText as provided by the API.
*/
public function verifyIdentity(Identity $identity, ?string $customerReference = null): string {
public function verifyIdentity(Identity $identity, ?string $customerReference = null): string
{
$this->lastIdentity = $identity;
$this->lastCustomerReference = $customerReference;

$gateway = $this->getGateway();

if (!$this->profileId) {
$error = 'An ID3global Profile ID must be set by calling setProfileId() before calling verifyIdentity().';

throw new LogicException($error);
}

Expand Down Expand Up @@ -158,7 +162,7 @@ public function getProfileVersion(): int

/**
* @return Identity|null The last Identity object to be verified by the API (regardless of whether it was
* successfully accepted by the ID3global API or not). Returns null if ->verifyIdentity() has not yet been called.
* successfully accepted by the ID3global API or not). Returns null if ->verifyIdentity() has not yet been called.
*/
public function getLastVerifiedIdentity(): ?Identity
{
Expand All @@ -167,7 +171,7 @@ public function getLastVerifiedIdentity(): ?Identity

/**
* @return string|null The last customer reference value to be verified by the API (regardless of whether it was
* successfully accepted by the ID3global API or not). Returns null if ->verifyIdentity() has not yet been called.
* successfully accepted by the ID3global API or not). Returns null if ->verifyIdentity() has not yet been called.
*/
public function getLastCustomerReference(): ?string
{
Expand All @@ -176,8 +180,8 @@ public function getLastCustomerReference(): ?string

/**
* @return stdClass|null Either the full response as returned by ID3global, or null if no call has been made yet. If
* the request was made but failed to validate (e.g. the ID3global API returned an invalid SOAP object, this will
* still be populated.
* the request was made but failed to validate (e.g. the ID3global API returned an invalid SOAP object, this will
* still be populated.
*/
public function getLastVerifyIdentityResponse(): ?stdClass
{
Expand Down
26 changes: 20 additions & 6 deletions tests/Service/GlobalAuthenticationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace ID3Global\Tests\Service;

use DateTime;
use Exception;
use LogicException;
use ID3Global\Exceptions\IdentityVerificationFailureException;
use ID3Global\Identity\Identity;
use ID3Global\Identity\PersonalDetails;
use ID3Global\Service\GlobalAuthenticationService;
use ID3Global\Stubs\Gateway\GlobalAuthenticationGatewayFake;
use LogicException;
use PHPUnit\Framework\TestCase;

class GlobalAuthenticationServiceTest extends TestCase
Expand All @@ -25,9 +25,14 @@ public function setUp(): void
}

/**
* @throws Exception
* @dataProvider authenticateSp
*
* @param string|null $customerReference
* @param DateTime|null $birthday
*
* @throws IdentityVerificationFailureException
*/
public function testSuccessfulResponse()
public function testSuccessfulResponse(?string $customerReference, ?DateTime $birthday)
{
// Arrange
$personalDetails = new PersonalDetails();
Expand All @@ -36,7 +41,7 @@ public function testSuccessfulResponse()
->setMiddleName('White')
->setSurname('Huntsman')
->setGender('Female')
->setDateOfBirth(DateTime::createFromFormat('Y-m-d', '1976-03-06'));
->setDateOfBirth($birthday);

$identity = new Identity();
$identity->setPersonalDetails($personalDetails);
Expand All @@ -46,7 +51,7 @@ public function testSuccessfulResponse()
// Act
$bandText = $this->service
->setProfileId($profileId)
->verifyIdentity($identity, 'customer reference');
->verifyIdentity($identity, $customerReference);

// Assert
$this->assertSame(GlobalAuthenticationGatewayFake::IDENTITY_BAND_PASS, $bandText);
Expand All @@ -64,4 +69,13 @@ public function testNotSettingProfileIdThrows()
$this->expectException(LogicException::class);
$this->service->verifyIdentity($identity);
}

public function authenticateSp(): array
{
return [
['customer-reference', DateTime::createFromFormat('Y-m-d', '1976-03-06')],
[null, DateTime::createFromFormat('Y-m-d', '1976-03-06')],
['customer-reference', null],
];
}
}

0 comments on commit 8d92059

Please sign in to comment.