-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWalletPlatformContext.php
More file actions
123 lines (109 loc) · 3.86 KB
/
WalletPlatformContext.php
File metadata and controls
123 lines (109 loc) · 3.86 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
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
113
114
115
116
117
118
119
120
121
122
123
<?php
declare(strict_types=1);
namespace Jolicode\WalletKit\Builder;
use Jolicode\WalletKit\Exception\GooglePlatformContextRequiredException;
use Jolicode\WalletKit\Exception\WalletKitInvariantViolationException;
use Jolicode\WalletKit\Pass\Android\Model\Shared\ReviewStatusEnum;
use Jolicode\WalletKit\Pass\Android\Model\Shared\StateEnum;
/**
* Shared identifiers and defaults for wallet payloads. At least one of {@see $apple}, {@see $google}, or {@see $samsung} must be set before passing to a builder.
*/
final class WalletPlatformContext
{
public function __construct(
public readonly ?AppleWalletContext $apple = null,
public readonly ?GoogleWalletContext $google = null,
public readonly ?SamsungWalletContext $samsung = null,
) {
}
public function hasApple(): bool
{
return null !== $this->apple;
}
public function hasGoogle(): bool
{
return null !== $this->google;
}
public function hasSamsung(): bool
{
return null !== $this->samsung;
}
/**
* Issuer name for Google Wallet *Class* resources. Uses {@see GoogleWalletContext::$issuerName} when set; otherwise Apple {@see AppleWalletContext::$organizationName}.
*
* @throws GooglePlatformContextRequiredException when there is no Google context (callers should guard with {@see hasGoogle()})
* @throws WalletKitInvariantViolationException if issuer cannot be resolved
*/
public function googleIssuerName(): string
{
if (null === $this->google) {
throw new GooglePlatformContextRequiredException('googleIssuerName() requires a Google context.');
}
if (null !== $this->google->issuerName && '' !== $this->google->issuerName) {
return $this->google->issuerName;
}
if (null !== $this->apple) {
return $this->apple->organizationName;
}
throw new WalletKitInvariantViolationException('Google issuer name is missing and no Apple context is available to fall back on.');
}
public function withApple(
string $teamIdentifier,
string $passTypeIdentifier,
string $serialNumber,
string $organizationName,
string $description,
int $formatVersion = 1,
): self {
return new self(
new AppleWalletContext(
teamIdentifier: $teamIdentifier,
passTypeIdentifier: $passTypeIdentifier,
serialNumber: $serialNumber,
organizationName: $organizationName,
description: $description,
formatVersion: $formatVersion,
),
$this->google,
$this->samsung,
);
}
public function withGoogle(
string $classId,
string $objectId,
ReviewStatusEnum $defaultReviewStatus = ReviewStatusEnum::DRAFT,
StateEnum $defaultObjectState = StateEnum::ACTIVE,
?string $issuerName = null,
): self {
return new self(
$this->apple,
new GoogleWalletContext(
classId: $classId,
objectId: $objectId,
defaultReviewStatus: $defaultReviewStatus,
defaultObjectState: $defaultObjectState,
issuerName: $issuerName,
),
$this->samsung,
);
}
public function withSamsung(
string $refId,
string $language = 'en',
?string $appLinkLogo = null,
?string $appLinkName = null,
?string $appLinkData = null,
): self {
return new self(
$this->apple,
$this->google,
new SamsungWalletContext(
refId: $refId,
language: $language,
appLinkLogo: $appLinkLogo,
appLinkName: $appLinkName,
appLinkData: $appLinkData,
),
);
}
}