1 | <?php |
||
2 | /** |
||
3 | * Gateway |
||
4 | * |
||
5 | * @author Pronamic <[email protected]> |
||
6 | * @copyright 2005-2020 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; |
||
14 | use MeprEmailFactory; |
||
15 | use MeprOptions; |
||
16 | use MeprProduct; |
||
17 | use MeprSubscription; |
||
18 | use MeprTransaction; |
||
19 | use MeprTransactionsHelper; |
||
20 | use MeprUser; |
||
21 | use MeprUtils; |
||
22 | use MeprView; |
||
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\Pronamic; |
||
28 | use Pronamic\WordPress\Pay\Subscriptions\SubscriptionStatus; |
||
29 | use ReflectionClass; |
||
30 | |||
31 | /** |
||
32 | * WordPress pay MemberPress gateway |
||
33 | * |
||
34 | * @author Remco Tolsma |
||
35 | * @version 2.1.2 |
||
36 | * @since 1.0.0 |
||
37 | */ |
||
38 | class Gateway extends MeprBaseRealGateway { |
||
39 | /** |
||
40 | * Payment method. |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $payment_method; |
||
45 | |||
46 | /** |
||
47 | * MemberPress transaction. |
||
48 | * |
||
49 | * @var MeprTransaction |
||
50 | */ |
||
51 | public $mp_txn; |
||
52 | |||
53 | /** |
||
54 | * Pronamic payment. |
||
55 | * |
||
56 | * @var Payment |
||
57 | */ |
||
58 | public $pronamic_payment; |
||
59 | |||
60 | /** |
||
61 | * Constructs and initialize iDEAL gateway. |
||
62 | */ |
||
63 | public function __construct() { |
||
64 | // Set the name of this gateway. |
||
65 | // @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L12-13. |
||
66 | $this->name = __( 'Pronamic', 'pronamic_ideal' ); |
||
67 | |||
68 | if ( ! empty( $this->payment_method ) ) { |
||
69 | $this->name = sprintf( |
||
70 | /* translators: %s: payment method name */ |
||
71 | __( 'Pronamic - %s', 'pronamic_ideal' ), |
||
72 | PaymentMethods::get_name( $this->payment_method ) |
||
73 | ); |
||
74 | } |
||
75 | |||
76 | // Set the default settings. |
||
77 | // @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L72-73. |
||
78 | $this->set_defaults(); |
||
79 | |||
80 | // Set the capabilities of this gateway. |
||
81 | // @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L36-37. |
||
82 | $this->capabilities = array(); |
||
83 | |||
84 | // Setup the notification actions for this gateway. |
||
85 | $this->notifiers = array(); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Load the specified settings. |
||
90 | * |
||
91 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L69-70 |
||
92 | * |
||
93 | * @param array $settings MemberPress gateway settings array. |
||
94 | */ |
||
95 | public function load( $settings ) { |
||
96 | $this->settings = (object) $settings; |
||
97 | |||
98 | $this->set_defaults(); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Custom helper function to send transaction notices. |
||
103 | * |
||
104 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/lib/MeprUtils.php#L1333-L1351 |
||
105 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/models/MeprTransaction.php |
||
106 | * |
||
107 | * @param MeprTransaction $transaction MemberPress transaction object. |
||
108 | * @param string $method PHP function name to call. |
||
109 | * |
||
110 | * @return mixed |
||
111 | */ |
||
112 | public function send_transaction_notices( $transaction, $method ) { |
||
113 | $class = 'MeprUtils'; |
||
114 | |||
115 | if ( ! Core_Util::class_method_exists( $class, $method ) ) { |
||
116 | $class = $this; |
||
117 | } |
||
118 | |||
119 | // `send_product_welcome_notices` is called from `send_signup_notices` in newer versions. |
||
120 | if ( 'send_product_welcome_notices' === $method ) { |
||
121 | if ( 'MeprUtils' === $class ) { |
||
122 | return null; |
||
123 | } |
||
124 | |||
125 | if ( ! \method_exists( $class, 'send_product_welcome_notices' ) ) { |
||
126 | return null; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | return call_user_func( array( $class, $method ), $transaction ); |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * Get icon function (this is not a MemberPress function). |
||
135 | * |
||
136 | * @since 1.0.2 |
||
137 | * @return string |
||
138 | */ |
||
139 | protected function get_icon() { |
||
140 | return ''; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Get class alias name. |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public function get_alias() { |
||
149 | return 'MeprPronamicGateway'; |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * Set the default settings. |
||
154 | * |
||
155 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L72-73 |
||
156 | */ |
||
157 | protected function set_defaults() { |
||
158 | if ( ! isset( $this->settings ) ) { |
||
159 | $this->settings = array(); |
||
160 | } |
||
161 | |||
162 | $this->settings = (object) array_merge( |
||
163 | array( |
||
164 | 'gateway' => $this->get_alias(), |
||
165 | 'id' => $this->generate_id(), |
||
166 | 'label' => '', |
||
167 | 'use_label' => true, |
||
168 | 'icon' => $this->get_icon(), |
||
169 | 'use_icon' => true, |
||
170 | 'desc' => '', |
||
171 | 'use_desc' => true, |
||
172 | 'config_id' => '', |
||
173 | 'email' => '', |
||
174 | 'sandbox' => false, |
||
175 | 'debug' => false, |
||
176 | ), |
||
177 | (array) $this->settings |
||
178 | ); |
||
179 | |||
180 | $this->id = $this->settings->id; |
||
181 | $this->label = $this->settings->label; |
||
182 | $this->use_label = $this->settings->use_label; |
||
183 | $this->icon = $this->settings->icon; |
||
184 | $this->use_icon = $this->settings->use_icon; |
||
185 | $this->desc = $this->settings->desc; |
||
186 | $this->use_desc = $this->settings->use_desc; |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * Process payment. |
||
191 | * |
||
192 | * @param MeprTransaction $txn MemberPress transaction object. |
||
193 | * |
||
194 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L119-122 |
||
195 | */ |
||
196 | public function process_payment( $txn ) { |
||
197 | |||
198 | } |
||
199 | |||
200 | /** |
||
201 | * Record subscription payment. |
||
202 | * |
||
203 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L140-145 |
||
204 | */ |
||
205 | public function record_subscription_payment() { |
||
206 | $transaction = $this->mp_txn; |
||
207 | |||
208 | $transaction->status = MeprTransaction::$complete_str; |
||
209 | $transaction->expires_at = MeprUtils::ts_to_mysql_date( $this->pronamic_payment->get_end_date()->getTimestamp(), 'Y-m-d 23:59:59' ); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
210 | $transaction->store(); |
||
211 | |||
212 | $subscription = $transaction->subscription(); |
||
213 | |||
214 | if ( $subscription ) { |
||
215 | $should_activate = ! \in_array( |
||
216 | $subscription->status, |
||
217 | array( |
||
218 | MeprSubscription::$active_str, |
||
219 | MeprSubscription::$cancelled_str, |
||
220 | ), |
||
221 | true |
||
222 | ); |
||
223 | |||
224 | if ( $should_activate ) { |
||
225 | $subscription->status = MeprSubscription::$active_str; |
||
226 | $subscription->store(); |
||
227 | } |
||
228 | |||
229 | $subscription->expire_confirmation_txn(); |
||
230 | |||
231 | $subscription->limit_payment_cycles(); |
||
232 | } |
||
233 | |||
234 | $this->send_transaction_notices( $transaction, 'send_transaction_receipt_notices' ); |
||
235 | |||
236 | return $transaction; |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * Record payment failure. |
||
241 | * |
||
242 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L147-148 |
||
243 | */ |
||
244 | public function record_payment_failure() { |
||
245 | $transaction = $this->mp_txn; |
||
246 | |||
247 | // @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/models/MeprTransaction.php#L50. |
||
248 | $transaction->status = MeprTransaction::$failed_str; |
||
249 | $transaction->store(); |
||
250 | |||
251 | // Expire associated subscription transactions for non-recurring payments. |
||
252 | if ( ! ( isset( $this->pronamic_payment ) && $this->pronamic_payment->get_recurring() ) ) { |
||
0 ignored issues
–
show
The expression
$this->pronamic_payment->get_recurring() of type boolean|null is loosely compared to false ; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.
If an expression can have both $a = canBeFalseAndNull();
// Instead of
if ( ! $a) { }
// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
![]() |
|||
253 | $subscription = $transaction->subscription(); |
||
254 | |||
255 | if ( $subscription ) { |
||
256 | $subscription->expire_txns(); |
||
257 | $subscription->store(); |
||
258 | } |
||
259 | } |
||
260 | |||
261 | $this->send_transaction_notices( $transaction, 'send_failed_txn_notices' ); |
||
262 | |||
263 | return $transaction; |
||
264 | } |
||
265 | |||
266 | /** |
||
267 | * Record payment. |
||
268 | * |
||
269 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L124-129 |
||
270 | */ |
||
271 | public function record_payment() { |
||
272 | $transaction = $this->mp_txn; |
||
273 | |||
274 | $transaction->status = MeprTransaction::$complete_str; |
||
275 | |||
276 | // This will only work before maybe_cancel_old_sub is run. |
||
277 | $upgrade = $transaction->is_upgrade(); |
||
278 | $downgrade = $transaction->is_downgrade(); |
||
279 | |||
280 | $event_transaction = $transaction->maybe_cancel_old_sub(); |
||
0 ignored issues
–
show
Are you sure the assignment to
$event_transaction is correct as $transaction->maybe_cancel_old_sub() targeting MeprTransaction::maybe_cancel_old_sub() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
281 | |||
282 | $subscription = $transaction->subscription(); |
||
283 | |||
284 | if ( $subscription ) { |
||
285 | $event_subscription = $subscription->maybe_cancel_old_sub(); |
||
0 ignored issues
–
show
Are you sure the assignment to
$event_subscription is correct as $subscription->maybe_cancel_old_sub() targeting MeprSubscription::maybe_cancel_old_sub() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
286 | |||
287 | $subscription->status = MeprSubscription::$active_str; |
||
288 | $subscription->created_at = $transaction->created_at; |
||
289 | $subscription->store(); |
||
290 | |||
291 | if ( false === $event_transaction && false !== $event_subscription ) { |
||
292 | $event_transaction = $event_subscription; |
||
293 | } |
||
294 | } |
||
295 | |||
296 | $transaction->store(); |
||
297 | |||
298 | /* |
||
299 | * For some reasons the `send_product_welcome_notices` function accepts 1 or 3 arguments. We are not sure |
||
300 | * if this is a difference in the 'Business' and 'Developer' edition or between version `1.2.4` and `1.2.7`. |
||
301 | * |
||
302 | * @link https://github.com/wp-premium/memberpress-developer/blob/1.2.4/app/lib/MeprBaseGateway.php#L596-L612 |
||
303 | * @link https://github.com/wp-premium/memberpress-business/blob/1.2.7/app/lib/MeprBaseGateway.php#L609-L619 |
||
304 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/models/MeprTransaction.php#L51 |
||
305 | */ |
||
306 | $reflection = new ReflectionClass( 'MeprBaseRealGateway' ); |
||
307 | |||
308 | if ( $reflection->hasMethod( 'send_product_welcome_notices' ) && 3 === $reflection->getMethod( 'send_product_welcome_notices' )->getNumberOfParameters() ) { |
||
309 | $uemail = MeprEmailFactory::fetch( |
||
310 | 'MeprUserProductWelcomeEmail', |
||
311 | 'MeprBaseProductEmail', |
||
312 | array( |
||
313 | array( |
||
314 | 'product_id' => $transaction->product_id, |
||
315 | ), |
||
316 | ) |
||
317 | ); |
||
318 | |||
319 | /** |
||
320 | * The `send_product_welcome_notices` method is only available in earlier version of MemberPress. |
||
321 | * |
||
322 | * @scrutinizer ignore-call |
||
323 | */ |
||
324 | $this->send_product_welcome_notices( |
||
325 | $uemail, |
||
326 | MeprTransactionsHelper::get_email_params( $transaction ), |
||
327 | $transaction->user() |
||
328 | ); |
||
329 | } else { |
||
330 | $this->send_transaction_notices( $transaction, 'send_product_welcome_notices' ); |
||
331 | } |
||
332 | |||
333 | // Send upgrade/downgrade notices. |
||
334 | $product = $transaction->product(); |
||
335 | |||
336 | if ( 'lifetime' === $product->period_type ) { |
||
337 | if ( $upgrade ) { |
||
338 | $this->upgraded_sub( $transaction, $event_transaction ); |
||
339 | $this->send_transaction_notices( $transaction, 'send_upgraded_txn_notices' ); |
||
340 | } elseif ( $downgrade ) { |
||
341 | $this->downgraded_sub( $transaction, $event_transaction ); |
||
342 | $this->send_transaction_notices( $transaction, 'send_downgraded_txn_notices' ); |
||
343 | } else { |
||
344 | $this->new_sub( $transaction ); |
||
345 | } |
||
346 | } |
||
347 | |||
348 | $this->send_transaction_notices( $transaction, 'send_signup_notices' ); |
||
349 | $this->send_transaction_notices( $transaction, 'send_transaction_receipt_notices' ); |
||
350 | |||
351 | return $transaction; |
||
352 | } |
||
353 | |||
354 | /** |
||
355 | * Process refund. |
||
356 | * |
||
357 | * @param MeprTransaction $txn MemberPress transaction object. |
||
358 | * |
||
359 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L131-133 |
||
360 | */ |
||
361 | public function process_refund( MeprTransaction $txn ) { |
||
362 | |||
363 | } |
||
364 | |||
365 | /** |
||
366 | * Record refund. |
||
367 | * |
||
368 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L135-138 |
||
369 | */ |
||
370 | public function record_refund() { |
||
371 | |||
372 | } |
||
373 | |||
374 | /** |
||
375 | * Process trial payment. |
||
376 | * |
||
377 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L150-157 |
||
378 | * |
||
379 | * @param MeprTransaction $transaction MemberPress transaction object. |
||
380 | */ |
||
381 | public function process_trial_payment( $transaction ) { |
||
382 | |||
383 | } |
||
384 | |||
385 | /** |
||
386 | * Reord trial payment. |
||
387 | * |
||
388 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L159-161 |
||
389 | * |
||
390 | * @param MeprTransaction $transaction MemberPress transaction object. |
||
391 | */ |
||
392 | public function record_trial_payment( $transaction ) { |
||
393 | |||
394 | } |
||
395 | |||
396 | /** |
||
397 | * Process create subscription. |
||
398 | * |
||
399 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L163-167 |
||
400 | * |
||
401 | * @param MeprTransaction $txn MemberPress transaction object. |
||
402 | */ |
||
403 | public function process_create_subscription( $txn ) { |
||
404 | |||
405 | } |
||
406 | |||
407 | /** |
||
408 | * Record create subscription. |
||
409 | * |
||
410 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L169-174 |
||
411 | */ |
||
412 | public function record_create_subscription() { |
||
413 | |||
414 | } |
||
415 | |||
416 | /** |
||
417 | * Process update subscription. |
||
418 | * |
||
419 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L176 |
||
420 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/lib/MeprBaseGateway.php#L194 |
||
421 | * |
||
422 | * @param int $sub_id Subscription ID. |
||
423 | */ |
||
424 | public function process_update_subscription( $sub_id ) { |
||
425 | |||
426 | } |
||
427 | |||
428 | /** |
||
429 | * Record update subscription. |
||
430 | * |
||
431 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L178-182 |
||
432 | */ |
||
433 | public function record_update_subscription() { |
||
434 | |||
435 | } |
||
436 | |||
437 | /** |
||
438 | * Process suspend subscription. |
||
439 | * |
||
440 | * @param int $sub_id Subscription id. |
||
441 | * |
||
442 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L184-186 |
||
443 | */ |
||
444 | public function process_suspend_subscription( $sub_id ) { |
||
445 | if ( ! MeprSubscription::exists( $sub_id ) ) { |
||
446 | return; |
||
447 | } |
||
448 | |||
449 | $sub = new MeprSubscription( $sub_id ); |
||
450 | |||
451 | if ( MeprSubscription::$suspended_str === $sub->status ) { |
||
452 | // Subscription is already suspended. |
||
453 | return; |
||
454 | } |
||
455 | |||
456 | $subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $sub->id ); |
||
457 | |||
458 | if ( ! $subscription ) { |
||
459 | return; |
||
460 | } |
||
461 | |||
462 | $sub->status = MeprSubscription::$suspended_str; |
||
463 | |||
464 | $sub->store(); |
||
465 | |||
466 | // Send suspended subscription notices. |
||
467 | MeprUtils::send_suspended_sub_notices( $sub ); |
||
468 | |||
469 | $note = sprintf( |
||
470 | /* translators: %s: extension name */ |
||
471 | __( '%s subscription on hold.', 'pronamic_ideal' ), |
||
472 | __( 'MemberPress', 'pronamic_ideal' ) |
||
473 | ); |
||
474 | |||
475 | $subscription->add_note( $note ); |
||
476 | |||
477 | // The status of canceled or completed subscriptions will not be changed automatically. |
||
478 | if ( ! in_array( $subscription->get_status(), array( SubscriptionStatus::CANCELLED, SubscriptionStatus::COMPLETED ), true ) ) { |
||
479 | $subscription->set_status( SubscriptionStatus::ON_HOLD ); |
||
480 | |||
481 | $subscription->save(); |
||
482 | } |
||
483 | } |
||
484 | |||
485 | /** |
||
486 | * Record suspend subscription. |
||
487 | * |
||
488 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L188-191 |
||
489 | */ |
||
490 | public function record_suspend_subscription() { |
||
491 | |||
492 | } |
||
493 | |||
494 | /** |
||
495 | * Process resume subscription. |
||
496 | * |
||
497 | * @param int $sub_id Subscription id. |
||
498 | * |
||
499 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L193-195 |
||
500 | */ |
||
501 | public function process_resume_subscription( $sub_id ) { |
||
502 | if ( ! MeprSubscription::exists( $sub_id ) ) { |
||
503 | return; |
||
504 | } |
||
505 | |||
506 | $sub = new MeprSubscription( $sub_id ); |
||
507 | |||
508 | if ( MeprSubscription::$active_str === $sub->status ) { |
||
509 | // Subscription is already active. |
||
510 | return; |
||
511 | } |
||
512 | |||
513 | $subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $sub->id ); |
||
514 | |||
515 | if ( ! $subscription ) { |
||
516 | return; |
||
517 | } |
||
518 | |||
519 | $sub->status = MeprSubscription::$active_str; |
||
520 | |||
521 | $sub->store(); |
||
522 | |||
523 | // Check if prior txn is expired yet or not, if so create a temporary txn so the user can access the content immediately. |
||
524 | $prior_txn = $sub->latest_txn(); |
||
525 | |||
526 | if ( false === $prior_txn || ! ( $prior_txn instanceof MeprTransaction ) || strtotime( $prior_txn->expires_at ) < time() ) { |
||
527 | $txn = new MeprTransaction(); |
||
528 | $txn->subscription_id = $sub->id; |
||
529 | $txn->trans_num = $sub->subscr_id . '-' . uniqid(); |
||
530 | $txn->status = MeprTransaction::$confirmed_str; |
||
531 | $txn->txn_type = MeprTransaction::$subscription_confirmation_str; |
||
532 | $txn->response = (string) $sub; |
||
533 | $txn->expires_at = MeprUtils::ts_to_mysql_date( time() + MeprUtils::days( 1 ), 'Y-m-d 23:59:59' ); |
||
534 | |||
535 | $txn->set_subtotal( 0.00 ); // Just a confirmation txn. |
||
536 | |||
537 | $txn->store(); |
||
538 | } |
||
539 | |||
540 | // Send resumed subscription notices. |
||
541 | MeprUtils::send_resumed_sub_notices( $sub ); |
||
542 | |||
543 | // Add note. |
||
544 | $note = sprintf( |
||
545 | /* translators: %s: extension name */ |
||
546 | __( '%s subscription reactivated.', 'pronamic_ideal' ), |
||
547 | __( 'MemberPress', 'pronamic_ideal' ) |
||
548 | ); |
||
549 | |||
550 | $subscription->add_note( $note ); |
||
551 | |||
552 | // The status of canceled or completed subscriptions will not be changed automatically. |
||
553 | if ( ! in_array( $subscription->get_status(), array( SubscriptionStatus::CANCELLED, SubscriptionStatus::COMPLETED ), true ) ) { |
||
554 | $subscription->set_status( SubscriptionStatus::ACTIVE ); |
||
555 | |||
556 | $subscription->save(); |
||
557 | } |
||
558 | } |
||
559 | |||
560 | /** |
||
561 | * Record resume subscription. |
||
562 | * |
||
563 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L197-201 |
||
564 | */ |
||
565 | public function record_resume_subscription() { |
||
566 | |||
567 | } |
||
568 | |||
569 | /** |
||
570 | * Process cancel subscription. |
||
571 | * |
||
572 | * @param int $sub_id Subscription id. |
||
573 | * |
||
574 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L202-206 |
||
575 | */ |
||
576 | public function process_cancel_subscription( $sub_id ) { |
||
577 | if ( ! MeprSubscription::exists( $sub_id ) ) { |
||
578 | return; |
||
579 | } |
||
580 | |||
581 | $sub = new MeprSubscription( $sub_id ); |
||
582 | |||
583 | if ( MeprSubscription::$cancelled_str === $sub->status ) { |
||
584 | // Subscription is already cancelled. |
||
585 | return; |
||
586 | } |
||
587 | |||
588 | $subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $sub->id ); |
||
589 | |||
590 | if ( ! $subscription ) { |
||
591 | return; |
||
592 | } |
||
593 | |||
594 | // Add note. |
||
595 | $note = sprintf( |
||
596 | /* translators: %s: extension name */ |
||
597 | __( '%s subscription cancelled.', 'pronamic_ideal' ), |
||
598 | __( 'MemberPress', 'pronamic_ideal' ) |
||
599 | ); |
||
600 | |||
601 | $subscription->add_note( $note ); |
||
602 | |||
603 | // The status of canceled or completed subscriptions will not be changed automatically. |
||
604 | if ( ! in_array( $subscription->get_status(), array( SubscriptionStatus::CANCELLED, SubscriptionStatus::COMPLETED ), true ) ) { |
||
605 | $subscription->set_status( SubscriptionStatus::CANCELLED ); |
||
606 | |||
607 | $subscription->next_payment_date = null; |
||
608 | $subscription->next_payment_delivery_date = null; |
||
609 | |||
610 | // Delete next payment post meta. |
||
611 | $subscription->set_meta( 'next_payment', null ); |
||
612 | $subscription->set_meta( 'next_payment_delivery_date', null ); |
||
613 | |||
614 | $subscription->save(); |
||
615 | } |
||
616 | |||
617 | // Cancel MemberPress subscription. |
||
618 | $sub->status = MeprSubscription::$cancelled_str; |
||
619 | |||
620 | $sub->store(); |
||
621 | |||
622 | // Expire the grace period (confirmation) if no completed payments have come through. |
||
623 | if ( (int) $sub->txn_count <= 0 ) { |
||
624 | $sub->expire_txns(); |
||
625 | } |
||
626 | |||
627 | $sub->limit_reached_actions(); |
||
628 | |||
629 | // Send cancelled subscription notices. |
||
630 | MeprUtils::send_cancelled_sub_notices( $sub ); |
||
631 | } |
||
632 | |||
633 | /** |
||
634 | * Record cancel subscription. |
||
635 | * |
||
636 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L208-212 |
||
637 | */ |
||
638 | public function record_cancel_subscription() { |
||
639 | |||
640 | } |
||
641 | |||
642 | /** |
||
643 | * Process signup form. |
||
644 | * |
||
645 | * Gets called when the signup form is posted used for running any payment |
||
646 | * method specific actions when processing the customer signup form. |
||
647 | * |
||
648 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L214-217 |
||
649 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/controllers/MeprCheckoutCtrl.php#L262 |
||
650 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/lib/MeprBaseGateway.php#L232-L235 |
||
651 | * |
||
652 | * @param MeprTransaction $txn MemberPress transaction object. |
||
653 | */ |
||
654 | public function process_signup_form( $txn ) { |
||
655 | |||
656 | } |
||
657 | |||
658 | /** |
||
659 | * Payment redirect. |
||
660 | * |
||
661 | * @param MeprTransaction $txn MemberPress transaction object. |
||
662 | * |
||
663 | * @throws \Exception Throws exception on gateway payment start error. |
||
664 | * @since 1.0.2 |
||
665 | */ |
||
666 | public function payment_redirect( $txn ) { |
||
667 | $txn = new MeprTransaction( $txn->id ); |
||
668 | |||
669 | // Gateway. |
||
670 | $config_id = $this->settings->config_id; |
||
671 | |||
672 | $gateway = Plugin::get_gateway( $config_id ); |
||
0 ignored issues
–
show
Are you sure the assignment to
$gateway is correct as Pronamic\WordPress\Pay\P...get_gateway($config_id) targeting Pronamic\WordPress\Pay\Plugin::get_gateway() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
673 | |||
674 | if ( ! $gateway ) { |
||
675 | return; |
||
676 | } |
||
677 | |||
678 | // Create Pronamic payment. |
||
679 | $payment = Pronamic::get_payment( $txn ); |
||
680 | |||
681 | $payment->config_id = $this->settings->config_id; |
||
682 | $payment->method = $this->payment_method; |
||
683 | |||
684 | $error = null; |
||
685 | |||
686 | try { |
||
687 | $payment = Plugin::start_payment( $payment ); |
||
688 | } catch ( \Exception $e ) { |
||
689 | $error = $e; |
||
690 | } |
||
691 | |||
692 | /* |
||
693 | * Update trial transaction. |
||
694 | * |
||
695 | * Notes: |
||
696 | * - MemberPress also uses trial amount for prorated upgrade/downgrade |
||
697 | * - Not updated BEFORE payment start, as transaction total amount is used for subscription amount. |
||
698 | * - Reload transaction to make sure actual status is being used (i.e. on free downgrade). |
||
699 | */ |
||
700 | $txn = new MeprTransaction( $txn->id ); |
||
701 | |||
702 | $subscription = $txn->subscription(); |
||
703 | |||
704 | if ( $subscription && $subscription->in_trial() ) { |
||
705 | $txn->expires_at = MeprUtils::ts_to_mysql_date( $payment->get_end_date()->getTimestamp(), 'Y-m-d 23:59:59' ); |
||
706 | |||
707 | $txn->set_subtotal( $subscription->trial_amount ); |
||
708 | $txn->store(); |
||
709 | } |
||
710 | |||
711 | if ( $error instanceof \Exception ) { |
||
712 | // Rethrow error, catched by MemberPress. |
||
713 | throw $error; |
||
714 | } |
||
715 | |||
716 | // Redirect. |
||
717 | $gateway->redirect( $payment ); |
||
718 | } |
||
719 | |||
720 | /** |
||
721 | * Display payment page. |
||
722 | * |
||
723 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L219-223 |
||
724 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/controllers/MeprCheckoutCtrl.php#L290 |
||
725 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/gateways/MeprPayPalGateway.php#L775-L850 |
||
726 | * |
||
727 | * @param MeprTransaction $txn MemberPress transaction object. |
||
728 | * |
||
729 | * @throws \Exception Throws exception on gateway payment start error. |
||
730 | */ |
||
731 | public function display_payment_page( $txn ) { |
||
732 | // Gateway. |
||
733 | $config_id = $this->settings->config_id; |
||
734 | |||
735 | $gateway = Plugin::get_gateway( $config_id ); |
||
0 ignored issues
–
show
Are you sure the assignment to
$gateway is correct as Pronamic\WordPress\Pay\P...get_gateway($config_id) targeting Pronamic\WordPress\Pay\Plugin::get_gateway() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
736 | |||
737 | if ( $gateway && '' === $gateway->get_input_html() ) { |
||
738 | $this->payment_redirect( $txn ); |
||
739 | } |
||
740 | } |
||
741 | |||
742 | /** |
||
743 | * Process payment form. |
||
744 | * |
||
745 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L239-289 |
||
746 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/controllers/MeprCheckoutCtrl.php#L336 |
||
747 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/gateways/MeprPayPalGateway.php#L1011 |
||
748 | * |
||
749 | * @param MeprTransaction $txn MemberPress transaction object. |
||
750 | * |
||
751 | * @return bool |
||
752 | * @throws \Exception Throws exception on gateway payment start error. |
||
753 | */ |
||
754 | public function process_payment_form( $txn ) { |
||
755 | if ( ! filter_has_var( INPUT_POST, 'pronamic_pay_memberpress_pay' ) ) { |
||
756 | return false; |
||
757 | } |
||
758 | |||
759 | // Gateway. |
||
760 | $config_id = $this->settings->config_id; |
||
761 | |||
762 | $gateway = Plugin::get_gateway( $config_id ); |
||
0 ignored issues
–
show
Are you sure the assignment to
$gateway is correct as Pronamic\WordPress\Pay\P...get_gateway($config_id) targeting Pronamic\WordPress\Pay\Plugin::get_gateway() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
763 | |||
764 | if ( $gateway ) { |
||
765 | $this->payment_redirect( $txn ); |
||
766 | } |
||
767 | } |
||
768 | |||
769 | /** |
||
770 | * Enqueue payment form scripts. |
||
771 | * |
||
772 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L219-223 |
||
773 | */ |
||
774 | public function enqueue_payment_form_scripts() { |
||
775 | |||
776 | } |
||
777 | |||
778 | /** |
||
779 | * Display payment form. |
||
780 | * |
||
781 | * This spits out html for the payment form on the registration / payment |
||
782 | * page for the user to fill out for payment. |
||
783 | * |
||
784 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L230-233 |
||
785 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/lib/MeprBaseGateway.php#L248-L251 |
||
786 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/controllers/MeprCheckoutCtrl.php#L318 |
||
787 | * |
||
788 | * @param float $amount Transaction amount to create a payment form for. |
||
789 | * @param MeprUser $user MemberPress user object. |
||
790 | * @param int $product_id Product ID. |
||
791 | * @param int $txn_id Transaction ID. |
||
792 | */ |
||
793 | public function display_payment_form( $amount, $user, $product_id, $txn_id ) { |
||
794 | $product = new MeprProduct( $product_id ); |
||
795 | |||
796 | $coupon = false; |
||
797 | |||
798 | $txn = new MeprTransaction( $txn_id ); |
||
799 | |||
800 | // Artifically set the price of the $prd in case a coupon was used. |
||
801 | if ( $product->price !== $amount ) { |
||
802 | $coupon = true; |
||
803 | $product->price = $amount; |
||
804 | } |
||
805 | |||
806 | $invoice = MeprTransactionsHelper::get_invoice( $txn ); |
||
807 | |||
808 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
809 | echo $invoice; |
||
810 | |||
811 | ?> |
||
812 | <div class="mp_wrapper mp_payment_form_wrapper"> |
||
813 | <form action="" method="post" id="payment-form" class="mepr-form" novalidate> |
||
814 | <input type="hidden" name="mepr_process_payment_form" value="Y"/> |
||
815 | <input type="hidden" name="mepr_transaction_id" value="<?php echo esc_attr( $txn_id ); ?>"/> |
||
816 | <input type="hidden" name="pronamic_pay_memberpress_pay" value="1"/> |
||
817 | |||
818 | <div class="mepr_spacer"> </div> |
||
819 | |||
820 | <?php |
||
821 | |||
822 | // Gateway. |
||
823 | $config_id = $this->settings->config_id; |
||
824 | |||
825 | $gateway = Plugin::get_gateway( $config_id ); |
||
0 ignored issues
–
show
Are you sure the assignment to
$gateway is correct as Pronamic\WordPress\Pay\P...get_gateway($config_id) targeting Pronamic\WordPress\Pay\Plugin::get_gateway() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
826 | |||
827 | if ( $gateway ) { |
||
828 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
829 | echo $gateway->get_input_html(); |
||
830 | } |
||
831 | |||
832 | ?> |
||
833 | |||
834 | <div class="mepr_spacer"> </div> |
||
835 | |||
836 | <input type="submit" class="mepr-submit" value="<?php esc_attr_e( 'Pay', 'pronamic_ideal' ); ?>"/> |
||
837 | <img src="<?php echo esc_attr( admin_url( 'images/loading.gif' ) ); ?>" style="display: none;" class="mepr-loading-gif"/> |
||
838 | <?php MeprView::render( '/shared/has_errors', get_defined_vars() ); ?> |
||
839 | |||
840 | <noscript> |
||
841 | <p class="mepr_nojs"> |
||
842 | <?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' ); ?> |
||
843 | </p> |
||
844 | </noscript> |
||
845 | </form> |
||
846 | </div> |
||
847 | <?php |
||
848 | } |
||
849 | |||
850 | /** |
||
851 | * Validate payment form. |
||
852 | * |
||
853 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L235-236 |
||
854 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/controllers/MeprCheckoutCtrl.php#L330 |
||
855 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/lib/MeprBaseGateway.php#L253-L254 |
||
856 | * |
||
857 | * @param array $errors Array with errors. |
||
858 | * @return array |
||
859 | */ |
||
860 | public function validate_payment_form( $errors ) { |
||
861 | return $errors; |
||
862 | } |
||
863 | |||
864 | /** |
||
865 | * Display options form. |
||
866 | * |
||
867 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L291-292 |
||
868 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/gateways/MeprAuthorizeGateway.php#L1027-1037 |
||
869 | */ |
||
870 | public function display_options_form() { |
||
871 | $mepr_options = MeprOptions::fetch(); |
||
872 | |||
873 | ?> |
||
874 | <table> |
||
875 | <tr> |
||
876 | <?php |
||
877 | |||
878 | $name = sprintf( |
||
879 | '%s[%s][%s]', |
||
880 | $mepr_options->integrations_str, |
||
881 | $this->id, |
||
882 | 'config_id' |
||
883 | ); |
||
884 | |||
885 | ?> |
||
886 | <td> |
||
887 | <?php esc_html_e( 'Configuration', 'pronamic_ideal' ); ?> |
||
888 | </td> |
||
889 | <td> |
||
890 | <select name="<?php echo esc_attr( $name ); ?>"> |
||
891 | <?php |
||
892 | |||
893 | foreach ( Plugin::get_config_select_options( $this->payment_method ) as $value => $label ) { |
||
894 | printf( |
||
895 | '<option value="%s" %s>%s</option>', |
||
896 | esc_attr( $value ), |
||
897 | selected( $value, $this->settings->config_id, false ), |
||
898 | esc_html( $label ) |
||
899 | ); |
||
900 | } |
||
901 | |||
902 | ?> |
||
903 | </select> |
||
904 | </td> |
||
905 | </tr> |
||
906 | </table> |
||
907 | <?php |
||
908 | } |
||
909 | |||
910 | /** |
||
911 | * Validate options form. |
||
912 | * |
||
913 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L294-295 |
||
914 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/gateways/MeprPayPalGateway.php#L909-L924 |
||
915 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/models/MeprOptions.php#L416-L423 |
||
916 | * |
||
917 | * @param array $errors Array with errors. |
||
918 | * @return array |
||
919 | */ |
||
920 | public function validate_options_form( $errors ) { |
||
921 | return $errors; |
||
922 | } |
||
923 | |||
924 | /** |
||
925 | * Enqueue user account scripts. |
||
926 | * |
||
927 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L297-302 |
||
928 | */ |
||
929 | public function enqueue_user_account_scripts() { |
||
930 | |||
931 | } |
||
932 | |||
933 | /** |
||
934 | * Display update account form. |
||
935 | * |
||
936 | * @param int $sub_id Subscription ID. |
||
937 | * @param array $errors Array with errors. |
||
938 | * @param string $message Update message. |
||
939 | * |
||
940 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L365-366 |
||
941 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/lib/MeprBaseStaticGateway.php#L160-L161 |
||
942 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/gateways/MeprStripeGateway.php#L1108-L1168 |
||
943 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/controllers/MeprAccountCtrl.php#L388 |
||
944 | */ |
||
945 | public function display_update_account_form( $sub_id, $errors = array(), $message = '' ) { |
||
946 | |||
947 | } |
||
948 | |||
949 | /** |
||
950 | * Validate update account form. |
||
951 | * |
||
952 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L368-369 |
||
953 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/gateways/MeprStripeGateway.php#L1170-L1173 |
||
954 | * |
||
955 | * @param array $errors Array with errors. |
||
956 | * @return array |
||
957 | */ |
||
958 | public function validate_update_account_form( $errors = array() ) { |
||
959 | return $errors; |
||
960 | } |
||
961 | |||
962 | /** |
||
963 | * Process update account form. |
||
964 | * |
||
965 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L371-372 |
||
966 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/gateways/MeprStripeGateway.php#L1175-L1181 |
||
967 | * |
||
968 | * @param int $sub_id Subscription ID. |
||
969 | */ |
||
970 | public function process_update_account_form( $sub_id ) { |
||
971 | |||
972 | } |
||
973 | |||
974 | /** |
||
975 | * Is test mode. |
||
976 | * |
||
977 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L374-375 |
||
978 | * |
||
979 | * @return boolean |
||
980 | */ |
||
981 | public function is_test_mode() { |
||
982 | return false; |
||
983 | } |
||
984 | |||
985 | /** |
||
986 | * Force SSL. |
||
987 | * |
||
988 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprBaseGateway.php#L377-378 |
||
989 | * |
||
990 | * @return boolean |
||
991 | */ |
||
992 | public function force_ssl() { |
||
993 | return false; |
||
994 | } |
||
995 | } |
||
996 |