1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* PayPal Donation extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2015-2024 Skouat |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace skouat\ppde\entity; |
12
|
|
|
|
13
|
|
|
use phpbb\db\driver\driver_interface; |
14
|
|
|
use phpbb\language\language; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @property driver_interface db phpBB Database object |
18
|
|
|
* @property language language phpBB Language object |
19
|
|
|
* @property string lang_key_prefix Prefix for the messages thrown by exceptions |
20
|
|
|
* @property string lang_key_suffix Suffix for the messages thrown by exceptions |
21
|
|
|
*/ |
22
|
|
|
class transactions extends main |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Data for this entity |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
* business |
29
|
|
|
* confirmed |
30
|
|
|
* custom |
31
|
|
|
* exchange_rate |
32
|
|
|
* first_name |
33
|
|
|
* item_name |
34
|
|
|
* item_number |
35
|
|
|
* last_name |
36
|
|
|
* mc_currency |
37
|
|
|
* mc_fee |
38
|
|
|
* mc_gross |
39
|
|
|
* memo |
40
|
|
|
* net_amount |
41
|
|
|
* parent_txn_id |
42
|
|
|
* payer_email |
43
|
|
|
* payer_id |
44
|
|
|
* payer_status |
45
|
|
|
* payment_date |
46
|
|
|
* payment_status |
47
|
|
|
* payment_type |
48
|
|
|
* receiver_email |
49
|
|
|
* receiver_id |
50
|
|
|
* residence_country |
51
|
|
|
* settle_amount |
52
|
|
|
* settle_currency |
53
|
|
|
* transaction_id |
54
|
|
|
* test_ipn |
55
|
|
|
* txn_errors |
56
|
|
|
* txn_id |
57
|
|
|
* txn_type |
58
|
|
|
* user_id |
59
|
|
|
*/ |
60
|
|
|
protected $data; |
61
|
|
|
protected $extra_data = []; |
62
|
|
|
protected $transactions_log_table; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Constructor |
66
|
|
|
* |
67
|
|
|
* @param driver_interface $db Database object |
68
|
|
|
* @param language $language Language object |
69
|
|
|
* @param string $table_name Name of the table used to store data |
70
|
|
|
*/ |
71
|
|
|
public function __construct(driver_interface $db, language $language, $table_name) |
72
|
|
|
{ |
73
|
|
|
$this->transactions_log_table = $table_name; |
74
|
|
|
parent::__construct( |
75
|
|
|
$db, |
76
|
|
|
$language, |
77
|
|
|
'PPDE_DT', |
78
|
|
|
'TRANSACTION', |
79
|
|
|
$table_name, |
80
|
|
|
[ |
81
|
|
|
'item_id' => ['name' => 'transaction_id', 'type' => 'integer'], |
82
|
|
|
'item_business' => ['name' => 'business', 'type' => 'string'], |
83
|
|
|
'item_confirmed' => ['name' => 'confirmed', 'type' => 'boolean'], |
84
|
|
|
'item_custom' => ['name' => 'custom', 'type' => 'string'], |
85
|
|
|
'item_exchange_rate' => ['name' => 'exchange_rate', 'type' => 'string'], |
86
|
|
|
'item_first_name' => ['name' => 'first_name', 'type' => 'string'], |
87
|
|
|
'item_item_name' => ['name' => 'item_name', 'type' => 'string'], |
88
|
|
|
'item_item_number' => ['name' => 'item_number', 'type' => 'string'], |
89
|
|
|
'item_last_name' => ['name' => 'last_name', 'type' => 'string'], |
90
|
|
|
'item_mc_currency' => ['name' => 'mc_currency', 'type' => 'string'], |
91
|
|
|
'item_mc_fee' => ['name' => 'mc_fee', 'type' => 'float'], |
92
|
|
|
'item_mc_gross' => ['name' => 'mc_gross', 'type' => 'float'], |
93
|
|
|
'item_memo' => ['name' => 'memo', 'type' => 'string'], |
94
|
|
|
'item_net_amount' => ['name' => 'net_amount', 'type' => 'float'], |
95
|
|
|
'item_parent_txn_id' => ['name' => 'parent_txn_id', 'type' => 'string'], |
96
|
|
|
'item_payer_email' => ['name' => 'payer_email', 'type' => 'string'], |
97
|
|
|
'item_payer_id' => ['name' => 'payer_id', 'type' => 'string'], |
98
|
|
|
'item_payer_status' => ['name' => 'payer_status', 'type' => 'string'], |
99
|
|
|
'item_payment_date' => ['name' => 'payment_date', 'type' => 'integer'], |
100
|
|
|
'item_payment_status' => ['name' => 'payment_status', 'type' => 'string'], |
101
|
|
|
'item_payment_type' => ['name' => 'payment_type', 'type' => 'string'], |
102
|
|
|
'item_receiver_email' => ['name' => 'receiver_email', 'type' => 'string'], |
103
|
|
|
'item_receiver_id' => ['name' => 'receiver_id', 'type' => 'string'], |
104
|
|
|
'item_residence_country' => ['name' => 'residence_country', 'type' => 'string'], |
105
|
|
|
'item_settle_amount' => ['name' => 'settle_amount', 'type' => 'float'], |
106
|
|
|
'item_settle_currency' => ['name' => 'settle_currency', 'type' => 'string'], |
107
|
|
|
'item_test_ipn' => ['name' => 'test_ipn', 'type' => 'boolean'], |
108
|
|
|
'item_txn_errors' => ['name' => 'txn_errors', 'type' => 'string'], |
109
|
|
|
'item_txn_errors_approved' => ['name' => 'txn_errors_approved', 'type' => 'boolean'], |
110
|
|
|
'item_txn_id' => ['name' => 'txn_id', 'type' => 'string'], |
111
|
|
|
'item_txn_type' => ['name' => 'txn_type', 'type' => 'string'], |
112
|
|
|
'item_user_id' => ['name' => 'user_id', 'type' => 'integer'], |
113
|
|
|
] |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Checks if the txn_id exists for this transaction |
119
|
|
|
* |
120
|
|
|
* @return int $this->data['transaction_id'] Transaction identifier; 0 if the transaction doesn't exist |
121
|
|
|
*/ |
122
|
|
|
public function transaction_exists(): int |
123
|
|
|
{ |
124
|
|
|
$sql = 'SELECT transaction_id |
125
|
|
|
FROM ' . $this->transactions_log_table . " |
126
|
|
|
WHERE txn_id = '" . $this->db->sql_escape($this->data['txn_id']) . "'"; |
127
|
|
|
$result = $this->db->sql_query($sql); |
128
|
|
|
$field = (int) $this->db->sql_fetchfield('transaction_id'); |
129
|
|
|
$this->db->sql_freeresult($result); |
130
|
|
|
|
131
|
|
|
return $field; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Get PayPal transaction id |
136
|
|
|
* |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
|
|
public function get_txn_id(): string |
140
|
|
|
{ |
141
|
|
|
return (string) ($this->data['txn_id'] ?? ''); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Get PayPal receiver ID |
146
|
|
|
* |
147
|
|
|
* @return string |
148
|
|
|
*/ |
149
|
|
|
public function get_receiver_id(): string |
150
|
|
|
{ |
151
|
|
|
return (string) ($this->data['receiver_id'] ?? ''); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Get PayPal receiver e-mail |
156
|
|
|
* |
157
|
|
|
* @return string |
158
|
|
|
*/ |
159
|
|
|
public function get_receiver_email(): string |
160
|
|
|
{ |
161
|
|
|
return (string) ($this->data['receiver_email'] ?? ''); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Get PayPal receiver ID |
166
|
|
|
* |
167
|
|
|
* @return string |
168
|
|
|
*/ |
169
|
|
|
public function get_residence_country(): string |
170
|
|
|
{ |
171
|
|
|
return (string) ($this->data['residence_country'] ?? ''); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Get PayPal business (same as receiver ID or receiver_email) |
176
|
|
|
* |
177
|
|
|
* @return string |
178
|
|
|
*/ |
179
|
|
|
public function get_business(): string |
180
|
|
|
{ |
181
|
|
|
return (string) ($this->data['business'] ?? ''); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Get PayPal transaction status |
186
|
|
|
* |
187
|
|
|
* @return bool |
188
|
|
|
*/ |
189
|
|
|
public function get_confirmed(): bool |
190
|
|
|
{ |
191
|
|
|
return (bool) ($this->data['confirmed'] ?? false); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Get Test IPN status |
196
|
|
|
* |
197
|
|
|
* @return bool |
198
|
|
|
*/ |
199
|
|
|
public function get_test_ipn(): bool |
200
|
|
|
{ |
201
|
|
|
return (bool) ($this->data['test_ipn'] ?? false); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Get PayPal transaction errors |
206
|
|
|
* |
207
|
|
|
* @return string |
208
|
|
|
*/ |
209
|
|
|
public function get_txn_errors(): string |
210
|
|
|
{ |
211
|
|
|
return (string) ($this->data['txn_errors'] ?? ''); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Get PayPal transaction errors approval status |
216
|
|
|
* |
217
|
|
|
* @return bool |
218
|
|
|
*/ |
219
|
|
|
public function get_txn_errors_approved(): bool |
220
|
|
|
{ |
221
|
|
|
return (bool) ($this->data['txn_errors_approved'] ?? ''); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Get PayPal transaction type |
226
|
|
|
* |
227
|
|
|
* @return string |
228
|
|
|
*/ |
229
|
|
|
public function get_txn_type(): string |
230
|
|
|
{ |
231
|
|
|
return (string) ($this->data['txn_type'] ?? ''); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Get PayPal parent transaction ID (in case of refund) |
236
|
|
|
* |
237
|
|
|
* @return string |
238
|
|
|
*/ |
239
|
|
|
public function get_parent_txn_id(): string |
240
|
|
|
{ |
241
|
|
|
return (string) ($this->data['parent_txn_id'] ?? ''); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Get PayPal payer e-mail |
246
|
|
|
* |
247
|
|
|
* @return string |
248
|
|
|
*/ |
249
|
|
|
public function get_payer_email(): string |
250
|
|
|
{ |
251
|
|
|
return (string) ($this->data['payer_email'] ?? ''); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Get PayPal payer account ID |
256
|
|
|
* |
257
|
|
|
* @return string |
258
|
|
|
*/ |
259
|
|
|
public function get_payer_id(): string |
260
|
|
|
{ |
261
|
|
|
return (string) ($this->data['payer_id'] ?? ''); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Get PayPal payer Status (such as unverified/verified) |
266
|
|
|
* |
267
|
|
|
* @return string |
268
|
|
|
*/ |
269
|
|
|
public function get_payer_status(): string |
270
|
|
|
{ |
271
|
|
|
return (string) ($this->data['payer_status'] ?? ''); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Get PayPal payer first name |
276
|
|
|
* |
277
|
|
|
* @return string |
278
|
|
|
*/ |
279
|
|
|
public function get_first_name(): string |
280
|
|
|
{ |
281
|
|
|
return (string) ($this->data['first_name'] ?? ''); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Get PayPal payer last name |
286
|
|
|
* |
287
|
|
|
* @return string |
288
|
|
|
*/ |
289
|
|
|
public function get_last_name(): string |
290
|
|
|
{ |
291
|
|
|
return (string) ($this->data['last_name'] ?? ''); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Get member user_id |
296
|
|
|
* |
297
|
|
|
* @return int |
298
|
|
|
*/ |
299
|
|
|
public function get_user_id(): int |
300
|
|
|
{ |
301
|
|
|
return (int) ($this->data['user_id'] ?? 0); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Get member username |
306
|
|
|
* |
307
|
|
|
* @return string |
308
|
|
|
*/ |
309
|
|
|
public function get_username(): string |
310
|
|
|
{ |
311
|
|
|
return (string) ($this->extra_data['username'] ?? ''); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Get PayPal payer last name |
316
|
|
|
* |
317
|
|
|
* @return string |
318
|
|
|
*/ |
319
|
|
|
public function get_custom(): string |
320
|
|
|
{ |
321
|
|
|
return (string) ($this->data['custom'] ?? ''); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Get PayPal item name |
326
|
|
|
* |
327
|
|
|
* @return string |
328
|
|
|
*/ |
329
|
|
|
public function get_item_name(): string |
330
|
|
|
{ |
331
|
|
|
return (string) ($this->data['item_name'] ?? ''); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Get PayPal item number (contains user_id) |
336
|
|
|
* |
337
|
|
|
* @return string |
338
|
|
|
*/ |
339
|
|
|
public function get_item_number(): string |
340
|
|
|
{ |
341
|
|
|
return (string) ($this->data['item_number'] ?? ''); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Get PayPal currency name (eg: USD, EUR, etc.) |
346
|
|
|
* |
347
|
|
|
* @return string |
348
|
|
|
*/ |
349
|
|
|
public function get_mc_currency(): string |
350
|
|
|
{ |
351
|
|
|
return (string) ($this->data['mc_currency'] ?? ''); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Get PayPal fees |
356
|
|
|
* |
357
|
|
|
* @return float |
358
|
|
|
*/ |
359
|
|
|
public function get_mc_fee(): float |
360
|
|
|
{ |
361
|
|
|
return (float) ($this->data['mc_fee'] ?? 0); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* Get PayPal amount |
366
|
|
|
* This is the amount of donation received before fees |
367
|
|
|
* |
368
|
|
|
* @return float |
369
|
|
|
*/ |
370
|
|
|
public function get_mc_gross(): float |
371
|
|
|
{ |
372
|
|
|
return (float) ($this->data['mc_gross'] ?? 0); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* Get Net amount |
377
|
|
|
* This is the amount of donation received after fees |
378
|
|
|
* |
379
|
|
|
* @return float |
380
|
|
|
*/ |
381
|
|
|
public function get_net_amount(): float |
382
|
|
|
{ |
383
|
|
|
return (float) ($this->data['net_amount'] ?? 0); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* Get PayPal payment date |
388
|
|
|
* |
389
|
|
|
* @return int |
390
|
|
|
*/ |
391
|
|
|
public function get_payment_date(): int |
392
|
|
|
{ |
393
|
|
|
return (int) ($this->data['payment_date'] ?? 0); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* Get PayPal payment status |
398
|
|
|
* |
399
|
|
|
* @return string |
400
|
|
|
*/ |
401
|
|
|
public function get_payment_status(): string |
402
|
|
|
{ |
403
|
|
|
return (string) ($this->data['payment_status'] ?? ''); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* Get PayPal payment type |
408
|
|
|
* |
409
|
|
|
* @return string |
410
|
|
|
*/ |
411
|
|
|
public function get_payment_type(): string |
412
|
|
|
{ |
413
|
|
|
return (string) ($this->data['payment_type'] ?? ''); |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* Get PayPal memo |
418
|
|
|
* |
419
|
|
|
* @return string |
420
|
|
|
*/ |
421
|
|
|
public function get_memo(): string |
422
|
|
|
{ |
423
|
|
|
return (string) ($this->data['memo'] ?? ''); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* Get PayPal settle amount |
428
|
|
|
* This is in case or the currency of the Payer is not in the same currency of the Receiver |
429
|
|
|
* |
430
|
|
|
* @return float |
431
|
|
|
*/ |
432
|
|
|
public function get_settle_amount(): float |
433
|
|
|
{ |
434
|
|
|
return (float) ($this->data['settle_amount'] ?? 0); |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* Get PayPal settle currency |
439
|
|
|
* |
440
|
|
|
* @return string |
441
|
|
|
*/ |
442
|
|
|
public function get_settle_currency(): string |
443
|
|
|
{ |
444
|
|
|
return (string) ($this->data['settle_currency'] ?? ''); |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* Get PayPal exchange rate |
449
|
|
|
* This is when the donation don’t use the same currency defined by the receiver |
450
|
|
|
* |
451
|
|
|
* @return string |
452
|
|
|
*/ |
453
|
|
|
public function get_exchange_rate(): string |
454
|
|
|
{ |
455
|
|
|
return (string) ($this->data['exchange_rate'] ?? ''); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* Set PayPal transaction errors approval status |
460
|
|
|
* |
461
|
|
|
* @param bool $txn_errors_approved |
462
|
|
|
* |
463
|
|
|
* @return transactions $this object for chaining calls; load()->set()->save() |
464
|
|
|
*/ |
465
|
|
|
public function set_txn_errors_approved($txn_errors_approved) |
466
|
|
|
{ |
467
|
|
|
$this->data['txn_errors_approved'] = (bool) $txn_errors_approved; |
468
|
|
|
|
469
|
|
|
return $this; |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* Set member user_id |
474
|
|
|
* |
475
|
|
|
* @param int $user_id |
476
|
|
|
* |
477
|
|
|
* @return transactions $this object for chaining calls; load()->set()->save() |
478
|
|
|
*/ |
479
|
|
|
public function set_user_id($user_id) |
480
|
|
|
{ |
481
|
|
|
$this->data['user_id'] = (integer) $user_id; |
482
|
|
|
|
483
|
|
|
return $this; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* Set member username |
488
|
|
|
* |
489
|
|
|
* @param string $username |
490
|
|
|
* |
491
|
|
|
* @return transactions $this object for chaining calls; load()->set()->save() |
492
|
|
|
*/ |
493
|
|
|
public function set_username($username) |
494
|
|
|
{ |
495
|
|
|
$this->extra_data['username'] = (string) $username; |
496
|
|
|
|
497
|
|
|
return $this; |
498
|
|
|
} |
499
|
|
|
} |
500
|
|
|
|