-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: create customer if it doesn't already exist
- Loading branch information
Showing
3 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* This example attempts to find a customer by the email address, supplied as | ||
* the first argument to the script. If there is no match, it will create a new | ||
* customer. | ||
* | ||
* The script requires the following arguments, in order: | ||
* 1. email address | ||
* 2. first name | ||
* 3. last name | ||
* 4. mobile number | ||
* | ||
* For any example to work, you must supply your own secrets in config.ini: | ||
* - username | ||
* - client | ||
* - secret_key | ||
*/ | ||
|
||
use BrightFlair\SpektrixAPI\CustomerNotFoundException; | ||
|
||
chdir(dirname(__DIR__)); | ||
require "vendor/autoload.php"; | ||
|
||
$config = parse_ini_file("config.ini"); | ||
$client = new BrightFlair\SpektrixAPI\Client( | ||
$config["username"], | ||
$config["client"], | ||
$config["secret_key"], | ||
); | ||
|
||
$email = $argv[1] ?? null; | ||
if(!$email) { | ||
fwrite(STDERR, "No email address supplied\n"); | ||
exit(1); | ||
} | ||
$firstName = $argv[2] ?? null; | ||
if(!$firstName) { | ||
fwrite(STDERR, "No first name supplied\n"); | ||
exit(1); | ||
} | ||
$lastName = $argv[3] ?? null; | ||
if(!$lastName) { | ||
fwrite(STDERR, "No last name supplied\n"); | ||
exit(1); | ||
} | ||
$mobileNumber = $argv[4] ?? null; | ||
if(!$mobileNumber) { | ||
fwrite(STDERR, "No mobile number supplied\n"); | ||
exit(1); | ||
} | ||
|
||
try { | ||
$customer = $client->getCustomer(email: $email); | ||
echo "Customer found!\n"; | ||
echo "ID: $customer->id\n"; | ||
echo "Email: $customer->email\n"; | ||
echo "First name: $customer->firstName\n"; | ||
echo "Last name: $customer->lastName\n"; | ||
} | ||
catch(CustomerNotFoundException) { | ||
echo "No customer was found with the email address $email\n"; | ||
echo "Creating new customer...\n"; | ||
|
||
// TODO: This simply isn't working. HTTP 500 with no reason why. I'm going to have to get back in contact with the team. | ||
$customer = $client->createCustomer($email, $firstName, $lastName, $mobileNumber); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters