Skip to content

Commit 01c9efb

Browse files
author
Greg Bowler
committed
example: get customer by id or email
1 parent febd767 commit 01c9efb

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

example/01-get-customer-by-id.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* This example finds a customer by the customer ID, supplied as the first
4+
* argument to the script.
5+
*
6+
* For any example to work, you must supply your own secrets in config.ini:
7+
* - username
8+
* - client
9+
* - secret_key
10+
*/
11+
use BrightFlair\SpektrixAPI\CustomerNotFoundException;
12+
13+
chdir(dirname(__DIR__));
14+
require "vendor/autoload.php";
15+
16+
$config = parse_ini_file("config.ini");
17+
$client = new BrightFlair\SpektrixAPI\Client(
18+
$config["username"],
19+
$config["client"],
20+
$config["secret_key"],
21+
);
22+
23+
$customerId = $argv[1] ?? null;
24+
if(!$customerId) {
25+
fwrite(STDERR, "No ID supplied\n");
26+
exit(1);
27+
}
28+
29+
try {
30+
$customer = $client->getCustomer(id: $customerId);
31+
echo "Customer found!\n";
32+
echo "ID: $customer->id\n";
33+
echo "Email: $customer->email\n";
34+
echo "First name: $customer->firstName\n";
35+
echo "Last name: $customer->lastName\n";
36+
}
37+
catch(CustomerNotFoundException) {
38+
echo "No customer was found with the email address $customerId\n";
39+
}
File renamed without changes.

0 commit comments

Comments
 (0)