|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* PayPal Donation extension for the phpBB Forum Software package. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright (c) 2015 Skouat |
|
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace skouat\ppde\controller; |
|
12
|
|
|
|
|
13
|
|
|
use phpbb\auth\auth; |
|
14
|
|
|
use phpbb\config\config; |
|
15
|
|
|
use phpbb\controller\helper; |
|
16
|
|
|
use phpbb\language\language; |
|
17
|
|
|
use phpbb\request\request; |
|
18
|
|
|
use phpbb\template\template; |
|
19
|
|
|
use phpbb\user; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
21
|
|
|
|
|
22
|
|
|
class main_controller |
|
23
|
|
|
{ |
|
24
|
|
|
/** Production Postback URL */ |
|
25
|
|
|
const VERIFY_URI = 'https://ipnpb.paypal.com/cgi-bin/webscr'; |
|
26
|
|
|
/** Sandbox Postback URL */ |
|
27
|
|
|
const SANDBOX_VERIFY_URI = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr'; |
|
28
|
|
|
|
|
29
|
|
|
protected $auth; |
|
30
|
|
|
protected $config; |
|
31
|
|
|
protected $container; |
|
32
|
|
|
protected $helper; |
|
33
|
|
|
protected $language; |
|
34
|
|
|
protected $ppde_actions_currency; |
|
35
|
|
|
protected $request; |
|
36
|
|
|
protected $template; |
|
37
|
|
|
protected $user; |
|
38
|
|
|
protected $root_path; |
|
39
|
|
|
protected $php_ext; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Constructor |
|
43
|
|
|
* |
|
44
|
|
|
* @param auth $auth Auth object |
|
45
|
|
|
* @param config $config Config object |
|
46
|
|
|
* @param ContainerInterface $container Service container interface |
|
47
|
|
|
* @param helper $helper Controller helper object |
|
48
|
|
|
* @param language $language Language user object |
|
49
|
|
|
* @param \skouat\ppde\actions\currency $ppde_actions_currency Currency actions object |
|
50
|
|
|
* @param request $request Request object |
|
51
|
|
|
* @param template $template Template object |
|
52
|
|
|
* @param user $user User object |
|
53
|
|
|
* @param string $root_path phpBB root path |
|
54
|
|
|
* @param string $php_ext phpEx |
|
55
|
|
|
* |
|
56
|
|
|
* @access public |
|
57
|
|
|
*/ |
|
58
|
|
|
public function __construct(auth $auth, config $config, ContainerInterface $container, helper $helper, language $language, \skouat\ppde\actions\currency $ppde_actions_currency, request $request, template $template, user $user, $root_path, $php_ext) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->auth = $auth; |
|
61
|
|
|
$this->config = $config; |
|
62
|
|
|
$this->container = $container; |
|
63
|
|
|
$this->helper = $helper; |
|
64
|
|
|
$this->language = $language; |
|
65
|
|
|
$this->ppde_actions_currency = $ppde_actions_currency; |
|
66
|
|
|
$this->request = $request; |
|
67
|
|
|
$this->template = $template; |
|
68
|
|
|
$this->user = $user; |
|
69
|
|
|
$this->root_path = $root_path; |
|
70
|
|
|
$this->php_ext = $php_ext; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function handle() |
|
74
|
|
|
{ |
|
75
|
|
|
// We stop the execution of the code because nothing need to be returned to phpBB. |
|
76
|
|
|
garbage_collection(); |
|
77
|
|
|
exit_handler(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return bool |
|
82
|
|
|
* @access public |
|
83
|
|
|
*/ |
|
84
|
|
|
public function can_use_ppde() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->auth->acl_get('u_ppde_use'); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return bool |
|
91
|
|
|
* @access public |
|
92
|
|
|
*/ |
|
93
|
|
|
public function can_view_ppde_donorlist() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->auth->acl_get('u_ppde_view_donorlist'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return bool |
|
100
|
|
|
* @access private |
|
101
|
|
|
*/ |
|
102
|
|
|
public function donorlist_is_enabled() |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->use_ipn() && $this->config['ppde_ipn_donorlist_enable']; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Check if IPN is enabled based on config value |
|
109
|
|
|
* |
|
110
|
|
|
* @return bool |
|
111
|
|
|
* @access public |
|
112
|
|
|
*/ |
|
113
|
|
|
public function use_ipn() |
|
114
|
|
|
{ |
|
115
|
|
|
return !empty($this->config['ppde_enable']) && !empty($this->config['ppde_ipn_enable']) && $this->is_ipn_requirement_satisfied(); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Check if IPN requirements are satisfied based on config value |
|
120
|
|
|
* |
|
121
|
|
|
* @return bool |
|
122
|
|
|
* @access public |
|
123
|
|
|
*/ |
|
124
|
|
|
public function is_ipn_requirement_satisfied() |
|
125
|
|
|
{ |
|
126
|
|
|
return !empty($this->config['ppde_curl_detected']) && !empty($this->config['ppde_tls_detected']); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Get PayPal URI |
|
131
|
|
|
* Used in form and in IPN process |
|
132
|
|
|
* |
|
133
|
|
|
* @param bool $is_test_ipn |
|
134
|
|
|
* |
|
135
|
|
|
* @return string |
|
136
|
|
|
* @access public |
|
137
|
|
|
*/ |
|
138
|
|
|
public function get_paypal_uri($is_test_ipn = false) |
|
139
|
|
|
{ |
|
140
|
|
|
return ($is_test_ipn || $this->use_sandbox()) ? self::SANDBOX_VERIFY_URI : self::VERIFY_URI; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Check if Sandbox is enabled based on config value |
|
145
|
|
|
* |
|
146
|
|
|
* @return bool |
|
147
|
|
|
* @access public |
|
148
|
|
|
*/ |
|
149
|
|
|
public function use_sandbox() |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->use_ipn() && !empty($this->config['ppde_sandbox_enable']) && $this->is_sandbox_founder_enable(); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Check if Sandbox could be use by founders based on config value |
|
156
|
|
|
* |
|
157
|
|
|
* @return bool |
|
158
|
|
|
* @access public |
|
159
|
|
|
*/ |
|
160
|
|
|
public function is_sandbox_founder_enable() |
|
161
|
|
|
{ |
|
162
|
|
|
return (!empty($this->config['ppde_sandbox_founder_enable']) && ($this->user->data['user_type'] == USER_FOUNDER)) || empty($this->config['ppde_sandbox_founder_enable']); |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|