33namespace ID3Global \Service ;
44
55use Exception ;
6+ use LogicException ;
67use ID3Global \Exceptions \IdentityVerificationFailureException ;
78use ID3Global \Gateway \GlobalAuthenticationGateway ;
89use ID3Global \Identity \Identity ;
@@ -16,6 +17,31 @@ class GlobalAuthenticationService extends ID3BaseService
1617 */
1718 private GlobalAuthenticationGateway $ gateway ;
1819
20+ /**
21+ * @var string The Profile ID to be used when verifying identities via $this->verifyIdentity().
22+ * @see self::setProfileId()
23+ */
24+ private string $ profileId = '' ;
25+
26+ /**
27+ * @var int The version of the Profile ID to be used when verifying identities via $this->verifyIdentity().
28+ * The special value of 0 is treated specially by ID3global and represents the 'most recent version of the profile'.
29+ * @see self::setProfileVersion()
30+ */
31+ private int $ profileVersion = 0 ;
32+
33+ /**
34+ * @var Identity The most recent Identity object to be verified by the ID3global API (regardless of the outcome of
35+ * the API request).
36+ */
37+ private Identity $ lastIdentity ;
38+
39+ /**
40+ * @var string|null The most recent customer reference to be verified by the ID3global API (regardless of the
41+ * outcome of the API request).
42+ */
43+ private ?string $ lastCustomerReference ;
44+
1945 /**
2046 * @var stdClass|null The last response, directly from the API gateway. Can be retrieved using
2147 * {@link getLastVerifyIdentityResponse()}.
@@ -39,39 +65,54 @@ public function __construct(GlobalAuthenticationGateway $gateway, array $soapOpt
3965 }
4066
4167 /**
42- * @param Identity $identity
43- * @param string $profileId The Profile ID to be used when verifying a @link \ID3Global\Identity\Identity object
44- * @param int $profileVersion The Profile Version to be used when verifying a @link \ID3Global\Identity\Identity object. The version
45- * 0 represents the 'most recent version of the profile', which is generally what is required.
46- * @param string|null $customerReference A reference stored against this identity request. This is optional, but is recommended to set a
47- * customer reference and store it against the returned identity verification so it can be later tracked if
68+ * Given an Identity and a profile of checks to perform, query ID3Global and verify the given $identity object. The
69+ * raw response is the output of the 'BandText' as returned directly by the ID3Global API. Per the
70+ * [ID3Global 'Integrate now' documentation](https://www.id3globalsupport.com/integrate-now/), you should use this
71+ * value to determine whether or not to consider the identity to be sufficiently verified for your needs.
72+ *
73+ * If you want to dive deeper (e.g. to look at individual checks that were performed such as whether the identity
74+ * matched on a driver's license or passport record), you can do this by calling
75+ * $service->getLastVerifyIdentityResponse() after calling this method - this will return the full response from the
76+ * API.
77+ *
78+ * Ensure you call at least ->setProfileId() prior to calling this method.
79+ * Optionally call ->setProfileVersion() if you wish to set a specific profile version to query against.
80+ *
81+ * @param Identity $identity The full Identity object that should be verified with the ID3global API
82+ * @param string|null $customerReference A reference stored against this identity request within the ID3global
83+ * interface. This is optional, but is highly recommended to set a reference
84+ * and store it against the identity so that it can be later tracked if
4885 * necessary for compliance purposes.
4986 *
50- * @throws IdentityVerificationFailureException
87+ * @throws IdentityVerificationFailureException Thrown specifically if the SOAP response was 'valid' according to
88+ * SOAP but does not conform to the expected response (missing BandText or Score elements of the response).
89+ * @throws Exception May throw a generic Exception or SoapFault if any part of the SOAP callstack fails.
5190 *
52- * @return string One of Identity::IDENTITY_BAND_PASS, Identity::IDENTITY_BAND_REFER, or Identity::IDENTITY_BAND_ALERT
53- */
54- public function verifyIdentity (
55- Identity $ identity ,
56- string $ profileId ,
57- int $ profileVersion = 0 ,
58- ?string $ customerReference = null
59- ): string {
91+ * @return string The raw BandText as provided by the API.
92+ */
93+ public function verifyIdentity (Identity $ identity , ?string $ customerReference = null ): string {
94+ $ this ->lastIdentity = $ identity ;
95+ $ this ->lastCustomerReference = $ customerReference ;
96+
6097 $ gateway = $ this ->getGateway ();
6198
99+ if (!$ this ->profileId ) {
100+ $ error = 'An ID3global Profile ID must be set by calling setProfileId() before calling verifyIdentity(). ' ;
101+ throw new LogicException ($ error );
102+ }
103+
104+ $ profileId = $ this ->profileId ;
105+ $ profileVersion = $ this ->profileVersion ;
106+
62107 try {
63- $ response = $ gateway ->AuthenticateSP (
64- $ profileId ,
65- $ profileVersion ,
66- $ customerReference ,
67- $ identity
68- );
108+ $ response = $ gateway ->AuthenticateSP ($ profileId , $ profileVersion , $ customerReference , $ identity );
69109
70110 if ($ gateway ->getClient () instanceof SoapClient) {
71111 $ this ->lastRawRequest = $ gateway ->getClient ()->__getLastRequest ();
72112 }
73113
74114 $ validResult = false ;
115+ $ this ->lastVerifyIdentityResponse = $ response ;
75116
76117 if (
77118 isset ($ response ) &&
@@ -82,8 +123,6 @@ public function verifyIdentity(
82123 }
83124
84125 if ($ validResult ) {
85- $ this ->lastVerifyIdentityResponse = $ response ;
86-
87126 return $ response ->AuthenticateSPResult ->BandText ;
88127 } else {
89128 throw new IdentityVerificationFailureException ($ response );
@@ -93,9 +132,52 @@ public function verifyIdentity(
93132 }
94133 }
95134
135+ public function setProfileId (string $ profileId ): self
136+ {
137+ $ this ->profileId = $ profileId ;
138+
139+ return $ this ;
140+ }
141+
142+ public function getProfileId (): string
143+ {
144+ return $ this ->profileId ;
145+ }
146+
147+ public function setProfileVersion (int $ profileVersion ): self
148+ {
149+ $ this ->profileVersion = $ profileVersion ;
150+
151+ return $ this ;
152+ }
153+
154+ public function getProfileVersion (): int
155+ {
156+ return $ this ->profileVersion ;
157+ }
158+
159+ /**
160+ * @return Identity|null The last Identity object to be verified by the API (regardless of whether it was
161+ * successfully accepted by the ID3global API or not). Returns null if ->verifyIdentity() has not yet been called.
162+ */
163+ public function getLastVerifiedIdentity (): ?Identity
164+ {
165+ return $ this ->lastIdentity ;
166+ }
167+
168+ /**
169+ * @return string|null The last customer reference value to be verified by the API (regardless of whether it was
170+ * successfully accepted by the ID3global API or not). Returns null if ->verifyIdentity() has not yet been called.
171+ */
172+ public function getLastCustomerReference (): ?string
173+ {
174+ return $ this ->lastCustomerReference ;
175+ }
176+
96177 /**
97- * @return stdClass|null Either the full response as returned by ID3Global, or null if no call has been made (or
98- * if the previous call failed for any reason)
178+ * @return stdClass|null Either the full response as returned by ID3global, or null if no call has been made yet. If
179+ * the request was made but failed to validate (e.g. the ID3global API returned an invalid SOAP object, this will
180+ * still be populated.
99181 */
100182 public function getLastVerifyIdentityResponse (): ?stdClass
101183 {
0 commit comments