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