1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* PayPal Donation extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2018 Skouat |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace skouat\ppde\notification; |
12
|
|
|
|
13
|
|
|
use phpbb\notification\manager; |
14
|
|
|
use skouat\ppde\actions\currency; |
15
|
|
|
use skouat\ppde\entity\transactions; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
17
|
|
|
|
18
|
|
|
class core |
19
|
|
|
{ |
20
|
|
|
protected $notification; |
21
|
|
|
protected $container; |
22
|
|
|
protected $ppde_actions_currency; |
23
|
|
|
protected $ppde_entity_transaction; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Constructor |
27
|
|
|
* |
28
|
|
|
* @param ContainerInterface $container Service container interface |
29
|
|
|
* @param manager $notification Notification object |
30
|
|
|
* @param \skouat\ppde\actions\currency $ppde_actions_currency Currency actions object |
31
|
|
|
* @param \skouat\ppde\entity\transactions $ppde_entity_transaction Transaction entity object |
32
|
|
|
* @access public |
33
|
|
|
*/ |
34
|
|
|
public function __construct( |
35
|
|
|
ContainerInterface $container, |
36
|
|
|
manager $notification, |
37
|
|
|
currency $ppde_actions_currency, |
38
|
|
|
transactions $ppde_entity_transaction |
39
|
|
|
) |
40
|
|
|
{ |
41
|
|
|
$this->container = $container; |
42
|
|
|
$this->notification = $notification; |
43
|
|
|
$this->ppde_actions_currency = $ppde_actions_currency; |
44
|
|
|
$this->ppde_entity_transaction = $ppde_entity_transaction; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Notify admin when the donation contains errors |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
* @access public |
52
|
|
|
*/ |
53
|
|
|
public function notify_donation_errors() |
54
|
|
|
{ |
55
|
|
|
$notification_data = $this->notify_donation_core('donation_errors'); |
56
|
|
|
$this->notification->add_notifications('skouat.ppde.notification.type.admin_donation_errors', $notification_data); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Notify admin when the donation is received |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
* @access public |
64
|
|
|
*/ |
65
|
|
|
public function notify_admin_donation_received() |
66
|
|
|
{ |
67
|
|
|
$notification_data = $this->notify_donation_core(); |
68
|
|
|
$this->notification->add_notifications('skouat.ppde.notification.type.admin_donation_received', $notification_data); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Notify donor when the donation is received |
73
|
|
|
* |
74
|
|
|
* @return void |
75
|
|
|
* @access public |
76
|
|
|
*/ |
77
|
|
|
public function notify_donor_donation_received() |
78
|
|
|
{ |
79
|
|
|
$notification_data = $this->notify_donation_core(); |
80
|
|
|
$this->notification->add_notifications('skouat.ppde.notification.type.donor_donation_received', $notification_data); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Build Notification data |
85
|
|
|
* |
86
|
|
|
* @param string $donation_type |
87
|
|
|
* |
88
|
|
|
* @return array |
89
|
|
|
* @access private |
90
|
|
|
*/ |
91
|
|
|
private function notify_donation_core($donation_type = '') |
92
|
|
|
{ |
93
|
|
|
switch ($donation_type) |
94
|
|
|
{ |
95
|
|
|
case 'donation_errors': |
96
|
|
|
$notification_data['txn_errors'] = $this->ppde_entity_transaction->get_txn_errors(); |
|
|
|
|
97
|
|
|
// No break |
98
|
|
|
default: |
99
|
|
|
// Set currency data properties |
100
|
|
|
$currency_mc_data = $this->ppde_actions_currency->get_currency_data($this->ppde_entity_transaction->get_mc_currency()); |
101
|
|
|
|
102
|
|
|
// Set currency settle data properties if exists |
103
|
|
|
$settle_amount = ''; |
104
|
|
|
if ($this->ppde_entity_transaction->get_settle_amount()) |
105
|
|
|
{ |
106
|
|
|
$currency_settle_data = $this->ppde_actions_currency->get_currency_data($this->ppde_entity_transaction->get_settle_currency()); |
107
|
|
|
$settle_amount = $this->ppde_actions_currency->currency_on_left((float) $settle_amount, $currency_settle_data[0]['currency_symbol'], (bool) $currency_settle_data[0]['currency_on_left']); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$notification_data = array( |
111
|
|
|
'net_amount' => $this->ppde_actions_currency->currency_on_left($this->ppde_entity_transaction->get_net_amount(), $currency_mc_data[0]['currency_symbol'], (bool) $currency_mc_data[0]['currency_on_left']), |
112
|
|
|
'mc_gross' => $this->ppde_actions_currency->currency_on_left($this->ppde_entity_transaction->get_mc_gross(), $currency_mc_data[0]['currency_symbol'], (bool) $currency_mc_data[0]['currency_on_left']), |
113
|
|
|
'payer_email' => $this->ppde_entity_transaction->get_payer_email(), |
114
|
|
|
'payer_username' => $this->ppde_entity_transaction->get_username(), |
115
|
|
|
'settle_amount' => $settle_amount, |
116
|
|
|
'transaction_id' => $this->ppde_entity_transaction->get_id(), |
117
|
|
|
'txn_id' => $this->ppde_entity_transaction->get_txn_id(), |
118
|
|
|
'user_from' => $this->ppde_entity_transaction->get_user_id(), |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return $notification_data; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|