-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgoogle_generic.php
98 lines (93 loc) · 3.45 KB
/
google_generic.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
<?php
use Chiiya\Passes\Google\Components\Common\Barcode;
use Chiiya\Passes\Google\Components\Common\DateTime;
use Chiiya\Passes\Google\Components\Common\GroupingInfo;
use Chiiya\Passes\Google\Components\Common\Image;
use Chiiya\Passes\Google\Components\Common\ImageModuleData;
use Chiiya\Passes\Google\Components\Common\LinksModuleData;
use Chiiya\Passes\Google\Components\Common\LocalizedString;
use Chiiya\Passes\Google\Components\Common\TextModuleData;
use Chiiya\Passes\Google\Components\Common\TimeInterval;
use Chiiya\Passes\Google\Components\Common\Uri;
use Chiiya\Passes\Google\Components\Generic\Notifications;
use Chiiya\Passes\Google\Components\Generic\UpcomingNotification;
use Chiiya\Passes\Google\Enumerators\BarcodeRenderEncoding;
use Chiiya\Passes\Google\Enumerators\BarcodeType;
use Chiiya\Passes\Google\Enumerators\MultipleDevicesAndHoldersAllowedStatus;
use Chiiya\Passes\Google\Enumerators\State;
use Chiiya\Passes\Google\Http\GoogleClient;
use Chiiya\Passes\Google\JWT;
use Chiiya\Passes\Google\Passes\GenericClass;
use Chiiya\Passes\Google\Passes\GenericObject;
use Chiiya\Passes\Google\Repositories\GenericClassRepository;
use Chiiya\Passes\Google\ServiceCredentials;
$credentials = ServiceCredentials::parse('service_credentials.json');
$client = GoogleClient::createAuthenticatedClient($credentials);
$repository = new GenericClassRepository($client);
$class = new GenericClass(
id: '1234567890123456789.generic-object',
imageModulesData: [
new ImageModuleData(
mainImage: Image::make('https://example.org/image.png')
)
],
textModulesData: [
new TextModuleData(
header: 'Lorem ipsum',
body: 'Dolor sit amet'
)
],
linksModuleData: new LinksModuleData(
uris: [
new Uri(uri: 'https://example.org/app', description: 'App'),
new Uri(uri: 'https://example.org', description: 'Homepage'),
]
),
multipleDevicesAndHoldersAllowedStatus: MultipleDevicesAndHoldersAllowedStatus::MULTIPLE_HOLDERS
);
$repository->create($class);
$object = new GenericObject(
cardTitle: LocalizedString::make('en', '::cardTitle::'),
header: LocalizedString::make('en', '::header::'),
subheader: LocalizedString::make('en', '::subheader::'),
logo: Image::make('https://example.org/logo.png'),
hexBackgroundColor: '#333',
notifications: new Notifications(
upcomingNotification: new UpcomingNotification(
enableNotification: true
),
),
classId: '1234567890123456789.generic-object',
id: '1234567890123456789.'.Str::uuid()->toString(),
heroImage: Image::make('https://example.org/hero-image.png'),
state: State::ACTIVE,
barcode: new Barcode(
type: BarcodeType::QR_CODE,
value: '1464194291627',
renderEncoding: BarcodeRenderEncoding::UTF_8,
),
validTimeInterval: new TimeInterval(
start: new DateTime(date: now()),
end: new DateTime(now()->addMonth())
),
textModulesData: [
new TextModuleData(
header: 'label-1',
body: 'value-1',
id: 'key-1',
),
new TextModuleData(
header: 'label-2',
body: 'value-2',
id: 'key-2',
)
],
groupingInfo: new GroupingInfo(
groupingId: 'group1'
)
);
$jwt = (new JWT(
iss: $credentials->client_email,
key: $credentials->private_key,
origins: ['https://example.org'],
))->addGenericObject($object)->sign();