@@ -47,21 +47,21 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function __construct() { |
| 49 | 49 | // @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprGatewayFactory.php#L48-50 |
| 50 | - add_filter( 'mepr-gateway-paths', array( $this, 'gateway_paths' ) ); |
|
| 50 | + add_filter('mepr-gateway-paths', array($this, 'gateway_paths')); |
|
| 51 | 51 | |
| 52 | - add_filter( 'pronamic_payment_redirect_url_' . self::SLUG, array( __CLASS__, 'redirect_url' ), 10, 2 ); |
|
| 53 | - add_action( 'pronamic_payment_status_update_' . self::SLUG, array( __CLASS__, 'status_update' ), 10, 1 ); |
|
| 52 | + add_filter('pronamic_payment_redirect_url_' . self::SLUG, array(__CLASS__, 'redirect_url'), 10, 2); |
|
| 53 | + add_action('pronamic_payment_status_update_' . self::SLUG, array(__CLASS__, 'status_update'), 10, 1); |
|
| 54 | 54 | |
| 55 | - add_filter( 'pronamic_payment_source_text_' . self::SLUG, array( __CLASS__, 'source_text' ), 10, 2 ); |
|
| 56 | - add_filter( 'pronamic_payment_source_description_' . self::SLUG, array( __CLASS__, 'source_description' ), 10, 2 ); |
|
| 57 | - add_filter( 'pronamic_payment_source_url_' . self::SLUG, array( __CLASS__, 'source_url' ), 10, 2 ); |
|
| 58 | - add_filter( 'pronamic_subscription_source_text_' . self::SLUG, array( __CLASS__, 'subscription_source_text' ), 10, 2 ); |
|
| 59 | - add_filter( 'pronamic_subscription_source_description_' . self::SLUG, array( __CLASS__, 'subscription_source_description' ), 10, 2 ); |
|
| 60 | - add_filter( 'pronamic_subscription_source_url_' . self::SLUG, array( __CLASS__, 'subscription_source_url' ), 10, 2 ); |
|
| 55 | + add_filter('pronamic_payment_source_text_' . self::SLUG, array(__CLASS__, 'source_text'), 10, 2); |
|
| 56 | + add_filter('pronamic_payment_source_description_' . self::SLUG, array(__CLASS__, 'source_description'), 10, 2); |
|
| 57 | + add_filter('pronamic_payment_source_url_' . self::SLUG, array(__CLASS__, 'source_url'), 10, 2); |
|
| 58 | + add_filter('pronamic_subscription_source_text_' . self::SLUG, array(__CLASS__, 'subscription_source_text'), 10, 2); |
|
| 59 | + add_filter('pronamic_subscription_source_description_' . self::SLUG, array(__CLASS__, 'subscription_source_description'), 10, 2); |
|
| 60 | + add_filter('pronamic_subscription_source_url_' . self::SLUG, array(__CLASS__, 'subscription_source_url'), 10, 2); |
|
| 61 | 61 | |
| 62 | - add_action( 'mepr_subscription_pre_delete', array( $this, 'subscription_pre_delete' ), 10, 1 ); |
|
| 62 | + add_action('mepr_subscription_pre_delete', array($this, 'subscription_pre_delete'), 10, 1); |
|
| 63 | 63 | |
| 64 | - add_action( 'mepr_subscription_transition_status', array( $this, 'memberpress_subscription_transition_status' ), 10, 3 ); |
|
| 64 | + add_action('mepr_subscription_transition_status', array($this, 'memberpress_subscription_transition_status'), 10, 3); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | * @param array $paths Array with gateway paths. |
| 73 | 73 | * @return array |
| 74 | 74 | */ |
| 75 | - public function gateway_paths( $paths ) { |
|
| 76 | - $paths[] = dirname( __FILE__ ) . '/../gateways/'; |
|
| 75 | + public function gateway_paths($paths) { |
|
| 76 | + $paths[] = dirname(__FILE__) . '/../gateways/'; |
|
| 77 | 77 | |
| 78 | 78 | return $paths; |
| 79 | 79 | } |
@@ -88,14 +88,14 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return string |
| 90 | 90 | */ |
| 91 | - public static function redirect_url( $url, Payment $payment ) { |
|
| 91 | + public static function redirect_url($url, Payment $payment) { |
|
| 92 | 92 | global $transaction; |
| 93 | 93 | |
| 94 | 94 | $transaction_id = $payment->get_source_id(); |
| 95 | 95 | |
| 96 | - $transaction = new MeprTransaction( $transaction_id ); |
|
| 96 | + $transaction = new MeprTransaction($transaction_id); |
|
| 97 | 97 | |
| 98 | - switch ( $payment->get_status() ) { |
|
| 98 | + switch ($payment->get_status()) { |
|
| 99 | 99 | case Statuses::CANCELLED: |
| 100 | 100 | case Statuses::EXPIRED: |
| 101 | 101 | case Statuses::FAILURE: |
@@ -106,9 +106,9 @@ discard block |
||
| 106 | 106 | 'action' => 'payment_form', |
| 107 | 107 | 'txn' => $transaction->trans_num, |
| 108 | 108 | 'errors' => array( |
| 109 | - __( 'Payment failed. Please try again.', 'pronamic_ideal' ), |
|
| 109 | + __('Payment failed. Please try again.', 'pronamic_ideal'), |
|
| 110 | 110 | ), |
| 111 | - '_wpnonce' => wp_create_nonce( 'mepr_payment_form' ), |
|
| 111 | + '_wpnonce' => wp_create_nonce('mepr_payment_form'), |
|
| 112 | 112 | ), |
| 113 | 113 | $product->url() |
| 114 | 114 | ); |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | // @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/models/MeprOptions.php#L768-782 |
| 119 | 119 | $mepr_options = MeprOptions::fetch(); |
| 120 | 120 | |
| 121 | - $product = new MeprProduct( $transaction->product_id ); |
|
| 122 | - $sanitized_title = sanitize_title( $product->post_title ); |
|
| 121 | + $product = new MeprProduct($transaction->product_id); |
|
| 122 | + $sanitized_title = sanitize_title($product->post_title); |
|
| 123 | 123 | |
| 124 | 124 | $args = array( |
| 125 | 125 | 'membership_id' => $product->ID, |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | 'trans_num' => $transaction->trans_num, |
| 128 | 128 | ); |
| 129 | 129 | |
| 130 | - $url = $mepr_options->thankyou_page_url( http_build_query( $args ) ); |
|
| 130 | + $url = $mepr_options->thankyou_page_url(http_build_query($args)); |
|
| 131 | 131 | |
| 132 | 132 | break; |
| 133 | 133 | case Statuses::OPEN: |
@@ -145,26 +145,26 @@ discard block |
||
| 145 | 145 | * |
| 146 | 146 | * @param Payment $payment The payment whose status is updated. |
| 147 | 147 | */ |
| 148 | - public static function status_update( Payment $payment ) { |
|
| 148 | + public static function status_update(Payment $payment) { |
|
| 149 | 149 | $transaction_id = $payment->get_source_id(); |
| 150 | 150 | |
| 151 | - $transaction = new MeprTransaction( $transaction_id ); |
|
| 151 | + $transaction = new MeprTransaction($transaction_id); |
|
| 152 | 152 | |
| 153 | - if ( $payment->get_recurring() ) { |
|
| 153 | + if ($payment->get_recurring()) { |
|
| 154 | 154 | $subscription = $transaction->subscription(); |
| 155 | 155 | |
| 156 | - if ( empty( $subscription ) || empty( $subscription->id ) ) { |
|
| 156 | + if (empty($subscription) || empty($subscription->id)) { |
|
| 157 | 157 | $subscription_id = $payment->get_subscription()->get_source_id(); |
| 158 | 158 | |
| 159 | - $subscription = new MeprSubscription( $subscription_id ); |
|
| 159 | + $subscription = new MeprSubscription($subscription_id); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // Same source ID and first transaction ID for recurring payment means we need to add a new transaction. |
| 163 | - if ( $payment->get_source_id() === $subscription->id ) { |
|
| 163 | + if ($payment->get_source_id() === $subscription->id) { |
|
| 164 | 164 | // First transaction. |
| 165 | 165 | $first_txn = $subscription->first_txn(); |
| 166 | 166 | |
| 167 | - if ( false === $first_txn || ! ( $first_txn instanceof MeprTransaction ) ) { |
|
| 167 | + if (false === $first_txn || ! ($first_txn instanceof MeprTransaction)) { |
|
| 168 | 168 | $first_txn = new MeprTransaction(); |
| 169 | 169 | $first_txn->user_id = $subscription->user_id; |
| 170 | 170 | $first_txn->product_id = $subscription->product_id; |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | // Transaction number. |
| 176 | 176 | $trans_num = $payment->get_transaction_id(); |
| 177 | 177 | |
| 178 | - if ( empty( $trans_num ) ) { |
|
| 178 | + if (empty($trans_num)) { |
|
| 179 | 179 | $trans_num = uniqid(); |
| 180 | 180 | } |
| 181 | 181 | |
@@ -191,16 +191,16 @@ discard block |
||
| 191 | 191 | $transaction->status = MeprTransaction::$pending_str; |
| 192 | 192 | $transaction->subscription_id = $subscription->id; |
| 193 | 193 | |
| 194 | - $transaction->set_gross( $payment->get_total_amount()->get_amount() ); |
|
| 194 | + $transaction->set_gross($payment->get_total_amount()->get_amount()); |
|
| 195 | 195 | |
| 196 | 196 | $transaction->store(); |
| 197 | 197 | |
| 198 | 198 | // Set source ID. |
| 199 | - $payment->set_meta( 'source_id', $transaction->id ); |
|
| 199 | + $payment->set_meta('source_id', $transaction->id); |
|
| 200 | 200 | |
| 201 | 201 | $payment->source_id = $transaction->id; |
| 202 | 202 | |
| 203 | - if ( MeprSubscription::$active_str === $subscription->status ) { |
|
| 203 | + if (MeprSubscription::$active_str === $subscription->status) { |
|
| 204 | 204 | /* |
| 205 | 205 | * We create a 'confirmed' 'subscription_confirmation' |
| 206 | 206 | * transaction for a grace period of 15 days. |
@@ -222,9 +222,9 @@ discard block |
||
| 222 | 222 | $subscription_confirmation->txn_type = MeprTransaction::$subscription_confirmation_str; |
| 223 | 223 | $subscription_confirmation->status = MeprTransaction::$confirmed_str; |
| 224 | 224 | $subscription_confirmation->subscription_id = $subscription->id; |
| 225 | - $subscription_confirmation->expires_at = MeprUtils::ts_to_mysql_date( strtotime( $payment->post->post_date_gmt ) + MeprUtils::days( 15 ), 'Y-m-d 23:59:59' ); |
|
| 225 | + $subscription_confirmation->expires_at = MeprUtils::ts_to_mysql_date(strtotime($payment->post->post_date_gmt) + MeprUtils::days(15), 'Y-m-d 23:59:59'); |
|
| 226 | 226 | |
| 227 | - $subscription_confirmation->set_subtotal( 0.00 ); |
|
| 227 | + $subscription_confirmation->set_subtotal(0.00); |
|
| 228 | 228 | |
| 229 | 229 | $subscription_confirmation->store(); |
| 230 | 230 | } |
@@ -239,12 +239,12 @@ discard block |
||
| 239 | 239 | ) |
| 240 | 240 | ); |
| 241 | 241 | |
| 242 | - if ( $should_update ) { |
|
| 242 | + if ($should_update) { |
|
| 243 | 243 | $gateway = new Gateway(); |
| 244 | 244 | |
| 245 | 245 | $gateway->mp_txn = $transaction; |
| 246 | 246 | |
| 247 | - switch ( $payment->get_status() ) { |
|
| 247 | + switch ($payment->get_status()) { |
|
| 248 | 248 | case Statuses::CANCELLED: |
| 249 | 249 | case Statuses::EXPIRED: |
| 250 | 250 | case Statuses::FAILURE: |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | break; |
| 254 | 254 | case Statuses::SUCCESS: |
| 255 | - if ( $payment->get_recurring() ) { |
|
| 255 | + if ($payment->get_recurring()) { |
|
| 256 | 256 | $gateway->record_subscription_payment(); |
| 257 | 257 | } else { |
| 258 | 258 | $gateway->record_payment(); |
@@ -271,25 +271,25 @@ discard block |
||
| 271 | 271 | * |
| 272 | 272 | * @param int $subscription_id MemberPress subscription id. |
| 273 | 273 | */ |
| 274 | - public function subscription_pre_delete( $subscription_id ) { |
|
| 275 | - $subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $subscription_id ); |
|
| 274 | + public function subscription_pre_delete($subscription_id) { |
|
| 275 | + $subscription = get_pronamic_subscription_by_meta('_pronamic_subscription_source_id', $subscription_id); |
|
| 276 | 276 | |
| 277 | - if ( ! $subscription ) { |
|
| 277 | + if ( ! $subscription) { |
|
| 278 | 278 | return; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // Add note. |
| 282 | 282 | $note = sprintf( |
| 283 | 283 | /* translators: %s: MemberPress */ |
| 284 | - __( '%s subscription deleted.', 'pronamic_ideal' ), |
|
| 285 | - __( 'MemberPress', 'pronamic_ideal' ) |
|
| 284 | + __('%s subscription deleted.', 'pronamic_ideal'), |
|
| 285 | + __('MemberPress', 'pronamic_ideal') |
|
| 286 | 286 | ); |
| 287 | 287 | |
| 288 | - $subscription->add_note( $note ); |
|
| 288 | + $subscription->add_note($note); |
|
| 289 | 289 | |
| 290 | 290 | // The status of canceled or completed subscriptions will not be changed automatically. |
| 291 | - if ( ! in_array( $subscription->get_status(), array( Statuses::CANCELLED, Statuses::COMPLETED ), true ) ) { |
|
| 292 | - $subscription->set_status( Statuses::CANCELLED ); |
|
| 291 | + if ( ! in_array($subscription->get_status(), array(Statuses::CANCELLED, Statuses::COMPLETED), true)) { |
|
| 292 | + $subscription->set_status(Statuses::CANCELLED); |
|
| 293 | 293 | |
| 294 | 294 | $subscription->save(); |
| 295 | 295 | } |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | * |
| 304 | 304 | * @return string |
| 305 | 305 | */ |
| 306 | - public static function source_text( $text, Payment $payment ) { |
|
| 307 | - $text = __( 'MemberPress', 'pronamic_ideal' ) . '<br />'; |
|
| 306 | + public static function source_text($text, Payment $payment) { |
|
| 307 | + $text = __('MemberPress', 'pronamic_ideal') . '<br />'; |
|
| 308 | 308 | |
| 309 | 309 | $text .= sprintf( |
| 310 | 310 | '<a href="%s">%s</a>', |
@@ -314,10 +314,10 @@ discard block |
||
| 314 | 314 | 'action' => 'edit', |
| 315 | 315 | 'id' => $payment->source_id, |
| 316 | 316 | ), |
| 317 | - admin_url( 'admin.php' ) |
|
| 317 | + admin_url('admin.php') |
|
| 318 | 318 | ), |
| 319 | 319 | /* translators: %s: payment source id */ |
| 320 | - sprintf( __( 'Transaction %s', 'pronamic_ideal' ), $payment->source_id ) |
|
| 320 | + sprintf(__('Transaction %s', 'pronamic_ideal'), $payment->source_id) |
|
| 321 | 321 | ); |
| 322 | 322 | |
| 323 | 323 | return $text; |
@@ -331,8 +331,8 @@ discard block |
||
| 331 | 331 | * |
| 332 | 332 | * @return string |
| 333 | 333 | */ |
| 334 | - public static function subscription_source_text( $text, Subscription $subscription ) { |
|
| 335 | - $text = __( 'MemberPress', 'pronamic_ideal' ) . '<br />'; |
|
| 334 | + public static function subscription_source_text($text, Subscription $subscription) { |
|
| 335 | + $text = __('MemberPress', 'pronamic_ideal') . '<br />'; |
|
| 336 | 336 | |
| 337 | 337 | $text .= sprintf( |
| 338 | 338 | '<a href="%s">%s</a>', |
@@ -341,10 +341,10 @@ discard block |
||
| 341 | 341 | 'page' => 'memberpress-subscriptions', |
| 342 | 342 | 'subscription' => $subscription->source_id, |
| 343 | 343 | ), |
| 344 | - admin_url( 'admin.php' ) |
|
| 344 | + admin_url('admin.php') |
|
| 345 | 345 | ), |
| 346 | 346 | /* translators: %s: payment source id */ |
| 347 | - sprintf( __( 'Subscription %s', 'pronamic_ideal' ), $subscription->source_id ) |
|
| 347 | + sprintf(__('Subscription %s', 'pronamic_ideal'), $subscription->source_id) |
|
| 348 | 348 | ); |
| 349 | 349 | |
| 350 | 350 | return $text; |
@@ -358,8 +358,8 @@ discard block |
||
| 358 | 358 | * |
| 359 | 359 | * @return string |
| 360 | 360 | */ |
| 361 | - public static function source_description( $description, Payment $payment ) { |
|
| 362 | - return __( 'MemberPress Transaction', 'pronamic_ideal' ); |
|
| 361 | + public static function source_description($description, Payment $payment) { |
|
| 362 | + return __('MemberPress Transaction', 'pronamic_ideal'); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -370,8 +370,8 @@ discard block |
||
| 370 | 370 | * |
| 371 | 371 | * @return string |
| 372 | 372 | */ |
| 373 | - public static function subscription_source_description( $description, Subscription $subscription ) { |
|
| 374 | - return __( 'MemberPress Subscription', 'pronamic_ideal' ); |
|
| 373 | + public static function subscription_source_description($description, Subscription $subscription) { |
|
| 374 | + return __('MemberPress Subscription', 'pronamic_ideal'); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -382,14 +382,14 @@ discard block |
||
| 382 | 382 | * |
| 383 | 383 | * @return string |
| 384 | 384 | */ |
| 385 | - public static function source_url( $url, Payment $payment ) { |
|
| 385 | + public static function source_url($url, Payment $payment) { |
|
| 386 | 386 | $url = add_query_arg( |
| 387 | 387 | array( |
| 388 | 388 | 'page' => 'memberpress-trans', |
| 389 | 389 | 'action' => 'edit', |
| 390 | 390 | 'id' => $payment->source_id, |
| 391 | 391 | ), |
| 392 | - admin_url( 'admin.php' ) |
|
| 392 | + admin_url('admin.php') |
|
| 393 | 393 | ); |
| 394 | 394 | |
| 395 | 395 | return $url; |
@@ -403,13 +403,13 @@ discard block |
||
| 403 | 403 | * |
| 404 | 404 | * @return string |
| 405 | 405 | */ |
| 406 | - public static function subscription_source_url( $url, Subscription $subscription ) { |
|
| 406 | + public static function subscription_source_url($url, Subscription $subscription) { |
|
| 407 | 407 | $url = add_query_arg( |
| 408 | 408 | array( |
| 409 | 409 | 'page' => 'memberpress-subscriptions', |
| 410 | 410 | 'subscription' => $subscription->source_id, |
| 411 | 411 | ), |
| 412 | - admin_url( 'admin.php' ) |
|
| 412 | + admin_url('admin.php') |
|
| 413 | 413 | ); |
| 414 | 414 | |
| 415 | 415 | return $url; |
@@ -426,16 +426,16 @@ discard block |
||
| 426 | 426 | * @param string $status_new New status identifier. |
| 427 | 427 | * @param MeprSubscription $memberpress_subscription MemberPress subscription object. |
| 428 | 428 | */ |
| 429 | - public function memberpress_subscription_transition_status( $status_old, $status_new, $memberpress_subscription ) { |
|
| 430 | - $subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $memberpress_subscription->id ); |
|
| 429 | + public function memberpress_subscription_transition_status($status_old, $status_new, $memberpress_subscription) { |
|
| 430 | + $subscription = get_pronamic_subscription_by_meta('_pronamic_subscription_source_id', $memberpress_subscription->id); |
|
| 431 | 431 | |
| 432 | - if ( empty( $subscription ) ) { |
|
| 432 | + if (empty($subscription)) { |
|
| 433 | 433 | return; |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - $status = SubscriptionStatuses::transform( $status_new ); |
|
| 436 | + $status = SubscriptionStatuses::transform($status_new); |
|
| 437 | 437 | |
| 438 | - $subscription->set_status( $status ); |
|
| 438 | + $subscription->set_status($status); |
|
| 439 | 439 | |
| 440 | 440 | $subscription->save(); |
| 441 | 441 | } |