diff --git a/README.md b/README.md index 36510a9c..6f35b579 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/composer.json b/composer.json index 420fe8e3..95ef8a52 100755 --- a/composer.json +++ b/composer.json @@ -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": "*" }, diff --git a/examples/digitalidentity/README.md b/examples/digitalidentity/README.md index 8faa9b32..3673b72a 100644 --- a/examples/digitalidentity/README.md +++ b/examples/digitalidentity/README.md @@ -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) \ No newline at end of file diff --git a/examples/digitalidentity/app/Http/Controllers/AdvancedIdentityController.php b/examples/digitalidentity/app/Http/Controllers/AdvancedIdentityController.php index cdfda0f6..c084faf2 100644 --- a/examples/digitalidentity/app/Http/Controllers/AdvancedIdentityController.php +++ b/examples/digitalidentity/app/Http/Controllers/AdvancedIdentityController.php @@ -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 { diff --git a/examples/digitalidentity/app/Http/Controllers/IdentityController.php b/examples/digitalidentity/app/Http/Controllers/IdentityController.php index 72ba9fc3..ca987617 100644 --- a/examples/digitalidentity/app/Http/Controllers/IdentityController.php +++ b/examples/digitalidentity/app/Http/Controllers/IdentityController.php @@ -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 { diff --git a/examples/digitalidentity/app/Http/Controllers/ReceiptController.php b/examples/digitalidentity/app/Http/Controllers/ReceiptController.php index cc529386..40299d42 100644 --- a/examples/digitalidentity/app/Http/Controllers/ReceiptController.php +++ b/examples/digitalidentity/app/Http/Controllers/ReceiptController.php @@ -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) diff --git a/tests/DocScan/DocScanClientTest.php b/tests/DocScan/DocScanClientTest.php index 306e1d17..623c0a60 100644 --- a/tests/DocScan/DocScanClientTest.php +++ b/tests/DocScan/DocScanClientTest.php @@ -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; @@ -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); @@ -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); @@ -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); @@ -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' ]); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/tests/YotiClientTest.php b/tests/YotiClientTest.php index 9f345a5a..d95b635f 100755 --- a/tests/YotiClientTest.php +++ b/tests/YotiClientTest.php @@ -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; @@ -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); @@ -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))