Skip to content

Commit 9747b0a

Browse files
authored
Merge pull request #15 from madmatt/pulls/add-linting-and-codecov
2 parents 7441dd6 + 21cd220 commit 9747b0a

30 files changed

+725
-889
lines changed

.github/workflows/phpunit.yml renamed to .github/workflows/run-tests.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
name: PHP Composer
1+
name: Run PHP Parallel Lint, PHP CodeSniffer, and PHPUnit tests
22

33
on: [ push, pull_request ]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
98

109
steps:
@@ -25,8 +24,20 @@ jobs:
2524
- name: Install dependencies
2625
run: composer install --prefer-dist --no-progress
2726

28-
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
29-
# Docs: https://getcomposer.org/doc/articles/scripts.md
27+
- name: Run PHP Parallel Lint
28+
run: vendor/bin/parallel-lint . --exclude vendor
29+
30+
- name: Run phpcs
31+
run: vendor/bin/phpcs -s
3032

3133
- name: Run test suite
32-
run: vendor/bin/phpunit
34+
run: XDEBUG_MODE=coverage vendor/bin/phpunit
35+
36+
- name: Upload code coverage to Codecov
37+
uses: codecov/codecov-action@v2
38+
with:
39+
token: ${{ secrets.CODECOV_TOKEN }}
40+
directory: ./.artifacts
41+
fail_ci_if_error: true
42+
flags: phpunit
43+
verbose: true

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
/.artifacts
12
/.idea
3+
/.phpunit.result.cache
4+
/composer.lock
25
/vendor
3-
.phpunit.result.cache
4-
*.lock

README.md

Lines changed: 45 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -14,124 +14,52 @@ The WSDL file gives an overview of the values that can be provided, these will v
1414
* [Online WSDL viewer](http://www.id3globalsupport.com/Website/content/Web-Service/WSDL%20Page/WSDL%20HTML/ID3%20Global%20WSDL-%20Live.xhtml)
1515
* [Sample code per country](http://www.id3globalsupport.com/Website/Sample-Code.html)
1616

17-
*Note:* The code below is entirely subject to change. It is primarily focused at the moment around the `AuthenticateSP` method of the ID3global API, and specifically on New Zealand (Aotearoa), however it should be generic enough to easily support other countries.
17+
Please see the [Full Code Example](docs/full-code-example.md) that provides a complete overview of usage of this module.
18+
19+
### Accessing the underlying ID3global request and response
20+
Depending on your use case, you may need to access the underlying request sent to ID3global, or the response returned by the ID3global API. Typical use cases of this are for auditing purposes - to confirm that identity information hasn't changed since the last time an identity verification was performed for example.
21+
22+
In order to facilitate this, the `GlobalAuthenticationService` class has a number of helper methods to give you access to the underlying data. All of the below code assumes that you have already called the `->verifyIdentity()` method and that either you have a valid BandText, or you have caught the `IdentityVerificationFailureException` that may be thrown.
1823

1924
```php
20-
/**
21-
* Namespaces:
22-
*
23-
* \ID3Global\Constants\Identity
24-
* \ID3Global\Gateways\GlobalAuthenticationGateway
25-
* \ID3Global\Services\GlobalAuthenticationService
26-
* \ID3Global\Identity\Address\FreeFormatAddress
27-
* \ID3Global\Identity\Address\FixedFormatAddress
28-
* \ID3Global\Identity\ContactDetails
29-
* \ID3Global\Identity\ContactDetails\LandTelephone
30-
* \ID3Global\Identity\ContactDetails\MobileTelephone
31-
* \ID3Global\Identity\ContactDetails\WorkTelephone
32-
* \ID3Global\Identity\Documents\NZ\DrivingLicence
33-
* \ID3Global\Identity\PersonalDetails
34-
*
35-
* \ID3Global\Identity\Addresses<\ID3Global\Identity\Address\FreeFormatAddress, \ID3Global\Identity\Address\FixedFormatAddress>
36-
* - CurrentAddress
37-
* - PreviousAddress[1-3]
38-
* - HistoricAddresses<\ID3Global\Identity\Address\FreeFormatAddress, \ID3Global\Identity\Address\FixedFormatAddress>
39-
*
40-
* \ID3Global\Identity\Documents
41-
*
42-
* Not core for implementation
43-
* \ID3Global\Identity\Aliases
44-
* \ID3Global\Identity\AlternateName
45-
* \ID3Global\Identity\BankingDetails\BankAccount
46-
* \ID3Global\Identity\BankingDetails\CreditDebitCard
47-
* \ID3Global\Identity\Documents\Address\UK\ElectricitySupplier
48-
* \ID3Global\Identity\Documents\Identity\Global\InternationalPassport
49-
* \ID3Global\Identity\Documents\Identity\Europe\EuropeanIdentityCard
50-
* \ID3Global\Identity\Documents\Identity\AU\ShortPassport
51-
* \ID3Global\Identity\Documents\Identity\AU\Medicare
52-
* \ID3Global\Identity\Documents\Identity\BR\CPFNumber
53-
* \ID3Global\Identity\Documents\Identity\CA\SocialInsuranceNumber
54-
* \ID3Global\Identity\Documents\Identity\CN\ResidentIdentityCard
55-
* \ID3Global\Identity\Documents\Identity\ES\TaxIDNumber
56-
* \ID3Global\Identity\Documents\Identity\MX\TaxIdentificationNumber
57-
* \ID3Global\Identity\Documents\Identity\UK\Passport
58-
* \ID3Global\Identity\Documents\Identity\UK\DrivingLicence
59-
* \ID3Global\Identity\Documents\Identity\UK\NationalInsuranceNumber
60-
* \ID3Global\Identity\Documents\Identity\UK\DrivingLicence
61-
* \ID3Global\Identity\Documents\Identity\US\DrivingLicence
62-
* \ID3Global\Identity\Documents\Identity\US\SocialSecurity
63-
* \ID3Global\Identity\Documents\Identity\US\IdentityCard
64-
* \ID3Global\Identity\Employment
65-
* \ID3Global\Identity\GlobalGeneric
66-
* \ID3Global\Identity\Images
67-
* \ID3Global\Identity\Location
68-
* \ID3Global\Identity\PersonalDetails\BirthInfo
69-
*/
70-
71-
$birthday = DateTime::createFromFormat('Y-m-d', '1922-08-20');
72-
$personalDetails = new \ID3Global\Identity\PersonalDetails();
73-
$personalDetails
74-
->setTitle('Mr')
75-
->setForeName('Dworkin')
76-
->setMiddleName('John')
77-
->setSurname('Barimen')
78-
->setGender('male')
79-
->setDateOfBirth($birthday);
80-
81-
$currentAddress = new \ID3Global\Identity\Address\FreeFormatAddress();
82-
$currentAddress
83-
->setCountry('New Zealand')
84-
->setPostCode('90210')
85-
// You can set up to 8 address lines if required using ->setAddressLine3(), ->setAddressLine8() etc.
86-
->setAddressLine1('Dungeon 1')
87-
->setAddressLine2('Courts of Amber');
88-
89-
$addressContainer = new \ID3Global\Identity\Address\AddressContainer();
90-
$addressContainer->setCurrentAddress($currentAddress);
91-
92-
$phone = new \ID3Global\Identity\ContactDetails\PhoneNumber();
93-
$phone->setNumber(1234567890);
94-
95-
$contactDetails = new \ID3Global\Identity\ContactDetails();
96-
$contactDetails
97-
->setLandTelephone($phone)
98-
->setMobileTelephone($phone)
99-
->setWorkTelephone($phone)
100-
->setEmail('[email protected]');
101-
102-
$internationalPassport = new \ID3Global\Identity\Documents\InternationalPassport();
103-
$documentContainer = new \ID3Global\Identity\Documents\DocumentContainer();
104-
$documentContainer->addIdentityDocument(new \ID3Global\Identity\Documents\NZ\DrivingLicence(), 'New Zealand');
105-
106-
/**
107-
* $result will be a string representing the 'BandText' as returned by the ID3global API. By default, this may be a word
108-
* like 'PASS', 'REFER' or 'ALERT' but could also be any string value e.g. 'Name, Address and DOB Match'. The exact
109-
* string returned is entirely dependent on how the profile is configured within ID3global, and can vary if you adjust
110-
* the profile id and profile version.
111-
*
112-
* It is up to your implementation how these are handled. Note that generally there is only a single value that
113-
* represents an identity that has passed the necessary verification, and multiple BandTexts that represent a failing
114-
* identity. You **must** handle this in your own code, as the ID3Global API does not provide any kind of boolean value
115-
* for whether a given identity passed identity verification or not.
116-
*
117-
* An exception is thrown if the web service fails or cannot be contacted.
118-
*/
119-
$validIdentityBandText = 'PASS'; // See note above about how this may differ for you
120-
121-
$identity = new \ID3Global\Identity\Identity();
122-
$identity
123-
->setPersonalDetails($personalDetails)
124-
->setAddresses($addressContainer)
125-
->setContactDetails($contactDetails)
126-
->setIdentityDocuments($documentContainer);
127-
128-
$gateway = new \ID3Global\Gateway\GlobalAuthenticationGateway('username', 'password');
129-
$id3Service = new \ID3Global\Service\GlobalAuthenticationService($gateway);
130-
$result = $id3Service
131-
->setProfileId('Profile ID as provided by ID3global interface')
132-
->verifyIdentity($identity, 'Unique customer reference');
133-
134-
if($result === $validIdentityBandText) {
135-
// Identity is verified, continue processing
25+
// Assumes $service is an instance of ID3Global\Service\GlobalAuthenticationService
26+
27+
// Return the last SOAP request made to the ID3global API as a string
28+
$lastRawRequest = $service->getLastRawRequest();
29+
30+
// Returns the SoapClient interpreted response from the API (this will be an object of type \stdClass, or null if the SOAP request failed entirely
31+
// For example you can access the BandText of a valid response with $lastResponse->AuthenticateSPResult->BandText
32+
$lastResponse = $service->getLastVerifyIdentityResponse();
33+
34+
// Access the underlying SoapClient object to perform more detailed debugging
35+
$gateway = $service->getGateway(); // Returns a ID3Global\Gateway\GlobalAuthenticationGateway object
36+
$soapClient = $gateway->getSoapClient(); // Returns a ID3Global\Gateway\SoapClient\ID3GlobalSoapClient object
37+
38+
// You can then do anything you'd normally do on SoapClient, such as:
39+
$lastRawRequestHeaders = $soapClient->__getLastRequestHeaders(); // Returns an array of the headers sent to the API
40+
$lastRawResponse = $soapClient->__getLastResponse(); // Returns the last response returned by the API
41+
```
42+
43+
### Debugging identity verification failures
44+
In certain circumstances, generally when the ID3Global API produces unexpected results, you may get an `IdentityVerificationFailureException` returned to you. This can happen in a number of scenarios, such as required fields being missing from the request, or data being in an invalid format.
45+
46+
You should also wrap your `->verifyIdentity()` calls within a try/catch to prevent users from seeing these exceptions.
47+
48+
By default, this library does not expose information in the exception message that would leak personally identifiable information, however this can be enabled if you are confident that the exception is properly handled (e.g. is being forwarded to a GDPR-compliant logging service). Sometimes this level of detail is necessary to determine why the API request failed.
49+
50+
You can enable logging of this information via the exception message with the following configuration:
51+
52+
```php
53+
$service = new ID3Global\Service\GlobalAuthenticationService;
54+
55+
// Must be set before calling ->verifyIdentity()
56+
$service->setVerboseExceptionHandling(true);
57+
58+
// Either way, regardless of whether or not you enable verbose exception handling, IdentityVerificationFailureException will still contain the response
59+
try {
60+
$service->verifyIdentity($identity, 'customer reference');
61+
} catch (IdentityVerificationFailureException $e) {
62+
/** @var stdClass $response */
63+
$response = $e->getResponse();
13664
}
13765
```

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
},
1313

1414
"require-dev": {
15-
"phpunit/phpunit": "^9.5.8"
15+
"phpunit/phpunit": "^9.5.8",
16+
"slevomat/coding-standard": "^7.0",
17+
"php-parallel-lint/php-parallel-lint": "^1.3",
18+
"php-parallel-lint/php-console-highlighter": "^0.5.0"
1619
},
1720

1821
"authors": [

docs/full-code-example.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# id3global-service
2+
3+
## Key classes
4+
5+
**Core services:**
6+
* `ID3Global\Service\GlobalAuthenticationService`: The core service class used to request identity verification
7+
* `ID3Global\Gateway\GlobalAuthenticationGateway`: The internal gateway class that communicates (via SOAP) with ID3global
8+
9+
**Identity information:**
10+
* `ID3Global\Identity\Identity`: The base class for a single person's identity
11+
* `ID3Global\Identity\PersonalDetails`: A class to capture core identity information (name, date of birth etc)
12+
* `ID3Global\Identity\ContactDetails\PhoneNumber`: Include a single phone number (can be used for landline, mobile etc)
13+
14+
**Address specification:**
15+
* `ID3Global\Identity\Address\FreeFormatAddress`: A 'free-form' address where individual address fields aren't specified
16+
* `ID3Global\Identity\Address\FixedFormatAddress`: A fixed address format (e.g. fields for street, city, subcity etc)
17+
18+
**Additional identity documents:**
19+
* `ID3Global\Identity\Documents\DocumentContainer`: Class that contains all below documents
20+
* `ID3Global\Identity\Documents\InternationalPassport`: Contains details about a passport
21+
* `ID3Global\Identity\Documents\NZ\DrivingLicence`: Contains details about a New Zealand drivers licence
22+
23+
## Full code example
24+
25+
Below is a complete example of how to utilise this module, configuring personal details, a single address, multiple phone numbers and a passport.
26+
27+
Once the identity is created, we create and submit it to the `GlobalAuthenticationService`.
28+
29+
In the below example, we enable the 'pilot' site, which is the ID3global test environment. Leave this line out to query production (this will incur costs).
30+
31+
Finally, please review the comment below regarding the value of `$validIdentityBandText` - it's critically important that this is correct.
32+
33+
```php
34+
$birthday = DateTime::createFromFormat('Y-m-d', '1922-08-20');
35+
$personalDetails = new \ID3Global\Identity\PersonalDetails();
36+
$personalDetails
37+
->setTitle('Mr')
38+
->setForeName('Dworkin')
39+
->setMiddleName('John')
40+
->setSurname('Barimen')
41+
->setGender('male')
42+
->setDateOfBirth($birthday);
43+
44+
$currentAddress = new \ID3Global\Identity\Address\FreeFormatAddress();
45+
$currentAddress
46+
->setCountry('New Zealand')
47+
->setPostCode('90210')
48+
// You can set up to 8 address lines if required using ->setAddressLine3(), ->setAddressLine8() etc.
49+
->setAddressLine1('Dungeon 1')
50+
->setAddressLine2('Courts of Amber');
51+
52+
$addressContainer = new \ID3Global\Identity\Address\AddressContainer();
53+
$addressContainer->setCurrentAddress($currentAddress);
54+
55+
$phone = new \ID3Global\Identity\ContactDetails\PhoneNumber();
56+
$phone->setNumber(1234567890);
57+
58+
$contactDetails = new \ID3Global\Identity\ContactDetails();
59+
$contactDetails
60+
->setLandTelephone($phone)
61+
->setMobileTelephone($phone)
62+
->setWorkTelephone($phone)
63+
->setEmail('[email protected]');
64+
65+
$internationalPassport = new \ID3Global\Identity\Documents\InternationalPassport();
66+
$documentContainer = new \ID3Global\Identity\Documents\DocumentContainer();
67+
$documentContainer->addIdentityDocument(new \ID3Global\Identity\Documents\NZ\DrivingLicence(), 'New Zealand');
68+
69+
/**
70+
* $result will be a string representing the 'BandText' as returned by the ID3global API. By default, this may be a word
71+
* like 'PASS', 'REFER' or 'ALERT' but could also be any string value e.g. 'Name, Address and DOB Match'. The exact
72+
* string returned is entirely dependent on how the profile is configured within ID3global, and can vary if you adjust
73+
* the profile id and profile version.
74+
*
75+
* It is up to your implementation how these are handled. Note that generally there is only a single value that
76+
* represents an identity that has passed the necessary verification, and multiple BandTexts that represent a failing
77+
* identity. You **must** handle this in your own code, as the ID3Global API does not provide any kind of boolean value
78+
* for whether a given identity passed identity verification or not.
79+
*
80+
* An exception is thrown if the web service fails or cannot be contacted.
81+
*/
82+
$validIdentityBandText = 'PASS'; // See note above about how this may differ for you
83+
84+
$identity = new \ID3Global\Identity\Identity();
85+
$identity
86+
->setPersonalDetails($personalDetails)
87+
->setAddresses($addressContainer)
88+
->setContactDetails($contactDetails)
89+
->setIdentityDocuments($documentContainer);
90+
91+
$gateway = new \ID3Global\Gateway\GlobalAuthenticationGateway('username', 'password');
92+
$id3Service = new \ID3Global\Service\GlobalAuthenticationService($gateway);
93+
$result = $id3Service
94+
->setProfileId('Profile ID as provided by ID3global interface')
95+
->setProfileVersion(0)
96+
->setPilotSiteEnabled(true)
97+
->verifyIdentity($identity, 'Unique customer reference');
98+
99+
if($result === $validIdentityBandText) {
100+
// Identity is verified, continue processing
101+
}
102+
```

0 commit comments

Comments
 (0)