This repository has been archived by the owner on Sep 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReward.php
224 lines (198 loc) · 5.07 KB
/
Reward.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php declare(strict_types=1);
namespace Squid\Patreon\Entities;
class Reward extends Entity
{
/**
* Resource type (from Patreon).
*
* @var string
*/
protected $type = 'reward';
/**
* Amount in cents required to be eligible for this reward.
* Notes: This is legacy, do not use this. Use `amount_cents`.
* Source: https://www.patreondevelopers.com/t/f/197/2
*
* @var integer
*/
public $amount;
/**
* Amount in cents required to be eligible for this reward.
*
* @var integer
*/
public $amount_cents;
/**
* Campaign that the Reward belongs to.
*
* @var \Squid\Patreon\Entities\Campaign
*/
public $campaign;
/**
* Timestamp of the reward creation, ISO 8601 combined date and time in UTC.
* Example: "2017-12-01T16:33:48+00:00"
*
* @var string
*/
public $created_at;
/**
* Description of the reward, rendered as HTML.
* Example: "Access to my Patron only streams."
*
* @var string
*/
public $description;
/**
* Discord Roles granted when the patron has Discord attached to their Patreon
* account.
*
* @var array
*/
public $discord_role_ids;
/**
* Timestamp of the last edit to the reward, ISO 8601 combined date and time
* in UTC.
* Example: "2017-12-01T16:33:48+00:00"
*
* @var string
*/
public $edited_at;
/**
* Unknown.
*
* @var string
*/
public $image_url;
/**
* Number of Pledges with this Reward.
* Note: all pledges, active and inactive, are included in this count.
*
* @var integer
*/
public $patron_count;
/**
* Number of posts with this Reward selected as the lowest reward tier that
* can access the post.
* Note: Patrons can access posts from their Reward tier and any lower Reward
* tier so to calculate the total number of posts the Patron can access you
* would need to include the post_count for this reward and each lower Reward.
*
* @var integer
*/
public $post_count;
/**
* Is this Reward visible on the campaign?
*
* @var bool
*/
public $published;
/**
* Timestamp of when the reward was published, ISO 8601 combined date and time
* in UTC.
* Example: "2017-12-01T16:33:48+00:00"
*
* @var string
*/
public $published_at;
/**
* The number of remaining rewards available if there is a user_limit.
*
* @var integer
*/
public $remaining;
/**
* Does the reward require a shipping address?
*
* @var bool
*/
public $requires_shipping;
/**
* Title of the Reward.
* Example: "Exclusive Live Chat"
*/
public $title;
/**
* Timestamp of when the reward was unpublished, ISO 8601 combined date and time
* in UTC.
* Example: "2017-12-01T16:33:48+00:00"
*
* @var string
*/
public $unpublished_at;
/**
* Relative URL for selecting this reward when becoming a patron.
* Example: /bePatron?c=1&rid=1
*
* @var string
*/
public $url;
/**
* Maximum number of pledges that can have this reward. This includes paused
* and declined pledges.
* Source: https://www.patreondevelopers.com/t/f/131/3
*
* @var integer
*/
public $user_limit;
/**
* Is this Reward available for Patrons to select?
*
* @return bool
*/
public function isAvailableToChoose(): bool
{
return ! $this->isSystemReward() && $this->hasRemainingLimit();
}
/**
* Does the Reward have spaces left, allowing it to be picked by a patron.
*
* @return bool
*/
public function hasRemainingLimit(): bool
{
return $this->remaining !== 0;
}
/**
* Is this Reward a Reward used by the Patreon system, and not configured by
* the campaign creator?
* Note: Rewards ID -1 "Everyone" and 0 "Patrons Only" appear to be used by
* the system for permissions to access posts. You should exclude system
* rewards when listing rewards.
*
* @return bool
*/
public function isSystemReward(): bool
{
return (int) $this->id < 1;
}
/**
* A system Reward should not be attached to a Campaign during hydration
* because they are not creator-configured rewards, they're rewards used
* internally by Patreon (that probably should not be exposed via the API).
*
* @return bool
*/
public function shouldAttach(): bool
{
return ! $this->isSystemReward();
}
/**
* Get an absolute URL to the pledge page for this Reward.
*
* @return string
*/
public function getPledgeUrl(): string
{
return self::PATREON_URL . $this->url;
}
/**
* Minimum pledge amount to be eligible for this reward, formatted as
* currency.
*
* @return string
*/
public function getPrice(): string
{
return number_format($this->amount_cents / 100, 2);
}
}