Skip to content

Commit c9a0e88

Browse files
Moussa Sidibesidibos
authored andcommitted
SDK-603: Add YotiSandbox namespace to composer
1 parent afc7497 commit c9a0e88

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"Google\\Protobuf\\": "src/protobuflib/Google/Protobuf",
4444
"GPBMetadata\\": "src/protobuflib/GPBMetadata",
4545
"phpseclib\\": "src/phpseclib/",
46-
"Yoti\\": "src/Yoti"
46+
"Yoti\\": "src/Yoti",
47+
"YotiSandbox\\": "sandbox/src"
4748
}
4849
},
4950
"require-dev": {
@@ -52,7 +53,8 @@
5253
},
5354
"autoload-dev": {
5455
"psr-4": {
55-
"YotiTest\\": "tests/"
56+
"YotiTest\\": "tests/",
57+
"SandboxTest\\": "sandbox/tests/"
5658
}
5759
}
5860
}

sandbox/composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
{
22
"description": "Sandbox for yoti-php-sdk",
3-
"autoload": {
4-
"psr-4": {
5-
"YotiSandbox\\": "src"
6-
}
7-
},
83
"repositories": [
94
{
105
"type": "git",
@@ -14,5 +9,10 @@
149
"require": {
1510
"yoti/yoti-php-sdk": "dev-development",
1611
"symfony/dotenv": "3.3.0"
12+
},
13+
"autoload": {
14+
"psr-4": {
15+
"YotiSandbox\\": "src"
16+
}
1717
}
1818
}

sandbox/src/Http/Response.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ private function processData(array $result)
4444
$this->checkResponseStatus($result['http_code']);
4545

4646
// Get decoded response data
47-
$responseArr = $result['response'];
47+
$responseJSON = $result['response'];
4848

4949
$this->checkJsonError();
5050

51+
$responseArr = json_decode($responseJSON, true);
52+
5153
if (!isset($responseArr['token'])) {
5254
throw new ResponseException('Token key is missing', 404);
5355
}

sandbox/src/Http/TokenRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TokenRequest
1919
public function __construct($rememberMeId, array $sandboxAttrs)
2020
{
2121
$this->rememberMeId = $rememberMeId;
22-
$this->sandboxAttributes['profile_attributes'] = $sandboxAttrs;
22+
$this->sandboxAttributes = $sandboxAttrs;
2323
}
2424

2525
public function getRememberMeId()
@@ -36,7 +36,7 @@ public function getPayload()
3636
{
3737
$payloadData = [
3838
'remember_me_id' => $this->rememberMeId,
39-
$this->sandboxAttributes
39+
'profile_attributes' => $this->sandboxAttributes,
4040
];
4141
return new Payload($payloadData);
4242
}

sandbox/src/SandboxClient.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class SandboxClient
1010
{
11-
const TOKEN_REQUEST_ENDPOINT_FORMAT = "/app/%s/tokens";
11+
const TOKEN_REQUEST_ENDPOINT_FORMAT = "/apps/%s/tokens";
1212
const DEFAULT_SANDBOX_API_URL = "https://api.yoti.com/sandbox/v1";
1313

1414
/**
@@ -40,13 +40,13 @@ class SandboxClient
4040
public function __construct($sdkId, $pem, $sandboxApi = self::DEFAULT_SANDBOX_API_URL, $sdkIdentifier = 'PHP')
4141
{
4242
$this->sdkId = $sdkId;
43+
$pem = $this->includePemWrapper($pem);
4344
$this->requestHandler = new CurlRequestHandler(
4445
$sandboxApi,
4546
$pem,
4647
$sdkId,
4748
$sdkIdentifier
4849
);
49-
5050
$this->yotiClient = new YotiClient($sdkId, $pem);
5151
}
5252

@@ -96,12 +96,27 @@ public function getToken(RequestBuilder $requestBuilder, $httpMethod)
9696
*/
9797
protected function sendRequest(RequestBuilder $requestBuilder, $endpoint, $httpMethod)
9898
{
99+
$payload = $requestBuilder->getRequest()->getPayload();
100+
99101
$resultArr = $this->requestHandler->sendRequest(
100102
$endpoint,
101103
$httpMethod,
102-
$requestBuilder->getRequest()->getPayload()
104+
$payload
103105
);
104106

105107
return $resultArr;
106108
}
109+
110+
private function includePemWrapper($pem)
111+
{
112+
if (strpos($pem, 'PRIVATE') === false) {
113+
$pem = <<<EOF
114+
-----BEGIN RSA PRIVATE KEY-----
115+
{$pem}
116+
-----END RSA PRIVATE KEY-----
117+
EOF;
118+
}
119+
return $pem;
120+
}
121+
107122
}

0 commit comments

Comments
 (0)