Skip to content

Commit a5c4379

Browse files
authored
Merge pull request #298 from getyoti/bug/SDK-2183
'uploadFaceCaptureImage' function results in Server Error 401 - MESSAGE_SIGNING was FIXED
2 parents 73e716e + ed9538a commit a5c4379

10 files changed

+38
-27
lines changed

src/DocScan/Service.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ public function createFaceCaptureResource(
233233
): CreateFaceCaptureResourceResponse {
234234
$response = (new RequestBuilder($this->config))
235235
->withBaseUrl($this->apiUrl)
236+
->withQueryParam('sdkId', $this->sdkId)
236237
->withEndpoint("sessions/$sessionId/resources/face-capture")
237238
->withPemFile($this->pemFile)
238239
->withPayload(Payload::fromJsonData($createFaceCaptureResourcePayload))

src/DocScan/Session/Create/FaceCapture/CreateFaceCaptureResourcePayload.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
namespace Yoti\DocScan\Session\Create\FaceCapture;
44

5-
class CreateFaceCaptureResourcePayload
5+
use JsonSerializable;
6+
use stdClass;
7+
use Yoti\Util\Json;
8+
9+
class CreateFaceCaptureResourcePayload implements JsonSerializable
610
{
711
/**
812
* @var string
913
*/
10-
private $requirementId;
14+
public $requirementId;
1115

1216
/**
1317
* @param string $requirementId
@@ -24,4 +28,11 @@ public function getRequirementId(): string
2428
{
2529
return $this->requirementId;
2630
}
31+
32+
public function jsonSerialize(): stdClass
33+
{
34+
return (object)Json::withoutNullValues([
35+
'requirement_id' => $this->getRequirementId(),
36+
]);
37+
}
2738
}

src/DocScan/Session/Create/FaceCapture/UploadFaceCaptureImagePayload.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ class UploadFaceCaptureImagePayload
1010
private $imageContentType;
1111

1212
/**
13-
* @var array<int, int>
13+
* @var string
1414
*/
1515
private $imageContents;
1616

1717
/**
1818
* @param string $imageContentType
19-
* @param array<int, int> $imageContents
19+
* @param string $imageContents
2020
*/
21-
public function __construct(string $imageContentType, array $imageContents)
21+
public function __construct(string $imageContentType, string $imageContents)
2222
{
2323
$this->imageContentType = $imageContentType;
2424
$this->imageContents = $imageContents;
@@ -33,9 +33,9 @@ public function getImageContentType(): string
3333
}
3434

3535
/**
36-
* @return array<int, int>
36+
* @return string
3737
*/
38-
public function getImageContents(): array
38+
public function getImageContents(): string
3939
{
4040
return $this->imageContents;
4141
}

src/DocScan/Session/Create/FaceCapture/UploadFaceCaptureImagePayloadBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class UploadFaceCaptureImagePayloadBuilder
1313
private $imageContentType;
1414

1515
/**
16-
* @var array<int, int>
16+
* @var string
1717
*/
1818
private $imageContents;
1919

@@ -44,10 +44,10 @@ public function forPngImage(): UploadFaceCaptureImagePayloadBuilder
4444
/**
4545
* Sets the contents of the image to be uploaded
4646
*
47-
* @param array<int, int> $imageContents
47+
* @param string $imageContents
4848
* @return $this
4949
*/
50-
public function withImageContents(array $imageContents): UploadFaceCaptureImagePayloadBuilder
50+
public function withImageContents(string $imageContents): UploadFaceCaptureImagePayloadBuilder
5151
{
5252
$this->imageContents = $imageContents;
5353

src/Http/MultipartEntity.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ public function setBoundary(string $multipartBoundary): void
4242

4343
/**
4444
* @param string $name
45-
* @param array<int,int> $payload
45+
* @param string $payload
4646
* @param string $contentType
4747
* @param string $fileName
4848
*
4949
* @return void
5050
*/
51-
public function addBinaryBody(string $name, array $payload, string $contentType, string $fileName): void
51+
public function addBinaryBody(string $name, string $payload, string $contentType, string $fileName): void
5252
{
5353
$this->multipartData[] = [
5454
'name' => $name,
55-
'contents' => json_encode($payload),
55+
'contents' => $payload,
5656
'filename' => $fileName,
57-
'headers' => ['Content-type' => $contentType]
57+
'headers' => ['Content-Type' => $contentType]
5858
];
5959
}
6060

src/Http/RequestBuilder.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,14 @@ public function withMultipartBoundary(string $multipartBoundary): RequestBuilder
247247
* in order to make use of the Multipart request
248248
*
249249
* @param string $name
250-
* @param array<int, int> $payload
250+
* @param string $payload
251251
* @param string $contentType
252252
* @param string $fileName
253253
* @return $this
254254
*/
255255
public function withMultipartBinaryBody(
256256
string $name,
257-
array $payload,
257+
string $payload,
258258
string $contentType,
259259
string $fileName
260260
): RequestBuilder {
@@ -284,10 +284,6 @@ private function getHeaders(): array
284284
$defaultHeaders['Content-Type'] = 'application/json';
285285
}
286286

287-
if (isset($this->multipartEntity)) {
288-
$defaultHeaders['Content-Type'] = 'multipart/form-data';
289-
}
290-
291287
return array_merge($defaultHeaders, $this->headers);
292288
}
293289

@@ -367,11 +363,14 @@ public function build(): Request
367363

368364
$endpointWithParams = $this->endpoint . '?' . http_build_query($this->queryParams);
369365

366+
$payload = isset($this->multipartEntity) ? Payload::fromStream($this->multipartEntity->createStream()) :
367+
$this->payload;
368+
370369
$this->withHeader(self::YOTI_DIGEST_HEADER_KEY, RequestSigner::sign(
371370
$this->pemFile,
372371
$endpointWithParams,
373372
$this->method,
374-
$this->payload
373+
$payload
375374
));
376375

377376
$url = $this->baseUrl . $endpointWithParams;

src/Util/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Config
2929
/** Logger key */
3030
public const LOGGER = 'logger';
3131

32-
public const YOTI_MULTIPART_BOUNDARY = 'yoti-doc-scan-boundary';
32+
public const YOTI_MULTIPART_BOUNDARY = 'X-Yoti-Multipart-Request-Boundary';
3333

3434
/** Type error message */
3535
private const TYPE_ERROR_MESSAGE = '%s configuration value must be of type %s';

tests/DocScan/Session/Create/FaceCapture/UploadFaceCaptureImagePayloadBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
class UploadFaceCaptureImagePayloadBuilderTest extends TestCase
1515
{
16-
private const SOME_IMAGE_CONTENTS = [1, 2, 3, 4];
16+
private const SOME_IMAGE_CONTENTS = "SOME_CONTENTS";
1717

1818
/**
1919
* @test

tests/DocScan/Session/Create/FaceCapture/UploadFaceCaptureImagePayloadTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
class UploadFaceCaptureImagePayloadTest extends TestCase
1313
{
14-
private const SOME_IMAGE_CONTENTS = [1, 2, 3, 4];
14+
private const SOME_IMAGE_CONTENTS = "SOME_CONTENTS";
1515
private const SOME_IMAGE_CONTENT_TYPE = 'img/some';
1616

1717
/**

tests/Http/MultipartEntityTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function shouldCorrectlyCreateObjectTest()
3333
public function shouldCorrectCreateStream()
3434
{
3535
$name = 'SOME_NAME';
36-
$payload = ['SOME_PAYLOAD'];
36+
$payload = 'SOME_PAYLOAD';
3737
$contentType = 'SOME_TYPE';
3838
$fileName = 'SOME_FILENAME';
3939

@@ -42,9 +42,9 @@ public function shouldCorrectCreateStream()
4242
$multipartData = [
4343
[
4444
'name' => $name,
45-
'contents' => json_encode($payload),
45+
'contents' => $payload,
4646
'filename' => $fileName,
47-
'headers' => ['Content-type' => $contentType]
47+
'headers' => ['Content-Type' => $contentType]
4848
]
4949
];
5050

0 commit comments

Comments
 (0)