-
Notifications
You must be signed in to change notification settings - Fork 3
/
BoardingPass.php
112 lines (93 loc) · 3.84 KB
/
BoardingPass.php
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
declare(strict_types=1);
use LauLamanApps\ApplePassbook\BoardingPassbook;
use LauLamanApps\ApplePassbook\Build\CompilerFactory;
use LauLamanApps\ApplePassbook\MetaData\Barcode;
use LauLamanApps\ApplePassbook\MetaData\BoardingPass\TransitType;
use LauLamanApps\ApplePassbook\MetaData\Field\Field;
use LauLamanApps\ApplePassbook\MetaData\Image\LocalImage;
use LauLamanApps\ApplePassbook\MetaData\Location;
use LauLamanApps\ApplePassbook\Style\BarcodeFormat;
use LauLamanApps\ApplePassbook\Style\Color\Rgb;
require_once '../../vendor/autoload.php';
$factory = new CompilerFactory();
$compiler = $factory->getCompiler(__DIR__ . '/../../certificates/certificate.p12', 'ea3eaa8e-d920-46d1-9a35-119c97c16122');
//-- Build pass
$passbook = new BoardingPassbook('gT6zrHkaW');
$passbook->setTeamIdentifier('<TeamId>');
$passbook->setPassTypeIdentifier('<PassTypeId>');
$passbook->setTransitType(TransitType::air());
$passbook->setOrganizationName('Skyport Airways');
$passbook->setDescription('Skyport Boarding Pass');
$passbook->setLogoText('Skyport Airways');
$passbook->addLocation(new Location(37.6189722, -122.3748889));
$passbook->setForegroundColor(new Rgb(22, 55, 110));
$passbook->setBackgroundColor(new Rgb(50, 91, 185));
$passbook->setRelevantDate(new DateTimeImmutable('2012-07-22T14:25-08:00'));
$passbook->setWebService('https://example.com/passes/', 'vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc');
$barcode = new Barcode();
$barcode->setFormat(BarcodeFormat::pdf417());
$barcode->setMessage('SFOJFK JOHN APPLESEED LH451 2012-07-22T14:25-08:00');
$passbook->setBarcode($barcode);
$gate = new Field();
$gate->setKey('gate');
$gate->setLabel('GATE');
$gate->setValue('23');
$gate->setChangeMessage('Gate changed to %@.');
$passbook->addHeaderField($gate);
$depart = new Field();
$depart->setKey('depart');
$depart->setLabel('SAN FRANCISCO');
$depart->setValue('SFO');
$passbook->addPrimaryField($depart);
$arrive = new Field();
$arrive->setKey('arrive');
$arrive->setLabel('NEW YORK');
$arrive->setValue('JFK');
$passbook->addPrimaryField($arrive);
$passenger = new Field();
$passenger->setKey('passenger');
$passenger->setLabel('PASSENGER');
$passenger->setValue('John Appleseed');
$passbook->addSecondaryField($passenger);
$boardingTime = new Field();
$boardingTime->setKey('boardingTime');
$boardingTime->setLabel('DEPART');
$boardingTime->setValue('2:25 PM');
$boardingTime->setChangeMessage('Boarding time changed to %@.');
$passbook->addAuxiliaryField($boardingTime);
$flightNewName = new Field();
$flightNewName->setKey('flightNewName');
$flightNewName->setLabel('FLIGHT');
$flightNewName->setValue('815');
$flightNewName->setChangeMessage('Flight number changed to %@');
$passbook->addAuxiliaryField($flightNewName);
$class = new Field();
$class->setKey('class');
$class->setLabel('DESIG.');
$class->setValue('Coach');
$passbook->addAuxiliaryField($class);
$date = new Field();
$date->setKey('date');
$date->setLabel('DATE');
$date->setValue('7/22');
$passbook->addAuxiliaryField($date);
$passport = new Field();
$passport->setKey('passport');
$passport->setLabel('PASSPORT');
$passport->setValue('Canadian/Canadien');
$passbook->addBackField($passport);
$residence = new Field();
$residence->setKey('residence');
$residence->setLabel('RESIDENCE');
$residence->setValue('999 Infinite Loop, Apartment 42, Cupertino CA');
$passbook->addBackField($residence);
$passbook->addImage(new LocalImage(__DIR__ . '/files/BoardingPass/icon.png'));
$passbook->addImage(new LocalImage(__DIR__ . '/files/BoardingPass/icon@2x.png'));
$passbook->addImage(new LocalImage(__DIR__ . '/files/BoardingPass/logo.png'));
$passbook->addImage(new LocalImage(__DIR__ . '/files/BoardingPass/logo@2x.png'));
//-- Send data too the browser
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.apple.pkpass');
header('Content-Disposition: filename="boardingpass.pkpass"');
echo $compiler->compile($passbook);