Skip to content

Commit fe56f26

Browse files
TSMD-8502 sdk updates
1 parent 77ae9ad commit fe56f26

File tree

2 files changed

+10
-63
lines changed

2 files changed

+10
-63
lines changed

src/phoneid/PhoneIdClient.php

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ function phoneid ($phone_number, array $fields = []) {
2626
}
2727

2828
protected function execute ($method_name, $resource, $fields = [], $date = null, $nonce = null) {
29-
print("\n********PHONEID*********\n");
3029
$json_fields = json_encode($fields);
3130

31+
$content_type = in_array($method_name, ["POST", "PUT"]) ? "application/json" : "";
32+
3233
$headers = $this->generateTelesignHeaders(
3334
$this->customer_id,
3435
$this->api_key,
@@ -37,7 +38,8 @@ protected function execute ($method_name, $resource, $fields = [], $date = null,
3738
$json_fields,
3839
$date,
3940
$nonce,
40-
$this->user_agent
41+
$this->user_agent,
42+
$content_type
4143
);
4244

4345
$option = in_array($method_name, [ "POST", "PUT" ]) ? "body" : "query";
@@ -48,63 +50,5 @@ protected function execute ($method_name, $resource, $fields = [], $date = null,
4850
"http_errors" => false
4951
]));
5052
}
51-
52-
static function generateTelesignHeaders (
53-
$customer_id,
54-
$api_key,
55-
$method_name,
56-
$resource,
57-
$url_encoded_fields,
58-
$date = null,
59-
$nonce = null,
60-
$user_agent = null
61-
) {
62-
if (!$date) {
63-
$date = gmdate("D, d M Y H:i:s T");
64-
}
65-
66-
if (!$nonce) {
67-
$nonce = Uuid::uuid4()->toString();
68-
}
69-
70-
$content_type = in_array($method_name, ["POST", "PUT"]) ? "application/json" : "";
71-
72-
$auth_method = "HMAC-SHA256";
73-
74-
$string_to_sign_builder = [
75-
$method_name,
76-
"\n$content_type",
77-
"\n$date",
78-
"\nx-ts-auth-method:$auth_method",
79-
"\nx-ts-nonce:$nonce"
80-
];
81-
82-
if ($content_type && $url_encoded_fields) {
83-
$string_to_sign_builder[] = "\n$url_encoded_fields";
84-
}
85-
86-
$string_to_sign_builder[] = "\n$resource";
87-
88-
$string_to_sign = join("", $string_to_sign_builder);
89-
90-
$signature = base64_encode(
91-
hash_hmac("sha256", utf8_encode($string_to_sign), base64_decode($api_key), true)
92-
);
93-
$authorization = "TSA $customer_id:$signature";
94-
95-
$headers = [
96-
"Authorization" => $authorization,
97-
"Date" => $date,
98-
"Content-Type" => $content_type,
99-
"x-ts-auth-method" => $auth_method,
100-
"x-ts-nonce" => $nonce
101-
];
102-
103-
if ($user_agent) {
104-
$headers["User-Agent"] = $user_agent;
105-
}
106-
107-
return $headers;
108-
}
10953

11054
}

src/rest/RestClient.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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,8 +97,10 @@ 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" : "";
100+
101+
if (!$content_type) {
102+
$content_type = in_array($method_name, ["POST", "PUT"]) ? "application/x-www-form-urlencoded" : "";
103+
}
101104

102105
$auth_method = "HMAC-SHA256";
103106

0 commit comments

Comments
 (0)