forked from 1f991/patreon-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPledge.php
175 lines (155 loc) · 4.28 KB
/
Pledge.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
<?php declare(strict_types=1);
namespace Squid\Patreon\Entities;
class Pledge extends Entity
{
/**
* Resource type (from Patreon).
*
* @var string
*/
protected $type = 'pledge';
/**
* Address associated with the Pledge if Reward `requires_shipping`.
*
* @var \Squid\Patreon\Entities\Address
*/
public $address;
/**
* Amount paid by the patron when billed.
*
* @var integer
*/
public $amount_cents;
/**
* Card associated with the Pledge for payment.
*
* @var \Squid\Patreon\Entities\Card
*/
public $card;
/**
* Timestamp of the pledge creation, ISO 8601 combined date and time in UTC.
* Example: "2017-12-01T16:33:48+00:00"
*
* @var string
*/
public $created_at;
/**
* Creator (Campaign owner) that the Pledge is to.
*
* @var \Squid\Patreon\Entities\User
*/
public $creator;
/**
* Timestamp of the most recent failed payment, ISO 8601 combined date and
* time in UTC. Example: "2017-12-01T16:33:48+00:00"
* Notes: "only ever treat this as a boolean value (is it null, or is it
* not null, since while the date is useful to us internally for retry
* purposes, it’s not super useful outside)"
* Source: https://www.patreondevelopers.com/t/125/8
*
* @var string
*/
public $declined_since;
/**
* Does the patron have a shipping address associated with this pledge?
*
* @var bool
*/
public $has_shipping_address;
/**
* Has the patron paused their pledge?
* Notes: A pledge can only be paused if the campaign is per-month, a
* per-post campaign cannot have any paused pledges.
*
* @var bool
*/
public $is_paused;
/**
* Patron that created the Pledge.
*
* @var \Squid\Patreon\Entities\User
*/
public $patron;
/**
* Legacy / unused.
* Source: https://www.patreondevelopers.com/t/131/3
*
* @var bool
*/
public $patron_pays_fees;
/**
* Maximum amount the patron can be charged per-month on per-creation
* campaigns.
* Source: https://patreon.zendesk.com/hc/en-us/articles/115002984506
*
* @var integer
*/
public $pledge_cap_cents;
/**
* Reward chosen by the Patron if they chose an option.
*
* @var \Squid\Patreon\Entities\Reward
*/
public $reward;
/**
* Total amount that the patron has been billed through the life of the pledge.
* Notes: this value will be greater than 0 once the patron has been
* successfully billed.
* Source: https://www.patreondevelopers.com/t/125/8
*
* @var integer
*/
public $total_historical_amount_cents;
/**
* An active pledge is not paused and is not currently declined.
* Note: a pledge can be active even if the patron hasn't been charged yet
* if the campaign does not charge upfront.
*
* @return bool
*/
public function isActive(): bool
{
return $this->declined_since === null && $this->is_paused !== true;
}
/**
* Was the latest attempt to charge the patrons payment method declined?
* Note: Patreon will retry payment methods and encourage the user to fix
* the issue by adding a new payment method. When payment has repeatedly
* failed for more than (undefined period of time) the pledge will be deleted.
* Source: https://www.patreondevelopers.com/t/131/3
*
* @return bool
*/
public function isPaymentDeclined(): bool
{
return $this->declined_since !== null;
}
/**
* Has the patron ever made a successful payment?
*
* @return bool
*/
public function hasMadeAPayment(): bool
{
return $this->total_historical_amount_cents > 0;
}
/**
* Has the Patron chosen a Reward to receive in return for their Pledge?
*
* @return bool
*/
public function hasReward(): bool
{
return (bool) $this->reward;
}
/**
* Total amount spent by the user who created this pledge, formatted as
* currency.
*
* @return string
*/
public function getTotalSpent(): string
{
return number_format($this->total_historical_amount_cents / 100, 2);
}
}