class-wc-payments-api-intention.php
6.05 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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
/**
* WC_Payments_API_Intention class
*
* @package WooCommerce\Payments
*/
/**
* An intention object used by the WooCommerce Payments API.
*/
class WC_Payments_API_Intention implements \JsonSerializable {
/**
* Intention ID
*
* @var string
*/
private $id;
/**
* Charge amount
*
* @var int
*/
private $amount;
/**
* Time charge created
*
* Server-side times are presumed to be UTC, (de)serializers should take care to set/respect the timezone on the
* DateTime object.
*
* @var DateTime
*/
private $created;
/**
* The status of the intention
*
* @var string
*/
private $status;
/**
* The client secret of the intention
*
* @var string
*/
private $client_secret;
/**
* The currency of the intention
*
* @var string
*/
private $currency;
/**
* ID of the customer making the payment
*
* @var string|null
*/
private $customer_id;
/**
* ID of the payment method used.
*
* @var string|null
*/
private $payment_method_id;
/**
* The next action needed of the intention
*
* @var array
*/
private $next_action;
/**
* The last payment error of the intention
*
* @var array
*/
private $last_payment_error;
/**
* The latest charge object
*
* @var WC_Payments_API_Charge
*/
private $charge;
/**
* Set of key-value pairs that can be useful for storing
* additional information about the object in a structured format.
*
* @var array
*/
private $metadata;
/**
* The details on the state of the payment.
*
* @var array
*/
private $processing;
/**
* WC_Payments_API_Intention constructor.
*
* @param string $id - ID of the intention.
* @param integer $amount - Amount charged.
* @param string $currency - The currency of the intention.
* @param string|null $customer_id - Stripe ID of the customer.
* @param string|null $payment_method_id - Stripe ID of the payment method.
* @param DateTime $created - Time charge created.
* @param string $status - Intention status.
* @param string $client_secret - The client secret of the intention.
* @param WC_Payments_API_Charge $charge - An array containing payment method details of associated charge.
* @param array $next_action - An array containing information for next action to take.
* @param array $last_payment_error - An array containing details of any errors.
* @param array $metadata - An array containing additional metadata of associated charge or order.
* @param array $processing - An array containing details of the processing state of the payment.
*/
public function __construct(
$id,
$amount,
string $currency,
$customer_id,
$payment_method_id,
DateTime $created,
$status,
$client_secret,
$charge = null,
$next_action = [],
$last_payment_error = [],
$metadata = [],
$processing = []
) {
$this->id = $id;
$this->amount = $amount;
$this->created = $created;
$this->status = $status;
$this->client_secret = $client_secret;
$this->currency = strtoupper( $currency );
$this->next_action = $next_action;
$this->last_payment_error = $last_payment_error;
$this->customer_id = $customer_id;
$this->payment_method_id = $payment_method_id;
$this->charge = $charge;
$this->metadata = $metadata;
$this->processing = $processing;
}
/**
* Gets charge ID
*
* @return string
*/
public function get_id() {
return $this->id;
}
/**
* Gets charge amount
*
* @return int
*/
public function get_amount() {
return $this->amount;
}
/**
* Gets charge created time
*
* @return DateTime
*/
public function get_created() {
return $this->created;
}
/**
* Gets intention status
*
* @return string
*/
public function get_status() {
return $this->status;
}
/**
* Returns the client secret associated with this intention
*
* @return string
*/
public function get_client_secret() {
return $this->client_secret;
}
/**
* Returns the currency of this intention
*
* @return string
*/
public function get_currency() {
return $this->currency;
}
/**
* Returns the customer ID of this intention
*
* @return string|null
*/
public function get_customer_id() {
return $this->customer_id;
}
/**
* Returns the payment method ID of this intention
*
* @return string|null
*/
public function get_payment_method_id() {
return $this->payment_method_id;
}
/**
* Returns the next action of this intention
*
* @return array
*/
public function get_next_action() {
return $this->next_action;
}
/**
* Returns the last payment error of this intention
*
* @return array
*/
public function get_last_payment_error() {
return $this->last_payment_error;
}
/**
* Returns the charge associated with this intention
*
* @return WC_Payments_API_Charge
*/
public function get_charge() {
return $this->charge;
}
/**
* Returns the metadata associated with this intention
*
* @return array
*/
public function get_metadata() {
return $this->metadata;
}
/**
* Returns the processing state of this intention
*
* @return array
*/
public function get_processing() {
return $this->processing;
}
/**
* Defines which data will be serialized to JSON
*/
public function jsonSerialize(): array {
return [
'id' => $this->get_id(),
'amount' => $this->get_amount(),
'currency' => $this->get_currency(),
'charge' => $this->get_charge(),
'created' => $this->get_created()->getTimestamp(),
'customer' => $this->get_customer_id(),
'metadata' => $this->get_metadata(),
'payment_method' => $this->get_payment_method_id(),
'processing' => $this->get_processing(),
'status' => $this->get_status(),
];
}
}