Skip to content

Commit ae51426

Browse files
committed
Merge branch 'feature/TSMD-8502_PHP_PhoneID_SDK_change'
2 parents 14a99c1 + fe56f26 commit ae51426

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

src/phoneid/PhoneIdClient.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace telesign\sdk\phoneid;
44

55
use telesign\sdk\rest\RestClient;
6+
use telesign\sdk\rest\Response;
7+
8+
use Ramsey\Uuid\Uuid;
69

710
/**
811
* A set of APIs that deliver deep phone number data attributes that help optimize the end user
@@ -21,5 +24,31 @@ class PhoneIdClient extends RestClient {
2124
function phoneid ($phone_number, array $fields = []) {
2225
return $this->post(sprintf(self::PHONEID_RESOURCE, $phone_number), $fields);
2326
}
27+
28+
protected function execute ($method_name, $resource, $fields = [], $date = null, $nonce = null) {
29+
$json_fields = json_encode($fields);
30+
31+
$content_type = in_array($method_name, ["POST", "PUT"]) ? "application/json" : "";
32+
33+
$headers = $this->generateTelesignHeaders(
34+
$this->customer_id,
35+
$this->api_key,
36+
$method_name,
37+
$resource,
38+
$json_fields,
39+
$date,
40+
$nonce,
41+
$this->user_agent,
42+
$content_type
43+
);
44+
45+
$option = in_array($method_name, [ "POST", "PUT" ]) ? "body" : "query";
46+
47+
return new Response($this->client->request($method_name, $resource, [
48+
"headers" => $headers,
49+
$option => $json_fields,
50+
"http_errors" => false
51+
]));
52+
}
2453

2554
}

src/rest/RestClient.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
*/
2020
class RestClient {
2121

22-
private $customer_id;
23-
private $api_key;
24-
private $user_agent;
25-
private $client;
22+
protected $customer_id;
23+
protected $api_key;
24+
protected $user_agent;
25+
protected $client;
2626

2727
/**
2828
* TeleSign RestClient instantiation function
@@ -87,7 +87,8 @@ static function generateTelesignHeaders (
8787
$url_encoded_fields,
8888
$date = null,
8989
$nonce = null,
90-
$user_agent = null
90+
$user_agent = null,
91+
$content_type = null
9192
) {
9293
if (!$date) {
9394
$date = gmdate("D, d M Y H:i:s T");
@@ -96,9 +97,11 @@ static function generateTelesignHeaders (
9697
if (!$nonce) {
9798
$nonce = Uuid::uuid4()->toString();
9899
}
99-
100-
$content_type = in_array($method_name, ["POST", "PUT"]) ? "application/x-www-form-urlencoded" : "";
101-
100+
101+
if (!$content_type) {
102+
$content_type = in_array($method_name, ["POST", "PUT"]) ? "application/x-www-form-urlencoded" : "";
103+
}
104+
102105
$auth_method = "HMAC-SHA256";
103106

104107
$string_to_sign_builder = [
@@ -203,7 +206,7 @@ function delete (...$args) {
203206
*
204207
* @return \telesign\sdk\rest\Response The RestClient Response object
205208
*/
206-
private function execute ($method_name, $resource, $fields = [], $date = null, $nonce = null) {
209+
protected function execute ($method_name, $resource, $fields = [], $date = null, $nonce = null) {
207210
$url_encoded_fields = http_build_query($fields, null, "&");
208211

209212
$headers = $this->generateTelesignHeaders(

test/phoneid/PhoneIdClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ final class PhoneIdClientTest extends ClientTest {
99

1010
const EXAMPLE_REFERENCE_ID = Example::REFERENCE_ID;
1111
const EXAMPLE_PHONE_NUMBER = Example::PHONE_NUMBER;
12-
12+
1313
function getRequestExamples () {
1414
return [
1515
[
@@ -21,7 +21,7 @@ function getRequestExamples () {
2121
],
2222
"uri" => self::EXAMPLE_REST_ENDPOINT . "/v1/phoneid/" . self::EXAMPLE_PHONE_NUMBER,
2323
[
24-
"optional_param" => "123"
24+
'{"optional_param":"123"}' => ""
2525
]
2626
]
2727
];

0 commit comments

Comments
 (0)