forked from chiiya/passes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle_offer.php
67 lines (62 loc) · 2.44 KB
/
google_offer.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
<?php
use Chiiya\Passes\Google\Components\Common\Barcode;
use Chiiya\Passes\Google\Components\Common\DateTime;
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\TimeInterval;
use Chiiya\Passes\Google\Components\Common\Uri;
use Chiiya\Passes\Google\Enumerators\BarcodeType;
use Chiiya\Passes\Google\Enumerators\Offer\RedemptionChannel;
use Chiiya\Passes\Google\Enumerators\ReviewStatus;
use Chiiya\Passes\Google\Enumerators\State;
use Chiiya\Passes\Google\Http\GoogleClient;
use Chiiya\Passes\Google\JWT;
use Chiiya\Passes\Google\Passes\OfferClass;
use Chiiya\Passes\Google\Passes\OfferObject;
use Chiiya\Passes\Google\Repositories\OfferClassRepository;
use Chiiya\Passes\Google\ServiceCredentials;
$credentials = ServiceCredentials::parse('service_credentials.json');
$client = GoogleClient::createAuthenticatedClient($credentials);
$repository = new OfferClassRepository($client);
$class = new OfferClass(
title: '15% off purchases',
redemptionChannel: RedemptionChannel::INSTORE,
provider: 'ACME',
titleImage: Image::make('https://example.org/title.png'),
helpUri: Uri::make('https://example.org/help'),
localizedDetails: LocalizedString::make('en', '::value::'),
id: '1234567890123456789.coupon-15',
issuerName: 'ACME',
reviewStatus: ReviewStatus::UNDER_REVIEW,
imageModulesData: [
new ImageModuleData(mainImage: Image::make('https://example.org/wallet.png')),
],
linksModuleData: new LinksModuleData(
uris: [
new Uri(uri: 'https://example.org/app', description: 'App'),
new Uri(uri: 'https://example.org', description: 'Homepage'),
]
),
hexBackgroundColor: '#ffffff',
);
$repository->create($class);
$object = new OfferObject(
classId: '1234567890123456789.coupon-15',
id: '1234567890123456789.'.Str::uuid()->toString(),
state: State::ACTIVE,
barcode: new Barcode(
type: BarcodeType::EAN_13,
value: '1464194291627',
),
validTimeInterval: new TimeInterval(
start: new DateTime(date: now()),
end: new DateTime(now()->addMonth())
),
);
$jwt = (new JWT(
iss: $credentials->client_email,
key: $credentials->private_key,
origins: ['https://example.org'],
))->addOfferObject($object)->sign();