1 | <?php |
||
2 | /** |
||
3 | * Gateway |
||
4 | * |
||
5 | * @author Pronamic <[email protected]> |
||
6 | * @copyright 2005-2022 Pronamic |
||
7 | * @license GPL-3.0-or-later |
||
8 | * @package Pronamic\WordPress\Pay\Extensions\MemberPress |
||
9 | */ |
||
10 | |||
11 | namespace Pronamic\WordPress\Pay\Extensions\MemberPress\Gateways; |
||
12 | |||
13 | use MeprBaseRealGateway; |
||
0 ignored issues
–
show
|
|||
14 | use MeprEmailFactory; |
||
0 ignored issues
–
show
The type
MeprEmailFactory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
15 | use MeprOptions; |
||
0 ignored issues
–
show
The type
MeprOptions was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
16 | use MeprProduct; |
||
0 ignored issues
–
show
The type
MeprProduct was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
17 | use MeprSubscription; |
||
0 ignored issues
–
show
The type
MeprSubscription was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
18 | use MeprTransaction; |
||
0 ignored issues
–
show
The type
MeprTransaction was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
19 | use MeprTransactionsHelper; |
||
0 ignored issues
–
show
The type
MeprTransactionsHelper was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
20 | use MeprUser; |
||
0 ignored issues
–
show
The type
MeprUser was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
21 | use MeprUtils; |
||
0 ignored issues
–
show
The type
MeprUtils was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
22 | use MeprView; |
||
0 ignored issues
–
show
The type
MeprView was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
23 | use Pronamic\WordPress\Pay\Core\PaymentMethods; |
||
24 | use Pronamic\WordPress\Pay\Core\Util as Core_Util; |
||
25 | use Pronamic\WordPress\Pay\Payments\Payment; |
||
26 | use Pronamic\WordPress\Pay\Plugin; |
||
27 | use Pronamic\WordPress\Pay\Extensions\MemberPress\MemberPress; |
||
28 | use Pronamic\WordPress\Pay\Extensions\MemberPress\Pronamic; |
||
29 | use Pronamic\WordPress\Pay\Subscriptions\SubscriptionStatus; |
||
30 | use ReflectionClass; |
||
31 | |||
32 | /** |
||
33 | * WordPress pay MemberPress gateway |
||
34 | * |
||
35 | * @author Remco Tolsma |
||
36 | * @version 3.1.0 |
||
37 | * @since 1.0.0 |
||
38 | */ |
||
39 | class Gateway extends MeprBaseRealGateway { |
||
40 | /** |
||
41 | * Payment method. |
||
42 | * |
||
43 | * @var string|null |
||
44 | */ |
||
45 | protected $payment_method; |
||
46 | |||
47 | /** |
||
48 | * Class alias. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $class_alias; |
||
53 | |||
54 | /** |
||
55 | * Key. |
||
56 | * |
||
57 | * The key property is not defined in the MemberPress library, |
||
58 | * but it is a MemberPress property. |
||
59 | * |
||
60 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php |
||
61 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L12 |
||
62 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/helpers/MeprOptionsHelper.php#L192 |
||
63 | * @var string |
||
64 | */ |
||
65 | public $key; |
||
66 | |||
67 | /** |
||
68 | * Constructs and initialize gateway. |
||
69 | * |
||
70 | * @param string $class_alias Class alias. |
||
71 | * @param string|null $payment_method Payment method. |
||
72 | */ |
||
73 | public function __construct( $class_alias = 'MeprPronamicGateway', $payment_method = null ) { |
||
74 | $this->class_alias = $class_alias; |
||
75 | |||
76 | $this->payment_method = $payment_method; |
||
77 | |||
78 | // Set the name of this gateway. |
||
79 | // @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L12-13. |
||
80 | $this->name = __( 'Pronamic', 'pronamic_ideal' ); |
||
0 ignored issues
–
show
|
|||
81 | |||
82 | if ( ! empty( $this->payment_method ) ) { |
||
83 | $this->name = sprintf( |
||
84 | /* translators: %s: payment method name */ |
||
85 | __( 'Pronamic - %s', 'pronamic_ideal' ), |
||
86 | PaymentMethods::get_name( $this->payment_method ) |
||
87 | ); |
||
88 | } |
||
89 | |||
90 | // Set the default settings. |
||
91 | // @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L72-73. |
||
92 | $this->set_defaults(); |
||
93 | |||
94 | // Set the capabilities of this gateway. |
||
95 | // @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L36-37. |
||
96 | $this->capabilities = array(); |
||
0 ignored issues
–
show
|
|||
97 | |||
98 | // Setup the notification actions for this gateway. |
||
99 | $this->notifiers = array(); |
||
0 ignored issues
–
show
|
|||
100 | |||
101 | // Support single-page checkout. |
||
102 | $this->has_spc_form = true; |
||
0 ignored issues
–
show
|
|||
103 | |||
104 | // Key. |
||
105 | $key = 'pronamic_pay'; |
||
106 | |||
107 | if ( null !== $this->payment_method ) { |
||
108 | $key = sprintf( 'pronamic_pay_%s', $this->payment_method ); |
||
109 | } |
||
110 | |||
111 | $this->key = $key; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Load the specified settings. |
||
116 | * |
||
117 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L73-L74 |
||
118 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprGatewayFactory.php#L18 |
||
119 | * @param mixed $settings MemberPress gateway settings array. |
||
120 | * @return void |
||
121 | */ |
||
122 | public function load( $settings ) { |
||
123 | $this->settings = (object) $settings; |
||
0 ignored issues
–
show
|
|||
124 | |||
125 | $this->set_defaults(); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Get icon function (this is not a MemberPress function). |
||
130 | * |
||
131 | * @since 1.0.2 |
||
132 | * @return string|null |
||
133 | */ |
||
134 | protected function get_icon() { |
||
135 | return PaymentMethods::get_icon_url( $this->payment_method ); |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Set the default settings. |
||
140 | * |
||
141 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L76-L77 |
||
142 | * @return void |
||
143 | */ |
||
144 | protected function set_defaults() { |
||
145 | if ( ! isset( $this->settings ) ) { |
||
146 | $this->settings = array(); |
||
0 ignored issues
–
show
|
|||
147 | } |
||
148 | |||
149 | $this->settings = (object) array_merge( |
||
150 | array( |
||
151 | 'gateway' => $this->class_alias, |
||
152 | 'id' => $this->generate_id(), |
||
153 | 'label' => '', |
||
154 | 'use_label' => true, |
||
155 | 'icon' => $this->get_icon(), |
||
156 | 'use_icon' => true, |
||
157 | 'desc' => '', |
||
158 | 'use_desc' => true, |
||
159 | 'config_id' => '', |
||
160 | 'email' => '', |
||
161 | 'sandbox' => false, |
||
162 | 'debug' => false, |
||
163 | ), |
||
164 | (array) $this->settings |
||
165 | ); |
||
166 | |||
167 | $this->id = $this->settings->id; |
||
0 ignored issues
–
show
|
|||
168 | $this->label = $this->settings->label; |
||
0 ignored issues
–
show
|
|||
169 | $this->use_label = $this->settings->use_label; |
||
0 ignored issues
–
show
|
|||
170 | $this->icon = $this->settings->icon; |
||
0 ignored issues
–
show
|
|||
171 | $this->use_icon = $this->settings->use_icon; |
||
0 ignored issues
–
show
|
|||
172 | $this->desc = $this->settings->desc; |
||
0 ignored issues
–
show
|
|||
173 | $this->use_desc = $this->settings->use_desc; |
||
0 ignored issues
–
show
|
|||
174 | } |
||
175 | |||
176 | /** |
||
177 | * Process payment. |
||
178 | * |
||
179 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L149-L152 |
||
180 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L520-L585 |
||
181 | * @param MeprTransaction $transaction MemberPress transaction object. |
||
182 | * @return void |
||
183 | */ |
||
184 | public function process_payment( $transaction ) { |
||
185 | // Gateway. |
||
186 | $config_id = $this->get_config_id(); |
||
187 | |||
188 | $gateway = Plugin::get_gateway( $config_id ); |
||
189 | |||
190 | if ( null === $gateway ) { |
||
191 | return; |
||
192 | } |
||
193 | |||
194 | // Create Pronamic payment. |
||
195 | $payment = Pronamic::get_payment( $transaction ); |
||
196 | |||
197 | $payment->config_id = $config_id; |
||
198 | |||
199 | $payment->set_payment_method( $this->payment_method ); |
||
200 | |||
201 | $payment = Plugin::start_payment( $payment ); |
||
202 | |||
203 | $gateway->redirect( $payment ); |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * Get payment method. |
||
208 | * |
||
209 | * @return string|null |
||
210 | */ |
||
211 | public function get_payment_method() { |
||
212 | return $this->payment_method; |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * Record subscription payment. |
||
217 | * |
||
218 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L170-L175 |
||
219 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L587-L714 |
||
220 | * @return void |
||
221 | */ |
||
222 | public function record_subscription_payment() { |
||
223 | |||
224 | } |
||
225 | |||
226 | /** |
||
227 | * Record payment failure. |
||
228 | * |
||
229 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L177-L178 |
||
230 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L833-L910 |
||
231 | * @return void |
||
232 | */ |
||
233 | public function record_payment_failure() { |
||
234 | |||
235 | } |
||
236 | |||
237 | /** |
||
238 | * Record payment. |
||
239 | * |
||
240 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L154-L159 |
||
241 | * @return void |
||
242 | */ |
||
243 | public function record_payment() { |
||
244 | |||
245 | } |
||
246 | |||
247 | /** |
||
248 | * Process refund. |
||
249 | * |
||
250 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L161-L163 |
||
251 | * @param MeprTransaction $txn MemberPress transaction object. |
||
252 | * @return void |
||
253 | */ |
||
254 | public function process_refund( MeprTransaction $txn ) { |
||
255 | |||
256 | } |
||
257 | |||
258 | /** |
||
259 | * Record refund. |
||
260 | * |
||
261 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L165-L168 |
||
262 | * @return void |
||
263 | */ |
||
264 | public function record_refund() { |
||
265 | |||
266 | } |
||
267 | |||
268 | /** |
||
269 | * Process trial payment. |
||
270 | * |
||
271 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L180-L187 |
||
272 | * @param MeprTransaction $transaction MemberPress transaction object. |
||
273 | * @return void |
||
274 | */ |
||
275 | public function process_trial_payment( $transaction ) { |
||
276 | $this->process_payment( $transaction ); |
||
277 | } |
||
278 | |||
279 | /** |
||
280 | * Record trial payment. |
||
281 | * |
||
282 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L189-L191 |
||
283 | * @param MeprTransaction $transaction MemberPress transaction object. |
||
284 | * @return void |
||
285 | */ |
||
286 | public function record_trial_payment( $transaction ) { |
||
287 | |||
288 | } |
||
289 | |||
290 | /** |
||
291 | * Process create subscription. |
||
292 | * |
||
293 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L193-L197 |
||
294 | * @param MeprTransaction $transaction MemberPress transaction object. |
||
295 | * @return void |
||
296 | */ |
||
297 | public function process_create_subscription( $transaction ) { |
||
298 | $subscription = $transaction->subscription(); |
||
299 | |||
300 | /** |
||
301 | * In the `process_create_subscription` function, every MemberPress |
||
302 | * transaction will be linked to a MemberPress subscription, but |
||
303 | * just to be sure we check this. |
||
304 | * |
||
305 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L312 |
||
306 | */ |
||
307 | if ( false !== $subscription ) { |
||
308 | /** |
||
309 | * The MemberPress transaction total does not contain the |
||
310 | * prorated or trial amount. |
||
311 | * |
||
312 | * We stole this code from the `MeprArtificialGateway` also |
||
313 | * known as the 'Offline Payment' gateway. |
||
314 | * |
||
315 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprArtificialGateway.php#L217 |
||
316 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L306-L311 |
||
317 | */ |
||
318 | if ( $subscription->trial ) { |
||
319 | $transaction->set_subtotal( MeprUtils::format_float( $subscription->trial_amount ) ); |
||
320 | |||
321 | $transaction->store(); |
||
322 | } |
||
323 | } |
||
324 | |||
325 | $this->process_payment( $transaction ); |
||
326 | } |
||
327 | |||
328 | /** |
||
329 | * Record create subscription. |
||
330 | * |
||
331 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L199-L204 |
||
332 | * @return void |
||
333 | */ |
||
334 | public function record_create_subscription() { |
||
335 | |||
336 | } |
||
337 | |||
338 | /** |
||
339 | * Process update subscription. |
||
340 | * |
||
341 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L206 |
||
342 | * @param int $sub_id Subscription ID. |
||
343 | * @return void |
||
344 | */ |
||
345 | public function process_update_subscription( $sub_id ) { |
||
346 | |||
347 | } |
||
348 | |||
349 | /** |
||
350 | * Record update subscription. |
||
351 | * |
||
352 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L208-L212 |
||
353 | * @return void |
||
354 | */ |
||
355 | public function record_update_subscription() { |
||
356 | |||
357 | } |
||
358 | |||
359 | /** |
||
360 | * Process suspend subscription. |
||
361 | * |
||
362 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/controllers/MeprAccountCtrl.php#L339-L360 |
||
363 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L214-L216 |
||
364 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L1429-L1459 |
||
365 | * @param int $subscription_id Subscription id. |
||
366 | * @return void |
||
367 | */ |
||
368 | public function process_suspend_subscription( $subscription_id ) { |
||
369 | $memberpress_subscription = MemberPress::get_subscription_by_id( $subscription_id ); |
||
370 | |||
371 | if ( null === $memberpress_subscription ) { |
||
372 | return; |
||
373 | } |
||
374 | |||
375 | /** |
||
376 | * If the MemberPress subscription is already suspended we bail out. |
||
377 | */ |
||
378 | if ( MeprSubscription::$suspended_str === $memberpress_subscription->status ) { |
||
379 | return; |
||
380 | } |
||
381 | |||
382 | $pronamic_subscription = \get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $memberpress_subscription->id ); |
||
383 | |||
384 | if ( ! $pronamic_subscription ) { |
||
385 | return; |
||
386 | } |
||
387 | |||
388 | $memberpress_subscription->status = MeprSubscription::$suspended_str; |
||
389 | |||
390 | $memberpress_subscription->store(); |
||
391 | |||
392 | // Send suspended subscription notices. |
||
393 | MeprUtils::send_suspended_sub_notices( $memberpress_subscription ); |
||
394 | |||
395 | $note = sprintf( |
||
396 | /* translators: %s: extension name */ |
||
397 | __( '%s subscription on hold.', 'pronamic_ideal' ), |
||
398 | __( 'MemberPress', 'pronamic_ideal' ) |
||
399 | ); |
||
400 | |||
401 | $pronamic_subscription->add_note( $note ); |
||
402 | |||
403 | // The status of canceled or completed subscriptions will not be changed automatically. |
||
404 | if ( ! in_array( $pronamic_subscription->get_status(), array( SubscriptionStatus::CANCELLED, SubscriptionStatus::COMPLETED ), true ) ) { |
||
405 | $pronamic_subscription->set_status( SubscriptionStatus::ON_HOLD ); |
||
406 | |||
407 | $pronamic_subscription->save(); |
||
408 | } |
||
409 | } |
||
410 | |||
411 | /** |
||
412 | * Record suspend subscription. |
||
413 | * |
||
414 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L218-L221 |
||
415 | * @return void |
||
416 | */ |
||
417 | public function record_suspend_subscription() { |
||
418 | |||
419 | } |
||
420 | |||
421 | /** |
||
422 | * Process resume subscription. |
||
423 | * |
||
424 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/controllers/MeprAccountCtrl.php#L362-L383 |
||
425 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L223-L225 |
||
426 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L1489-L1550 |
||
427 | * @param int $subscription_id Subscription id. |
||
428 | * @return void |
||
429 | */ |
||
430 | public function process_resume_subscription( $subscription_id ) { |
||
431 | $memberpress_subscription = MemberPress::get_subscription_by_id( $subscription_id ); |
||
432 | |||
433 | if ( null === $memberpress_subscription ) { |
||
434 | return; |
||
435 | } |
||
436 | |||
437 | /** |
||
438 | * If the MemberPress subscription is already active we bail out. |
||
439 | */ |
||
440 | if ( MeprSubscription::$active_str === $memberpress_subscription->status ) { |
||
441 | return; |
||
442 | } |
||
443 | |||
444 | $pronamic_subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $memberpress_subscription->id ); |
||
445 | |||
446 | if ( ! $pronamic_subscription ) { |
||
447 | return; |
||
448 | } |
||
449 | |||
450 | $memberpress_subscription->status = MeprSubscription::$active_str; |
||
451 | |||
452 | $memberpress_subscription->store(); |
||
453 | |||
454 | /** |
||
455 | * If the Pronamic subscription requires a follow-up payment start this. |
||
456 | * |
||
457 | * @todo |
||
458 | */ |
||
459 | |||
460 | // Send resumed subscription notices. |
||
461 | MeprUtils::send_resumed_sub_notices( $memberpress_subscription ); |
||
462 | |||
463 | // Add note. |
||
464 | $note = sprintf( |
||
465 | /* translators: %s: extension name */ |
||
466 | __( '%s subscription reactivated.', 'pronamic_ideal' ), |
||
467 | __( 'MemberPress', 'pronamic_ideal' ) |
||
468 | ); |
||
469 | |||
470 | $pronamic_subscription->add_note( $note ); |
||
471 | |||
472 | // The status of canceled or completed subscriptions will not be changed automatically. |
||
473 | if ( ! in_array( $pronamic_subscription->get_status(), array( SubscriptionStatus::CANCELLED, SubscriptionStatus::COMPLETED ), true ) ) { |
||
474 | $pronamic_subscription->set_status( SubscriptionStatus::ACTIVE ); |
||
475 | |||
476 | $pronamic_subscription->save(); |
||
477 | } |
||
478 | } |
||
479 | |||
480 | /** |
||
481 | * Record resume subscription. |
||
482 | * |
||
483 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L227-L230 |
||
484 | * @return void |
||
485 | */ |
||
486 | public function record_resume_subscription() { |
||
487 | |||
488 | } |
||
489 | |||
490 | /** |
||
491 | * Process cancel subscription. |
||
492 | * |
||
493 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L232-L236 |
||
494 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L1687-L1715 |
||
495 | * @param int $subscription_id Subscription id. |
||
496 | * @return void |
||
497 | */ |
||
498 | public function process_cancel_subscription( $subscription_id ) { |
||
499 | $memberpress_subscription = MemberPress::get_subscription_by_id( $subscription_id ); |
||
500 | |||
501 | if ( null === $memberpress_subscription ) { |
||
502 | return; |
||
503 | } |
||
504 | |||
505 | /** |
||
506 | * If the MemberPress subscription is already cancelled we bail out. |
||
507 | */ |
||
508 | if ( MeprSubscription::$cancelled_str === $memberpress_subscription->status ) { |
||
509 | return; |
||
510 | } |
||
511 | |||
512 | $pronamic_subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $memberpress_subscription->id ); |
||
513 | |||
514 | if ( ! $pronamic_subscription ) { |
||
515 | return; |
||
516 | } |
||
517 | |||
518 | // Add note. |
||
519 | $note = sprintf( |
||
520 | /* translators: %s: extension name */ |
||
521 | __( '%s subscription cancelled.', 'pronamic_ideal' ), |
||
522 | __( 'MemberPress', 'pronamic_ideal' ) |
||
523 | ); |
||
524 | |||
525 | $pronamic_subscription->add_note( $note ); |
||
526 | |||
527 | // The status of canceled or completed subscriptions will not be changed automatically. |
||
528 | if ( ! in_array( $pronamic_subscription->get_status(), array( SubscriptionStatus::CANCELLED, SubscriptionStatus::COMPLETED ), true ) ) { |
||
529 | $pronamic_subscription->set_status( SubscriptionStatus::CANCELLED ); |
||
530 | |||
531 | $pronamic_subscription->save(); |
||
532 | } |
||
533 | |||
534 | // Cancel MemberPress subscription. |
||
535 | $memberpress_subscription->status = MeprSubscription::$cancelled_str; |
||
536 | |||
537 | $memberpress_subscription->store(); |
||
538 | |||
539 | // Expire the grace period (confirmation) if no completed payments have come through. |
||
540 | if ( (int) $memberpress_subscription->txn_count <= 0 ) { |
||
541 | $memberpress_subscription->expire_txns(); |
||
542 | } |
||
543 | |||
544 | $memberpress_subscription->limit_reached_actions(); |
||
545 | |||
546 | // Send cancelled subscription notices. |
||
547 | MeprUtils::send_cancelled_sub_notices( $memberpress_subscription ); |
||
548 | } |
||
549 | |||
550 | /** |
||
551 | * Record cancel subscription. |
||
552 | * |
||
553 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L238-L242 |
||
554 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L1717-L1753 |
||
555 | * @return void |
||
556 | */ |
||
557 | public function record_cancel_subscription() { |
||
558 | |||
559 | } |
||
560 | |||
561 | /** |
||
562 | * Process signup form. |
||
563 | * |
||
564 | * Gets called when the signup form is posted used for running any payment |
||
565 | * method specific actions when processing the customer signup form. |
||
566 | * |
||
567 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L244-L247 |
||
568 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L1755-L1764 |
||
569 | * @param MeprTransaction $txn MemberPress transaction object. |
||
570 | * @return void |
||
571 | */ |
||
572 | public function process_signup_form( $txn ) { |
||
573 | |||
574 | } |
||
575 | |||
576 | /** |
||
577 | * Display payment page. |
||
578 | * |
||
579 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L249-L253 |
||
580 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L1766-L1768 |
||
581 | * @param MeprTransaction $txn MemberPress transaction object. |
||
582 | * @return void |
||
583 | * @throws \Exception Throws exception on gateway payment start error. |
||
584 | */ |
||
585 | public function display_payment_page( $txn ) { |
||
586 | |||
587 | } |
||
588 | |||
589 | /** |
||
590 | * Enqueue payment form scripts. |
||
591 | * |
||
592 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprBaseGateway.php#L255-L258 |
||
593 | * @return void |
||
594 | */ |
||
595 | public function enqueue_payment_form_scripts() { |
||
596 | |||
597 | } |
||
598 | |||
599 | /** |
||
600 | * Display payment form. |
||
601 | * |
||
602 | * This spits out html for the payment form on the registration / payment |
||
603 | * page for the user to fill out for payment. |
||
604 | * |
||
605 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/controllers/MeprCheckoutCtrl.php#L571 |
||
606 | * @param float $amount Transaction amount to create a payment form for. |
||
607 | * @param MeprUser $user MemberPress user object. |
||
608 | * @param int $product_id Product ID. |
||
609 | * @param int $txn_id Transaction ID. |
||
610 | * @return void |
||
611 | */ |
||
612 | public function display_payment_form( $amount, $user, $product_id, $txn_id ) { |
||
613 | // Gateway. |
||
614 | $config_id = $this->get_config_id(); |
||
615 | |||
616 | $gateway = Plugin::get_gateway( $config_id ); |
||
617 | |||
618 | if ( null === $gateway ) { |
||
619 | |||
620 | $admin_message = null; |
||
621 | |||
622 | if ( \current_user_can( 'manage_options' ) ) { |
||
623 | $admin_message = __( 'For admins only: check payment method settings in MemberPress.', 'pronamic_ideal' ); |
||
624 | } |
||
625 | |||
626 | printf( |
||
627 | '<div class="mp_wrapper mp_payment_form_wrapper"><ul><li>%s</li>%s</ul></div>', |
||
628 | \esc_html( Plugin::get_default_error_message() ), |
||
629 | null === $admin_message ? '' : sprintf( '<li><em>%s</em></li>', \esc_html( $admin_message ) ) |
||
630 | ); |
||
631 | |||
632 | return; |
||
633 | } |
||
634 | |||
635 | // Invoice. |
||
636 | $product = new MeprProduct( $product_id ); |
||
637 | |||
638 | $coupon = false; |
||
639 | |||
640 | $txn = new MeprTransaction( $txn_id ); |
||
641 | |||
642 | // Artificially set the price of the $prd in case a coupon was used. |
||
643 | if ( $product->price !== $amount ) { |
||
644 | $coupon = true; |
||
645 | $product->price = $amount; |
||
646 | } |
||
647 | |||
648 | $invoice = MeprTransactionsHelper::get_invoice( $txn ); |
||
649 | |||
650 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
651 | echo $invoice; |
||
652 | |||
653 | ?> |
||
654 | <div class="mp_wrapper mp_payment_form_wrapper"> |
||
655 | <form action="" method="post" id="payment-form" class="mepr-form" novalidate> |
||
656 | <input type="hidden" name="mepr_process_payment_form" value="Y"/> |
||
657 | <input type="hidden" name="mepr_transaction_id" value="<?php echo \esc_attr( (string) $txn_id ); ?>"/> |
||
658 | <input type="hidden" name="pronamic_pay_memberpress_pay" value="1"/> |
||
659 | |||
660 | <div class="mepr_spacer"> </div> |
||
661 | |||
662 | <?php |
||
663 | |||
664 | $gateway->set_payment_method( $this->payment_method ); |
||
665 | |||
666 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
667 | echo $gateway->get_input_html(); |
||
668 | |||
669 | ?> |
||
670 | |||
671 | <div class="mepr_spacer"> </div> |
||
672 | |||
673 | <input type="submit" class="mepr-submit" value="<?php esc_attr_e( 'Pay', 'pronamic_ideal' ); ?>"/> |
||
674 | <img src="<?php echo \esc_url( admin_url( 'images/loading.gif' ) ); ?>" style="display: none;" class="mepr-loading-gif"/> |
||
675 | <?php MeprView::render( '/shared/has_errors', get_defined_vars() ); ?> |
||
676 | |||
677 | <noscript> |
||
678 | <p class="mepr_nojs"> |
||
679 | <?php esc_html_e( 'JavaScript is disabled in your browser. You will not be able to complete your purchase until you either enable JavaScript in your browser, or switch to a browser that supports it.', 'pronamic_ideal' ); ?> |
||
680 | </p> |
||
681 | </noscript> |
||
682 | </form> |
||
683 | </div> |
||
684 | <?php |
||
685 | } |
||
686 | |||
687 | /** |
||
688 | * Single-page checkout payment fields. |
||
689 | * |
||
690 | * @return string |
||
691 | */ |
||
692 | public function spc_payment_fields() { |
||
693 | // Gateway. |
||
694 | $config_id = $this->get_config_id(); |
||
695 | |||
696 | $gateway = Plugin::get_gateway( $config_id ); |
||
697 | |||
698 | if ( null === $gateway ) { |
||
699 | return ''; |
||
700 | } |
||
701 | |||
702 | // Input HTML. |
||
703 | $gateway->set_payment_method( $this->payment_method ); |
||
704 | |||
705 | $html = $gateway->get_input_html(); |
||
706 | |||
707 | if ( empty( $html ) ) { |
||
708 | return ''; |
||
709 | } |
||
710 | |||
711 | return $html; |
||
712 | } |
||
713 | |||
714 | /** |
||
715 | * Validate payment form. |
||
716 | * |
||
717 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/controllers/MeprCheckoutCtrl.php#L648 |
||
718 | * @param string[] $errors Array with errors. |
||
719 | * @return string[] |
||
720 | */ |
||
721 | public function validate_payment_form( $errors ) { |
||
722 | return $errors; |
||
723 | } |
||
724 | |||
725 | /** |
||
726 | * Display options form. |
||
727 | * |
||
728 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/views/admin/options/gateway.php#L41 |
||
729 | * @return void |
||
730 | */ |
||
731 | public function display_options_form() { |
||
732 | $mepr_options = MeprOptions::fetch(); |
||
733 | |||
734 | ?> |
||
735 | <table> |
||
736 | <tr> |
||
737 | <?php |
||
738 | |||
739 | $name = sprintf( |
||
740 | '%s[%s][%s]', |
||
741 | $mepr_options->integrations_str, |
||
742 | $this->id, |
||
743 | 'config_id' |
||
744 | ); |
||
745 | |||
746 | ?> |
||
747 | <td> |
||
748 | <?php esc_html_e( 'Configuration', 'pronamic_ideal' ); ?> |
||
749 | </td> |
||
750 | <td> |
||
751 | <select name="<?php echo esc_attr( $name ); ?>"> |
||
752 | <?php |
||
753 | |||
754 | foreach ( Plugin::get_config_select_options( $this->payment_method ) as $value => $label ) { |
||
755 | printf( |
||
756 | '<option value="%s" %s>%s</option>', |
||
757 | esc_attr( $value ), |
||
758 | selected( $value, $this->settings->config_id, false ), |
||
759 | esc_html( $label ) |
||
760 | ); |
||
761 | } |
||
762 | |||
763 | ?> |
||
764 | </select> |
||
765 | </td> |
||
766 | </tr> |
||
767 | </table> |
||
768 | <?php |
||
769 | } |
||
770 | |||
771 | /** |
||
772 | * Validate options form. |
||
773 | * |
||
774 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/models/MeprOptions.php#L468 |
||
775 | * @ilnk https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L2006-L2026 |
||
776 | * @param string[] $errors Array with errors. |
||
777 | * @return string[] |
||
778 | */ |
||
779 | public function validate_options_form( $errors ) { |
||
780 | return $errors; |
||
781 | } |
||
782 | |||
783 | /** |
||
784 | * Enqueue user account scripts. |
||
785 | * |
||
786 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/controllers/MeprAccountCtrl.php#L126 |
||
787 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L2028-L2044 |
||
788 | * @return void |
||
789 | */ |
||
790 | public function enqueue_user_account_scripts() { |
||
791 | |||
792 | } |
||
793 | |||
794 | /** |
||
795 | * Display update account form. |
||
796 | * |
||
797 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/controllers/MeprAccountCtrl.php#L438 |
||
798 | * @param string $sub_id Subscription ID. |
||
799 | * @param string[] $errors Array with errors. |
||
800 | * @param string $message Update message. |
||
801 | * @return void |
||
802 | */ |
||
803 | public function display_update_account_form( $sub_id, $errors = array(), $message = '' ) { |
||
804 | $subscriptions = \get_pronamic_subscriptions_by_source( 'memberpress_subscription', $sub_id ); |
||
805 | |||
806 | $subscriptions = ( null === $subscriptions ) ? array() : $subscriptions; |
||
0 ignored issues
–
show
|
|||
807 | |||
808 | $subscription = \reset( $subscriptions ); |
||
809 | |||
810 | $message = \__( 'The payment method for this subscription can not be updated manually.', 'pronamic_ideal' ); |
||
811 | |||
812 | if ( false !== $subscription ) { |
||
813 | // Set URL to mandate selection URL. |
||
814 | $url = $subscription->get_mandate_selection_url(); |
||
815 | |||
816 | // Maybe set URL to subscription renewal, |
||
817 | // to catch up with last failed payment. |
||
818 | $renewal_period = $subscription->get_renewal_period(); |
||
819 | |||
820 | if ( SubscriptionStatus::ACTIVE !== $subscription->get_status() && null !== $renewal_period ) { |
||
821 | $url = $subscription->get_renewal_url(); |
||
822 | } |
||
823 | |||
824 | $message = \sprintf( |
||
825 | /* translators: %s: mandate selection URL anchor */ |
||
826 | \__( 'To update the payment method for this subscription, please visit the %s page.', 'pronamic_ideal' ), |
||
827 | \sprintf( |
||
828 | '<a href="%1$s" title="%2$s">%3$s</a>', |
||
829 | \esc_url( $url ), |
||
830 | \esc_attr( \__( 'payment method update', 'pronamic_ideal' ) ), |
||
831 | \esc_html( \__( 'payment method update', 'pronamic_ideal' ) ) |
||
832 | ) |
||
833 | ); |
||
834 | } |
||
835 | |||
836 | ?> |
||
837 | |||
838 | <h3> |
||
839 | <?php echo \esc_html( __( 'Update payment method', 'pronamic_ideal' ) ); ?> |
||
840 | </h3> |
||
841 | |||
842 | <div> |
||
843 | <?php echo \wp_kses_post( $message ); ?> |
||
844 | </div> |
||
845 | |||
846 | <?php |
||
847 | } |
||
848 | |||
849 | /** |
||
850 | * Validate update account form. |
||
851 | * |
||
852 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprAuthorizeGateway.php#L1182-L1197 |
||
853 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L2100-L2103 |
||
854 | * @param string[] $errors Array with errors. |
||
855 | * @return string[] |
||
856 | */ |
||
857 | public function validate_update_account_form( $errors = array() ) { |
||
858 | return $errors; |
||
859 | } |
||
860 | |||
861 | /** |
||
862 | * Process update account form. |
||
863 | * |
||
864 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/controllers/MeprAccountCtrl.php#L430 |
||
865 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L2105-L2111 |
||
866 | * @param int $sub_id Subscription ID. |
||
867 | * @return void |
||
868 | */ |
||
869 | public function process_update_account_form( $sub_id ) { |
||
870 | |||
871 | } |
||
872 | |||
873 | /** |
||
874 | * Is test mode. |
||
875 | * |
||
876 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L374-375 |
||
877 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L2113-L2121 |
||
878 | * @return boolean |
||
879 | */ |
||
880 | public function is_test_mode() { |
||
881 | return false; |
||
882 | } |
||
883 | |||
884 | /** |
||
885 | * Force SSL. |
||
886 | * |
||
887 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L377-378 |
||
888 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L2123-L2125 |
||
889 | * @return boolean |
||
890 | */ |
||
891 | public function force_ssl() { |
||
892 | return false; |
||
893 | } |
||
894 | |||
895 | /** |
||
896 | * Get config ID. |
||
897 | * |
||
898 | * @return int|null |
||
899 | */ |
||
900 | protected function get_config_id() { |
||
901 | // Get config ID setting. |
||
902 | $config_id = $this->settings->config_id; |
||
903 | |||
904 | // Check empty config ID. |
||
905 | if ( empty( $config_id ) ) { |
||
906 | $config_id = \get_option( 'pronamic_pay_config_id' ); |
||
907 | } |
||
908 | |||
909 | // Check empty config ID. |
||
910 | if ( empty( $config_id ) ) { |
||
911 | $config_id = null; |
||
912 | } |
||
913 | |||
914 | return (int) $config_id; |
||
915 | } |
||
916 | } |
||
917 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths