diff --git a/src/Gateway/GlobalAuthenticationGateway.php b/src/Gateway/GlobalAuthenticationGateway.php index 717f1bb..00e6a1a 100644 --- a/src/Gateway/GlobalAuthenticationGateway.php +++ b/src/Gateway/GlobalAuthenticationGateway.php @@ -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); diff --git a/src/Identity/PersonalDetails.php b/src/Identity/PersonalDetails.php index 6f4c053..55001d4 100644 --- a/src/Identity/PersonalDetails.php +++ b/src/Identity/PersonalDetails.php @@ -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; diff --git a/src/Service/GlobalAuthenticationService.php b/src/Service/GlobalAuthenticationService.php index 034b75a..ff11fed 100644 --- a/src/Service/GlobalAuthenticationService.php +++ b/src/Service/GlobalAuthenticationService.php @@ -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; @@ -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; @@ -85,12 +87,13 @@ 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; @@ -98,6 +101,7 @@ public function verifyIdentity(Identity $identity, ?string $customerReference = if (!$this->profileId) { $error = 'An ID3global Profile ID must be set by calling setProfileId() before calling verifyIdentity().'; + throw new LogicException($error); } @@ -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 { @@ -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 { @@ -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 { diff --git a/tests/Service/GlobalAuthenticationServiceTest.php b/tests/Service/GlobalAuthenticationServiceTest.php index 0a9e768..73daf5c 100644 --- a/tests/Service/GlobalAuthenticationServiceTest.php +++ b/tests/Service/GlobalAuthenticationServiceTest.php @@ -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 @@ -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(); @@ -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); @@ -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); @@ -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], + ]; + } }