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