-
Notifications
You must be signed in to change notification settings - Fork 3
/
Coupon.php
64 lines (52 loc) · 2.38 KB
/
Coupon.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
<?php
declare(strict_types=1);
use LauLamanApps\ApplePassbook\Build\CompilerFactory;
use LauLamanApps\ApplePassbook\CouponPassbook;
use LauLamanApps\ApplePassbook\MetaData\Barcode;
use LauLamanApps\ApplePassbook\MetaData\Field\DateField;
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;
use LauLamanApps\ApplePassbook\Style\DateStyle;
require_once '../../vendor/autoload.php';
$factory = new CompilerFactory();
$compiler = $factory->getCompiler(__DIR__ . '/../../certificates/certificate.p12', '<CertificatePassword>');
//-- Build pass
$passbook = new CouponPassbook('E5982H-I2');
$passbook->setTeamIdentifier('<TeamId>');
$passbook->setPassTypeIdentifier('<PassTypeId>');
$passbook->setOrganizationName('Paw Planet');
$passbook->setDescription('Paw Planet Coupon');
$passbook->setLogoText('Paw Planet');
$passbook->setForegroundColor(new Rgb(255, 255, 255));
$passbook->setBackgroundColor(new Rgb(206, 140, 53));
$passbook->setWebService('https://example.com/passes/', 'vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc');
$passbook->addLocation(new Location(37.6189722, -122.3748889));
$passbook->addLocation(new Location(37.33182, -122.03118));
$barcode = new Barcode();
$barcode->setFormat(BarcodeFormat::pdf417());
$barcode->setMessage('123456789');
$passbook->setBarcode($barcode);
$offer = new Field();
$offer->setKey('offer');
$offer->setLabel('Any premium dog food');
$offer->setValue('20% off');
$passbook->addPrimaryField($offer);
$expires = new DateField();
$expires->setKey('expires');
$expires->setLabel('EXPIRES');
$expires->setDate(new DateTimeImmutable('2013-04-24T10:00-05:00'));
$expires->isRelative();
$expires->setDateStyle(DateStyle::short());
$passbook->addAuxiliaryField($expires);
$passbook->addImage(new LocalImage(__DIR__ . '/files/Coupon/icon.png'));
$passbook->addImage(new LocalImage(__DIR__ . '/files/Coupon/[email protected]'));
$passbook->addImage(new LocalImage(__DIR__ . '/files/Coupon/logo.png'));
$passbook->addImage(new LocalImage(__DIR__ . '/files/Coupon/[email protected]'));
//-- Send data too the browser
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.apple.pkpass');
header('Content-Disposition: filename="coupon.pkpass"');
echo $compiler->compile($passbook);