Skip to content

Commit

Permalink
Sdk 2481 (#369)
Browse files Browse the repository at this point in the history
* SDK-2241 Create Session
* SDK-2244 Retrieve Session
* SDK-2250 Create QR Code
* SDK-2258 Retrieve QR Code
* SDK-2265 Retrieve Receipt 
* SDK-2377 added failure reasons to idv
* SDK-2357 added failure receipt error details
* Sdk 2420 php add support for advanced identity profiles to share v 2 and examples (#360)
* SDK-2371 added advanced identity profile to sharev1,example and updated tests
* Added-example-for-DBS-and-updated-failure-details
* Updated IDV Example Defaults
* Removed unneccessary used libraries
* Updated readme, and removed unnecessary usings
* SDK-2481 updated http-message and related test methods
  • Loading branch information
mehmet-yoti authored Sep 10, 2024
1 parent 3f90ff4 commit 515ade7
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 37 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ Add the Yoti SDK dependency:

```json
"require": {
"yoti/yoti-php-sdk" : "^4.2.1"
"yoti/yoti-php-sdk" : "^4.3.0"
}
```

Or run this Composer command
```console
$ composer require yoti/yoti-php-sdk "^4.2.1"
$ composer require yoti/yoti-php-sdk "^4.3.0"
```

## Setup
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"phpseclib/phpseclib": "^3.0",
"guzzlehttp/guzzle": "^7.0",
"psr/http-client": "^1.0",
"psr/http-message": "^1.0",
"psr/http-message": "^2.0",
"guzzlehttp/psr7": "^2.4",
"ext-openssl": "*"
},
Expand Down
7 changes: 5 additions & 2 deletions examples/digitalidentity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ This example requires [Docker](https://docs.docker.com/)
* Visit [https://localhost:4002](https://localhost:4002)
* Run the `docker-compose stop` command to stop the containers.

> To see how to retrieve activity details using the one time use token, refer to the [digitalidentity controller](app/Http/Controllers/IdentityController.php)
> To see how to retrieve a profile using share receipt, refer to the [receipt controller](app/Http/Controllers/ReceiptController.php)
## Digital Identity Example
* Visit [/generate-share](https://localhost:4002/generate-share)
## Digital Identity(Advanced) Share Example
* Visit [/generate-advanced-identity-share](https://localhost:4002/generate-advanced-identity-share)
* ## Digital Identity DBS Example
* Visit [/generate-dbs-share](https://localhost:4002/generate-dbs-share)
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Log;
use mysql_xdevapi\Exception;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Yoti\DigitalIdentityClient;
use Yoti\Identity\Policy\PolicyBuilder;
use Yoti\Identity\ShareSessionRequestBuilder;
use Yoti\YotiClient;

class AdvancedIdentityController extends BaseController
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Log;
use mysql_xdevapi\Exception;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Yoti\DigitalIdentityClient;
use Yoti\Identity\Policy\PolicyBuilder;
use Yoti\Identity\ShareSessionRequestBuilder;
use Yoti\YotiClient;

class IdentityController extends BaseController
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
namespace App\Http\Controllers;

use Yoti\DigitalIdentityClient;
use Yoti\YotiClient;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Yoti\Profile\Attribute;
use Yoti\Profile\UserProfile;
use Yoti\Util\Logger;
use Yoti\Exception\ActivityDetailsException;

class ReceiptController extends BaseController
{
public function show(Request $request, DigitalIdentityClient $client, ?LoggerInterface $logger = null)
Expand Down
82 changes: 69 additions & 13 deletions tests/DocScan/DocScanClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Yoti\DocScan\DocScanClient;
use Yoti\DocScan\Session\Create\CreateSessionResult;
use Yoti\DocScan\Session\Create\FaceCapture\CreateFaceCaptureResourcePayload;
Expand Down Expand Up @@ -92,8 +93,12 @@ public function testEmptyApiUrlEnvironmentVariable()
*/
private function assertApiUrlStartsWith($expectedUrl, $clientApiUrl = null)
{
$stream = $this->createMock(\Psr\Http\Message\StreamInterface::class);
$stream->method('getContents')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_CREATION_RESPONSE));
$stream->method('__toString')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_CREATION_RESPONSE));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_CREATION_RESPONSE));
$response->method('getBody')->willReturn($stream);
$response->method('getStatusCode')->willReturn(200);

$httpClient = $this->createMock(ClientInterface::class);
Expand Down Expand Up @@ -126,8 +131,13 @@ private function assertApiUrlStartsWith($expectedUrl, $clientApiUrl = null)
*/
public function testCreateSession()
{
$stream = $this->createMock(\Psr\Http\Message\StreamInterface::class);
$stream->method('getContents')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_CREATION_RESPONSE));
$stream->method('__toString')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_CREATION_RESPONSE));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_CREATION_RESPONSE));
$response->method('getBody')->willReturn($stream);

$response->method('getStatusCode')->willReturn(200);

$httpClient = $this->createMock(ClientInterface::class);
Expand Down Expand Up @@ -155,8 +165,12 @@ public function testCreateSession()
*/
public function testGetSession()
{
$stream = $this->createMock(\Psr\Http\Message\StreamInterface::class);
$stream->method('getContents')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_RESPONSE));
$stream->method('__toString')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_RESPONSE));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_RESPONSE));
$response->method('getBody')->willReturn($stream);
$response->method('getStatusCode')->willReturn(200);

$httpClient = $this->createMock(ClientInterface::class);
Expand Down Expand Up @@ -203,8 +217,13 @@ public function testDeleteSessionDoesNotThrowException()
*/
public function testGetMedia()
{
$stream = $this->createMock(\Psr\Http\Message\StreamInterface::class);
$stream->method('getContents')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_RESPONSE));
$stream->method('__toString')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_RESPONSE));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn(file_get_contents(TestData::DOC_SCAN_SESSION_RESPONSE));
$response->method('getBody')->willReturn($stream);

$response->method('getStatusCode')->willReturn(200);
$response->method('getHeader')->willReturn([ 'image/png' ]);

Expand Down Expand Up @@ -276,8 +295,12 @@ public function testDeleteMediaDoesNotThrowException()
*/
public function testGetSupportedDocuments()
{
$stream = $this->createMock(StreamInterface::class);
$stream->method('getContents')->willReturn(json_encode((object)[]));
$stream->method('__toString')->willReturn(json_encode((object)[]));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn(json_encode((object)[]));
$response->method('getBody')->willReturn($stream);
$response->method('getStatusCode')->willReturn(200);

$httpClient = $this->createMock(ClientInterface::class);
Expand All @@ -301,8 +324,12 @@ public function testGetSupportedDocuments()
*/
public function testCreateFaceCaptureResource()
{
$stream = $this->createMock(StreamInterface::class);
$stream->method('getContents')->willReturn(json_encode((object)[]));
$stream->method('__toString')->willReturn(json_encode((object)[]));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn(json_encode((object)[]));
$response->method('getBody')->willReturn($stream);
$response->method('getStatusCode')->willReturn(201);

$createFaceCaptureResourcePayloadMock = $this->createMock(CreateFaceCaptureResourcePayload::class);
Expand Down Expand Up @@ -331,9 +358,14 @@ public function testCreateFaceCaptureResource()
*/
public function testUploadFaceCaptureImage()
{

$stream = $this->createMock(StreamInterface::class);
$stream->method('getContents')->willReturn(json_encode((object)[]));
$stream->method('__toString')->willReturn(json_encode((object)[]));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn($stream);
$uploadFaceCaptureImagePayloadMock = $this->createMock(UploadFaceCaptureImagePayload::class);
$response->method('getBody')->willReturn(json_encode((object)[]));
$response->method('getStatusCode')->willReturn(200);

$httpClient = $this->createMock(ClientInterface::class);
Expand All @@ -358,8 +390,12 @@ public function testUploadFaceCaptureImage()
*/
public function testGetSessionConfiguration()
{
$stream = $this->createMock(StreamInterface::class);
$stream->method('getContents')->willReturn(json_encode((object)[]));
$stream->method('__toString')->willReturn(json_encode((object)[]));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn(json_encode((object)[]));
$response->method('getBody')->willReturn($stream);
$response->method('getStatusCode')->willReturn(200);

$httpClient = $this->createMock(ClientInterface::class);
Expand All @@ -383,9 +419,13 @@ public function testGetSessionConfiguration()
*/
public function testPutIbvInstructions()
{
$stream = $this->createMock(StreamInterface::class);
$stream->method('getContents')->willReturn(json_encode((object)[]));
$stream->method('__toString')->willReturn(json_encode((object)[]));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn($stream);
$instructionsMock = $this->createMock(Instructions::class);
$response->method('getBody')->willReturn(json_encode((object)[]));
$response->method('getStatusCode')->willReturn(200);

$httpClient = $this->createMock(ClientInterface::class);
Expand All @@ -409,8 +449,12 @@ public function testPutIbvInstructions()
*/
public function testGetIbvInstructions()
{
$stream = $this->createMock(StreamInterface::class);
$stream->method('getContents')->willReturn(json_encode((object)[]));
$stream->method('__toString')->willReturn(json_encode((object)[]));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn(json_encode((object)[]));
$response->method('getBody')->willReturn($stream);
$response->method('getStatusCode')->willReturn(200);

$httpClient = $this->createMock(ClientInterface::class);
Expand All @@ -433,8 +477,12 @@ public function testGetIbvInstructions()
*/
public function testGetIbvInstructionsPdf()
{
$stream = $this->createMock(StreamInterface::class);
$stream->method('getContents')->willReturn(json_encode((object)[]));
$stream->method('__toString')->willReturn(json_encode((object)[]));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn(json_encode((object)[]));
$response->method('getBody')->willReturn($stream);
$response->method('getStatusCode')->willReturn(200);

$httpClient = $this->createMock(ClientInterface::class);
Expand All @@ -457,8 +505,12 @@ public function testGetIbvInstructionsPdf()
*/
public function testFetchInstructionsContactProfile()
{
$stream = $this->createMock(StreamInterface::class);
$stream->method('getContents')->willReturn(json_encode((object)[]));
$stream->method('__toString')->willReturn(json_encode((object)[]));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn(json_encode((object)[]));
$response->method('getBody')->willReturn($stream);
$response->method('getStatusCode')->willReturn(200);

$httpClient = $this->createMock(ClientInterface::class);
Expand All @@ -481,8 +533,12 @@ public function testFetchInstructionsContactProfile()
*/
public function testTriggerIbvEmailNotification()
{
$stream = $this->createMock(StreamInterface::class);
$stream->method('getContents')->willReturn(json_encode((object)[]));
$stream->method('__toString')->willReturn(json_encode((object)[]));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn(json_encode((object)[]));
$response->method('getBody')->willReturn($stream);
$response->method('getStatusCode')->willReturn(200);

$httpClient = $this->createMock(ClientInterface::class);
Expand Down
32 changes: 19 additions & 13 deletions tests/YotiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use GuzzleHttp\Psr7;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Log\LoggerInterface;
use Yoti\Aml\Address as AmlAddress;
use Yoti\Aml\Country as AmlCountry;
Expand Down Expand Up @@ -122,8 +123,12 @@ private function assertApiUrlStartsWith($expectedUrl, $clientApiUrl = null)
*/
public function testGetActivityDetails()
{
$stream = $this->createMock(StreamInterface::class);
$stream->method('getContents')->willReturn(file_get_contents(TestData::RECEIPT_JSON));
$stream->method('__toString')->willReturn(file_get_contents(TestData::RECEIPT_JSON));

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn(file_get_contents(TestData::RECEIPT_JSON));
$response->method('getBody')->willReturn($stream);
$response->method('getStatusCode')->willReturn(200);

$httpClient = $this->createMock(ClientInterface::class);
Expand Down Expand Up @@ -220,20 +225,21 @@ public function testGetLoginUrl()
*/
public function testCustomLogger()
{
$response = $this->createMock(ResponseInterface::class);
$jsonstr = json_encode([
'receipt' => [
'timestamp' => 'some invalid timestamp',
'wrapped_receipt_key' => 'some receipt key',
'sharing_outcome' => 'SUCCESS',
]
]);

$stream = $this->createMock(StreamInterface::class);
$stream->method('getContents')->willReturn($jsonstr);
$stream->method('__toString')->willReturn($jsonstr);

$response = $this->createMock(ResponseInterface::class);
$response->method('getBody')->willReturn($stream);
$response->method('getStatusCode')->willReturn(200);
$response
->method('getBody')
->willReturn(
json_encode([
'receipt' => [
'timestamp' => 'some invalid timestamp',
'wrapped_receipt_key' => 'some receipt key',
'sharing_outcome' => 'SUCCESS',
]
])
);

$httpClient = $this->createMock(ClientInterface::class);
$httpClient->expects($this->exactly(1))
Expand Down

0 comments on commit 515ade7

Please sign in to comment.