-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetting-started.php
More file actions
70 lines (64 loc) · 2.74 KB
/
Copy pathgetting-started.php
File metadata and controls
70 lines (64 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use PassKit\Quickstart\Config;
use PassKit\Quickstart\ConnectionPool;
use PassKit\Quickstart\CouponsQuickstart;
use PassKit\Quickstart\EventTicketsQuickstart;
use PassKit\Quickstart\FlightsQuickstart;
use PassKit\Quickstart\LoyaltyQuickstart;
use PassKit\Quickstart\PassKitApi;
$examples = [
'loyalty' => ['membership/create-program.php', 'membership/create-tier.php', 'membership/enrol-member.php'],
'coupons' => ['coupons/create-campaign.php', 'coupons/create-offer.php', 'coupons/create-coupon.php'],
'tickets' => ['event-tickets/create-production.php', 'event-tickets/create-venue.php', 'event-tickets/create-event.php', 'event-tickets/issue-event-ticket.php'],
'flights' => ['flights/create-carrier.php', 'flights/create-airport.php', 'flights/create-flight.php', 'flights/create-boarding-pass.php'],
];
$name = $argv[1] ?? null;
if ($name === null || in_array($name, ['help', '--help', '-h'], true)) {
echo "PassKit PHP Quickstart\n\nUsage: composer example -- <loyalty|coupons|tickets|flights>\n\n";
echo "Each choice runs a complete workflow and cleans up the resources it creates.\n";
exit(0);
}
if (!isset($examples[$name])) {
fwrite(STDERR, "Unknown example '{$name}'. Choose: " . implode(', ', array_keys($examples)) . "\n");
exit(1);
}
try {
$config = Config::fromEnvironment(__DIR__);
$config->validate($name === 'flights');
$pool = new ConnectionPool($config);
try {
$api = $pool->api();
$methodCount = array_sum(array_map(
fn (array $definition): int => count($definition['unary']) + count($definition['stream']),
PassKitApi::METHODS,
));
echo "Setup complete for {$name}. {$methodCount} safe SDK operations are available through PassKitApi.\n\n";
$workflow = match ($name) {
'loyalty' => new LoyaltyQuickstart($api, $config),
'coupons' => new CouponsQuickstart($api, $config),
'tickets' => new EventTicketsQuickstart($api, $config),
'flights' => new FlightsQuickstart($api, $config),
};
try {
$result = $workflow->run();
echo "\nCreated resources:\n";
foreach ($result->urls as $label => $url) {
echo " {$label}: {$url}\n";
}
} finally {
if ($config->keepAssets) {
echo "\nPASSKIT_KEEP_ASSETS=true; generated resources were not deleted.\n";
} else {
echo "\nCleaning up generated resources...\n";
$workflow->cleanup();
}
}
} finally {
$pool->close();
}
} catch (Throwable $error) {
fwrite(STDERR, $error->getMessage() . "\n");
exit(1);
}