Skip to content

Commit eacc1a8

Browse files
committed
tweak: extra checks for apostrophes and other characters
for #11
1 parent 1387537 commit eacc1a8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Client.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,24 @@ public function createCustomer(
3232
?string $lastName = null,
3333
?string $mobile = null,
3434
):Customer {
35+
// This isn't typically the way URL-encoded data will be passed, if + or -
36+
// characters are present, Spektrix's servers will fail.
37+
$email = rawurlencode($email);
38+
$email = str_replace("+", "%2b", $email);
39+
$firstName = rawurlencode($firstName ?? "");
40+
$firstName = str_replace("'", "%27", $firstName);
41+
$lastName = rawurlencode($lastName ?? "");
42+
$lastName = str_replace("'", "%27", $lastName);
43+
3544
$endpoint = Endpoint::createCustomer;
3645
$authenticatedRequest = new AuthenticatedRequest(
3746
$this->secretKey,
3847
$endpoint,
3948
$this->client,
4049
[
4150
"email" => $email,
42-
"firstName" => $firstName ?? "",
43-
"lastName" => $lastName ?? "",
51+
"firstName" => $firstName,
52+
"lastName" => $lastName,
4453
"mobile" => $mobile ?? "",
4554
"birthDate" => ("D, d M Y H:i:s T"),
4655
"friendlyId" => uniqid(),

0 commit comments

Comments
 (0)