|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This software may be modified and distributed under the terms |
|
7
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Shapin\Stripe\Model\Coupon; |
|
11
|
|
|
|
|
12
|
|
|
use Shapin\Stripe\Model\ContainsMetadata; |
|
13
|
|
|
use Shapin\Stripe\Model\CreatableFromArray; |
|
14
|
|
|
use Shapin\Stripe\Model\LivemodeTrait; |
|
15
|
|
|
use Shapin\Stripe\Model\MetadataTrait; |
|
16
|
|
|
use Shapin\Stripe\Model\MetadataCollection; |
|
17
|
|
|
use Money\Currency; |
|
18
|
|
|
use Money\Money; |
|
19
|
|
|
|
|
20
|
|
|
final class Coupon implements CreatableFromArray, ContainsMetadata |
|
21
|
|
|
{ |
|
22
|
|
|
use LivemodeTrait, MetadataTrait; |
|
23
|
|
|
|
|
24
|
|
|
const DURATION_FOREVER = 'forever'; |
|
25
|
|
|
const DURATION_ONCE = 'once'; |
|
26
|
|
|
const DURATION_REPEATING = 'repeating'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
private $id; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var ?Money |
|
35
|
|
|
*/ |
|
36
|
|
|
private $amountOff; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var \DateTimeImmutable |
|
40
|
|
|
*/ |
|
41
|
|
|
private $createdAt; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var ?Currency |
|
45
|
|
|
*/ |
|
46
|
|
|
private $currency; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var string |
|
50
|
|
|
*/ |
|
51
|
|
|
private $duration; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var int |
|
55
|
|
|
*/ |
|
56
|
|
|
private $durationInMonths; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var ?int |
|
60
|
|
|
*/ |
|
61
|
|
|
private $maxRedemptions; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @var string |
|
65
|
|
|
*/ |
|
66
|
|
|
private $name; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @var float |
|
70
|
|
|
*/ |
|
71
|
|
|
private $percentOff; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @var ?\DateTimeImmutable |
|
75
|
|
|
*/ |
|
76
|
|
|
private $redeemBy; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @var int |
|
80
|
|
|
*/ |
|
81
|
|
|
private $timesRedeemed; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @var bool |
|
85
|
|
|
*/ |
|
86
|
|
|
private $valid; |
|
87
|
|
|
|
|
88
|
8 |
|
public static function createFromArray(array $data): self |
|
89
|
|
|
{ |
|
90
|
8 |
|
$model = new self(); |
|
91
|
|
|
|
|
92
|
8 |
|
if (isset($data['currency'])) { |
|
93
|
|
|
$currency = new Currency(strtoupper($data['currency'])); |
|
94
|
|
|
|
|
95
|
|
|
$model->amountOff = isset($data['amount_off']) ? new Money($data['amount_off'], $currency) : null; |
|
96
|
|
|
$model->currency = $currency; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
8 |
|
$model->id = $data['id']; |
|
100
|
8 |
|
$model->createdAt = new \DateTimeImmutable('@'.$data['created']); |
|
101
|
8 |
|
$model->duration = $data['duration']; |
|
102
|
8 |
|
$model->durationInMonths = (int) $data['duration_in_months']; |
|
103
|
8 |
|
$model->live = $data['livemode']; |
|
104
|
8 |
|
$model->maxRedemptions = $data['max_redemptions'] ?? null; |
|
105
|
8 |
|
$model->metadata = MetadataCollection::createFromArray($data['metadata']); |
|
|
|
|
|
|
106
|
8 |
|
$model->name = $data['name']; |
|
107
|
8 |
|
$model->percentOff = (float) $data['percent_off']; |
|
108
|
8 |
|
$model->redeemBy = isset($data['redeem_by']) ? new \DateTimeImmutable('@'.$data['redeem_by']) : null; |
|
109
|
8 |
|
$model->timesRedeemed = (int) $data['times_redeemed']; |
|
110
|
8 |
|
$model->valid = (bool) $data['valid']; |
|
111
|
|
|
|
|
112
|
8 |
|
return $model; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
1 |
|
public function getId(): string |
|
116
|
|
|
{ |
|
117
|
1 |
|
return $this->id; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
1 |
|
public function getAmountOff(): ?Money |
|
121
|
|
|
{ |
|
122
|
1 |
|
return $this->amountOff; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
1 |
|
public function getCreatedAt(): \DateTimeImmutable |
|
126
|
|
|
{ |
|
127
|
1 |
|
return $this->createdAt; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
1 |
|
public function getCurrency(): ?Currency |
|
131
|
|
|
{ |
|
132
|
1 |
|
return $this->currency; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
1 |
|
public function getDuration(): string |
|
136
|
|
|
{ |
|
137
|
1 |
|
return $this->duration; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
1 |
|
public function getDurationInMonths(): int |
|
141
|
|
|
{ |
|
142
|
1 |
|
return $this->durationInMonths; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
1 |
|
public function getMaxRedemptions(): ?int |
|
146
|
|
|
{ |
|
147
|
1 |
|
return $this->maxRedemptions; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
1 |
|
public function getName(): ?string |
|
151
|
|
|
{ |
|
152
|
1 |
|
return $this->name; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
public function getPercentOff(): float |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->percentOff; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
1 |
|
public function getRedeemBy(): ?\DateTimeImmutable |
|
161
|
|
|
{ |
|
162
|
1 |
|
return $this->redeemBy; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
1 |
|
public function getTimesRedeemed(): int |
|
166
|
|
|
{ |
|
167
|
1 |
|
return $this->timesRedeemed; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
1 |
|
public function isValid(): bool |
|
171
|
|
|
{ |
|
172
|
1 |
|
return $this->valid; |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..