@@ -47,25 +47,25 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function __construct() { |
| 49 | 49 | // @see 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 | - if ( version_compare( MEPR_VERSION, '1.3.36', '<' ) ) { |
|
| 53 | - add_filter( 'mepr_recurring_subscriptions_table_joins', array( $this, 'subscriptions_table_joins_nested_query_fix' ) ); |
|
| 52 | + if (version_compare(MEPR_VERSION, '1.3.36', '<')) { |
|
| 53 | + add_filter('mepr_recurring_subscriptions_table_joins', array($this, 'subscriptions_table_joins_nested_query_fix')); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - add_filter( 'pronamic_payment_redirect_url_' . self::SLUG, array( __CLASS__, 'redirect_url' ), 10, 2 ); |
|
| 57 | - add_action( 'pronamic_payment_status_update_' . self::SLUG, array( __CLASS__, 'status_update' ), 10, 1 ); |
|
| 56 | + add_filter('pronamic_payment_redirect_url_' . self::SLUG, array(__CLASS__, 'redirect_url'), 10, 2); |
|
| 57 | + add_action('pronamic_payment_status_update_' . self::SLUG, array(__CLASS__, 'status_update'), 10, 1); |
|
| 58 | 58 | |
| 59 | - add_filter( 'pronamic_payment_source_text_' . self::SLUG, array( __CLASS__, 'source_text' ), 10, 2 ); |
|
| 60 | - add_filter( 'pronamic_payment_source_description_' . self::SLUG, array( __CLASS__, 'source_description' ), 10, 2 ); |
|
| 61 | - add_filter( 'pronamic_payment_source_url_' . self::SLUG, array( __CLASS__, 'source_url' ), 10, 2 ); |
|
| 62 | - add_filter( 'pronamic_subscription_source_text_' . self::SLUG, array( __CLASS__, 'subscription_source_text' ), 10, 2 ); |
|
| 63 | - add_filter( 'pronamic_subscription_source_description_' . self::SLUG, array( __CLASS__, 'subscription_source_description' ), 10, 2 ); |
|
| 64 | - add_filter( 'pronamic_subscription_source_url_' . self::SLUG, array( __CLASS__, 'subscription_source_url' ), 10, 2 ); |
|
| 59 | + add_filter('pronamic_payment_source_text_' . self::SLUG, array(__CLASS__, 'source_text'), 10, 2); |
|
| 60 | + add_filter('pronamic_payment_source_description_' . self::SLUG, array(__CLASS__, 'source_description'), 10, 2); |
|
| 61 | + add_filter('pronamic_payment_source_url_' . self::SLUG, array(__CLASS__, 'source_url'), 10, 2); |
|
| 62 | + add_filter('pronamic_subscription_source_text_' . self::SLUG, array(__CLASS__, 'subscription_source_text'), 10, 2); |
|
| 63 | + add_filter('pronamic_subscription_source_description_' . self::SLUG, array(__CLASS__, 'subscription_source_description'), 10, 2); |
|
| 64 | + add_filter('pronamic_subscription_source_url_' . self::SLUG, array(__CLASS__, 'subscription_source_url'), 10, 2); |
|
| 65 | 65 | |
| 66 | - add_action( 'mepr_subscription_pre_delete', array( $this, 'subscription_pre_delete' ), 10, 1 ); |
|
| 66 | + add_action('mepr_subscription_pre_delete', array($this, 'subscription_pre_delete'), 10, 1); |
|
| 67 | 67 | |
| 68 | - add_action( 'mepr_subscription_transition_status', array( $this, 'memberpress_subscription_transition_status' ), 10, 3 ); |
|
| 68 | + add_action('mepr_subscription_transition_status', array($this, 'memberpress_subscription_transition_status'), 10, 3); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | * @param array $paths Array with gateway paths. |
| 77 | 77 | * @return array |
| 78 | 78 | */ |
| 79 | - public function gateway_paths( $paths ) { |
|
| 80 | - $paths[] = dirname( __FILE__ ) . '/../gateways/'; |
|
| 79 | + public function gateway_paths($paths) { |
|
| 80 | + $paths[] = dirname(__FILE__) . '/../gateways/'; |
|
| 81 | 81 | |
| 82 | 82 | return $paths; |
| 83 | 83 | } |
@@ -90,15 +90,15 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @return array |
| 92 | 92 | */ |
| 93 | - public function subscriptions_table_joins_nested_query_fix( $joins ) { |
|
| 94 | - if ( ! is_array( $joins ) ) { |
|
| 93 | + public function subscriptions_table_joins_nested_query_fix($joins) { |
|
| 94 | + if ( ! is_array($joins)) { |
|
| 95 | 95 | return $joins; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Loop joins. |
| 99 | - foreach ( $joins as &$join ) { |
|
| 99 | + foreach ($joins as &$join) { |
|
| 100 | 100 | // Determine if fix needs to be applied. |
| 101 | - if ( ! strpos( $join, 'expiring_txn' ) && ! strpos( $join, 't2.subscription_id=sub.id' ) ) { |
|
| 101 | + if ( ! strpos($join, 'expiring_txn') && ! strpos($join, 't2.subscription_id=sub.id')) { |
|
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | $join = str_replace( |
| 114 | 114 | ' AS t', |
| 115 | - sprintf( ' AS t, %s AS sub', $mepr_db->subscriptions ), |
|
| 115 | + sprintf(' AS t, %s AS sub', $mepr_db->subscriptions), |
|
| 116 | 116 | $join |
| 117 | 117 | ); |
| 118 | 118 | } |
@@ -130,14 +130,14 @@ discard block |
||
| 130 | 130 | * |
| 131 | 131 | * @return string |
| 132 | 132 | */ |
| 133 | - public static function redirect_url( $url, Payment $payment ) { |
|
| 133 | + public static function redirect_url($url, Payment $payment) { |
|
| 134 | 134 | global $transaction; |
| 135 | 135 | |
| 136 | 136 | $transaction_id = $payment->get_source_id(); |
| 137 | 137 | |
| 138 | - $transaction = new MeprTransaction( $transaction_id ); |
|
| 138 | + $transaction = new MeprTransaction($transaction_id); |
|
| 139 | 139 | |
| 140 | - switch ( $payment->get_status() ) { |
|
| 140 | + switch ($payment->get_status()) { |
|
| 141 | 141 | case Statuses::CANCELLED: |
| 142 | 142 | case Statuses::EXPIRED: |
| 143 | 143 | case Statuses::FAILURE: |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | array( |
| 148 | 148 | 'action' => 'payment_form', |
| 149 | 149 | 'txn' => $transaction->trans_num, |
| 150 | - '_wpnonce' => wp_create_nonce( 'mepr_payment_form' ), |
|
| 150 | + '_wpnonce' => wp_create_nonce('mepr_payment_form'), |
|
| 151 | 151 | ), |
| 152 | 152 | $product->url() |
| 153 | 153 | ); |
@@ -157,8 +157,8 @@ discard block |
||
| 157 | 157 | // @see https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/models/MeprOptions.php#L768-782 |
| 158 | 158 | $mepr_options = MeprOptions::fetch(); |
| 159 | 159 | |
| 160 | - $product = new MeprProduct( $transaction->product_id ); |
|
| 161 | - $sanitized_title = sanitize_title( $product->post_title ); |
|
| 160 | + $product = new MeprProduct($transaction->product_id); |
|
| 161 | + $sanitized_title = sanitize_title($product->post_title); |
|
| 162 | 162 | |
| 163 | 163 | $args = array( |
| 164 | 164 | 'membership_id' => $product->ID, |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | 'trans_num' => $transaction->trans_num, |
| 167 | 167 | ); |
| 168 | 168 | |
| 169 | - $url = $mepr_options->thankyou_page_url( http_build_query( $args ) ); |
|
| 169 | + $url = $mepr_options->thankyou_page_url(http_build_query($args)); |
|
| 170 | 170 | |
| 171 | 171 | break; |
| 172 | 172 | case Statuses::OPEN: |
@@ -184,26 +184,26 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @param Payment $payment The payment whose status is updated. |
| 186 | 186 | */ |
| 187 | - public static function status_update( Payment $payment ) { |
|
| 187 | + public static function status_update(Payment $payment) { |
|
| 188 | 188 | $transaction_id = $payment->get_source_id(); |
| 189 | 189 | |
| 190 | - $transaction = new MeprTransaction( $transaction_id ); |
|
| 190 | + $transaction = new MeprTransaction($transaction_id); |
|
| 191 | 191 | |
| 192 | - if ( $payment->get_recurring() ) { |
|
| 192 | + if ($payment->get_recurring()) { |
|
| 193 | 193 | $subscription = $transaction->subscription(); |
| 194 | 194 | |
| 195 | - if ( empty( $subscription ) || empty( $subscription->id ) ) { |
|
| 195 | + if (empty($subscription) || empty($subscription->id)) { |
|
| 196 | 196 | $subscription_id = $payment->get_subscription()->get_source_id(); |
| 197 | 197 | |
| 198 | - $subscription = new MeprSubscription( $subscription_id ); |
|
| 198 | + $subscription = new MeprSubscription($subscription_id); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | // Same source ID and first transaction ID for recurring payment means we need to add a new transaction. |
| 202 | - if ( $payment->get_source_id() === $subscription->id ) { |
|
| 202 | + if ($payment->get_source_id() === $subscription->id) { |
|
| 203 | 203 | // First transaction. |
| 204 | 204 | $first_txn = $subscription->first_txn(); |
| 205 | 205 | |
| 206 | - if ( false === $first_txn || ! ( $first_txn instanceof MeprTransaction ) ) { |
|
| 206 | + if (false === $first_txn || ! ($first_txn instanceof MeprTransaction)) { |
|
| 207 | 207 | $first_txn = new MeprTransaction(); |
| 208 | 208 | $first_txn->user_id = $subscription->user_id; |
| 209 | 209 | $first_txn->product_id = $subscription->product_id; |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | // Transaction number. |
| 215 | 215 | $trans_num = $payment->get_transaction_id(); |
| 216 | 216 | |
| 217 | - if ( empty( $trans_num ) ) { |
|
| 217 | + if (empty($trans_num)) { |
|
| 218 | 218 | $trans_num = uniqid(); |
| 219 | 219 | } |
| 220 | 220 | |
@@ -230,16 +230,16 @@ discard block |
||
| 230 | 230 | $transaction->status = MeprTransaction::$pending_str; |
| 231 | 231 | $transaction->subscription_id = $subscription->id; |
| 232 | 232 | |
| 233 | - $transaction->set_gross( $payment->get_amount()->get_amount() ); |
|
| 233 | + $transaction->set_gross($payment->get_amount()->get_amount()); |
|
| 234 | 234 | |
| 235 | 235 | $transaction->store(); |
| 236 | 236 | |
| 237 | 237 | // Set source ID. |
| 238 | - $payment->set_meta( 'source_id', $transaction->id ); |
|
| 238 | + $payment->set_meta('source_id', $transaction->id); |
|
| 239 | 239 | |
| 240 | 240 | $payment->source_id = $transaction->id; |
| 241 | 241 | |
| 242 | - if ( MeprSubscription::$active_str === $subscription->status ) { |
|
| 242 | + if (MeprSubscription::$active_str === $subscription->status) { |
|
| 243 | 243 | // New transaction and subscription confirmation. |
| 244 | 244 | $subscription_confirmation = new MeprTransaction(); |
| 245 | 245 | $subscription_confirmation->created_at = $payment->post->post_date_gmt; |
@@ -251,26 +251,26 @@ discard block |
||
| 251 | 251 | $subscription_confirmation->txn_type = MeprTransaction::$subscription_confirmation_str; |
| 252 | 252 | $subscription_confirmation->status = MeprTransaction::$confirmed_str; |
| 253 | 253 | $subscription_confirmation->subscription_id = $subscription->id; |
| 254 | - $subscription_confirmation->expires_at = MeprUtils::ts_to_mysql_date( strtotime( $payment->post->post_date_gmt ) + MeprUtils::days( 15 ), 'Y-m-d 23:59:59' ); |
|
| 254 | + $subscription_confirmation->expires_at = MeprUtils::ts_to_mysql_date(strtotime($payment->post->post_date_gmt) + MeprUtils::days(15), 'Y-m-d 23:59:59'); |
|
| 255 | 255 | |
| 256 | - $subscription_confirmation->set_subtotal( 0.00 ); |
|
| 256 | + $subscription_confirmation->set_subtotal(0.00); |
|
| 257 | 257 | |
| 258 | 258 | $subscription_confirmation->store(); |
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - $should_update = ! MemberPress::transaction_has_status( $transaction, array( |
|
| 263 | + $should_update = ! MemberPress::transaction_has_status($transaction, array( |
|
| 264 | 264 | MeprTransaction::$failed_str, |
| 265 | 265 | MeprTransaction::$complete_str, |
| 266 | - ) ); |
|
| 266 | + )); |
|
| 267 | 267 | |
| 268 | - if ( $should_update ) { |
|
| 268 | + if ($should_update) { |
|
| 269 | 269 | $gateway = new Gateway(); |
| 270 | 270 | |
| 271 | 271 | $gateway->mp_txn = $transaction; |
| 272 | 272 | |
| 273 | - switch ( $payment->get_status() ) { |
|
| 273 | + switch ($payment->get_status()) { |
|
| 274 | 274 | case Statuses::CANCELLED: |
| 275 | 275 | case Statuses::EXPIRED: |
| 276 | 276 | case Statuses::FAILURE: |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | |
| 279 | 279 | break; |
| 280 | 280 | case Statuses::SUCCESS: |
| 281 | - if ( $payment->get_recurring() ) { |
|
| 281 | + if ($payment->get_recurring()) { |
|
| 282 | 282 | $gateway->record_subscription_payment(); |
| 283 | 283 | } else { |
| 284 | 284 | $gateway->record_payment(); |
@@ -297,25 +297,25 @@ discard block |
||
| 297 | 297 | * |
| 298 | 298 | * @param int $subscription_id MemberPress subscription id. |
| 299 | 299 | */ |
| 300 | - public function subscription_pre_delete( $subscription_id ) { |
|
| 301 | - $subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $subscription_id ); |
|
| 300 | + public function subscription_pre_delete($subscription_id) { |
|
| 301 | + $subscription = get_pronamic_subscription_by_meta('_pronamic_subscription_source_id', $subscription_id); |
|
| 302 | 302 | |
| 303 | - if ( ! $subscription ) { |
|
| 303 | + if ( ! $subscription) { |
|
| 304 | 304 | return; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // Add note. |
| 308 | 308 | $note = sprintf( |
| 309 | 309 | /* translators: %s: MemberPress */ |
| 310 | - __( '%s subscription deleted.', 'pronamic_ideal' ), |
|
| 311 | - __( 'MemberPress', 'pronamic_ideal' ) |
|
| 310 | + __('%s subscription deleted.', 'pronamic_ideal'), |
|
| 311 | + __('MemberPress', 'pronamic_ideal') |
|
| 312 | 312 | ); |
| 313 | 313 | |
| 314 | - $subscription->add_note( $note ); |
|
| 314 | + $subscription->add_note($note); |
|
| 315 | 315 | |
| 316 | 316 | // The status of canceled or completed subscriptions will not be changed automatically. |
| 317 | - if ( ! in_array( $subscription->get_status(), array( Statuses::CANCELLED, Statuses::COMPLETED ), true ) ) { |
|
| 318 | - $subscription->set_status( Statuses::CANCELLED ); |
|
| 317 | + if ( ! in_array($subscription->get_status(), array(Statuses::CANCELLED, Statuses::COMPLETED), true)) { |
|
| 318 | + $subscription->set_status(Statuses::CANCELLED); |
|
| 319 | 319 | |
| 320 | 320 | $subscription->save(); |
| 321 | 321 | } |
@@ -329,18 +329,18 @@ discard block |
||
| 329 | 329 | * |
| 330 | 330 | * @return string |
| 331 | 331 | */ |
| 332 | - public static function source_text( $text, Payment $payment ) { |
|
| 333 | - $text = __( 'MemberPress', 'pronamic_ideal' ) . '<br />'; |
|
| 332 | + public static function source_text($text, Payment $payment) { |
|
| 333 | + $text = __('MemberPress', 'pronamic_ideal') . '<br />'; |
|
| 334 | 334 | |
| 335 | 335 | $text .= sprintf( |
| 336 | 336 | '<a href="%s">%s</a>', |
| 337 | - add_query_arg( array( |
|
| 337 | + add_query_arg(array( |
|
| 338 | 338 | 'page' => 'memberpress-trans', |
| 339 | 339 | 'action' => 'edit', |
| 340 | 340 | 'id' => $payment->source_id, |
| 341 | - ), admin_url( 'admin.php' ) ), |
|
| 341 | + ), admin_url('admin.php')), |
|
| 342 | 342 | /* translators: %s: payment source id */ |
| 343 | - sprintf( __( 'Transaction %s', 'pronamic_ideal' ), $payment->source_id ) |
|
| 343 | + sprintf(__('Transaction %s', 'pronamic_ideal'), $payment->source_id) |
|
| 344 | 344 | ); |
| 345 | 345 | |
| 346 | 346 | return $text; |
@@ -354,17 +354,17 @@ discard block |
||
| 354 | 354 | * |
| 355 | 355 | * @return string |
| 356 | 356 | */ |
| 357 | - public static function subscription_source_text( $text, Subscription $subscription ) { |
|
| 358 | - $text = __( 'MemberPress', 'pronamic_ideal' ) . '<br />'; |
|
| 357 | + public static function subscription_source_text($text, Subscription $subscription) { |
|
| 358 | + $text = __('MemberPress', 'pronamic_ideal') . '<br />'; |
|
| 359 | 359 | |
| 360 | 360 | $text .= sprintf( |
| 361 | 361 | '<a href="%s">%s</a>', |
| 362 | - add_query_arg( array( |
|
| 362 | + add_query_arg(array( |
|
| 363 | 363 | 'page' => 'memberpress-subscriptions', |
| 364 | 364 | 'subscription' => $subscription->source_id, |
| 365 | - ), admin_url( 'admin.php' ) ), |
|
| 365 | + ), admin_url('admin.php')), |
|
| 366 | 366 | /* translators: %s: payment source id */ |
| 367 | - sprintf( __( 'Subscription %s', 'pronamic_ideal' ), $subscription->source_id ) |
|
| 367 | + sprintf(__('Subscription %s', 'pronamic_ideal'), $subscription->source_id) |
|
| 368 | 368 | ); |
| 369 | 369 | |
| 370 | 370 | return $text; |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | * |
| 379 | 379 | * @return string |
| 380 | 380 | */ |
| 381 | - public static function source_description( $description, Payment $payment ) { |
|
| 382 | - return __( 'MemberPress Transaction', 'pronamic_ideal' ); |
|
| 381 | + public static function source_description($description, Payment $payment) { |
|
| 382 | + return __('MemberPress Transaction', 'pronamic_ideal'); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | * |
| 391 | 391 | * @return string |
| 392 | 392 | */ |
| 393 | - public static function subscription_source_description( $description, Subscription $subscription ) { |
|
| 394 | - return __( 'MemberPress Subscription', 'pronamic_ideal' ); |
|
| 393 | + public static function subscription_source_description($description, Subscription $subscription) { |
|
| 394 | + return __('MemberPress Subscription', 'pronamic_ideal'); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -402,12 +402,12 @@ discard block |
||
| 402 | 402 | * |
| 403 | 403 | * @return string |
| 404 | 404 | */ |
| 405 | - public static function source_url( $url, Payment $payment ) { |
|
| 406 | - $url = add_query_arg( array( |
|
| 405 | + public static function source_url($url, Payment $payment) { |
|
| 406 | + $url = add_query_arg(array( |
|
| 407 | 407 | 'page' => 'memberpress-trans', |
| 408 | 408 | 'action' => 'edit', |
| 409 | 409 | 'id' => $payment->source_id, |
| 410 | - ), admin_url( 'admin.php' ) ); |
|
| 410 | + ), admin_url('admin.php')); |
|
| 411 | 411 | |
| 412 | 412 | return $url; |
| 413 | 413 | } |
@@ -420,11 +420,11 @@ discard block |
||
| 420 | 420 | * |
| 421 | 421 | * @return string |
| 422 | 422 | */ |
| 423 | - public static function subscription_source_url( $url, Subscription $subscription ) { |
|
| 424 | - $url = add_query_arg( array( |
|
| 423 | + public static function subscription_source_url($url, Subscription $subscription) { |
|
| 424 | + $url = add_query_arg(array( |
|
| 425 | 425 | 'page' => 'memberpress-subscriptions', |
| 426 | 426 | 'subscription' => $subscription->source_id, |
| 427 | - ), admin_url( 'admin.php' ) ); |
|
| 427 | + ), admin_url('admin.php')); |
|
| 428 | 428 | |
| 429 | 429 | return $url; |
| 430 | 430 | } |
@@ -440,16 +440,16 @@ discard block |
||
| 440 | 440 | * @param string $status_new New status identifier. |
| 441 | 441 | * @param MeprSubscription $memberpress_subscription MemberPress subscription object. |
| 442 | 442 | */ |
| 443 | - public function memberpress_subscription_transition_status( $status_old, $status_new, $memberpress_subscription ) { |
|
| 444 | - $subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $memberpress_subscription->id ); |
|
| 443 | + public function memberpress_subscription_transition_status($status_old, $status_new, $memberpress_subscription) { |
|
| 444 | + $subscription = get_pronamic_subscription_by_meta('_pronamic_subscription_source_id', $memberpress_subscription->id); |
|
| 445 | 445 | |
| 446 | - if ( empty( $subscription ) ) { |
|
| 446 | + if (empty($subscription)) { |
|
| 447 | 447 | return; |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | - $status = SubscriptionStatuses::transform( $status_new ); |
|
| 450 | + $status = SubscriptionStatuses::transform($status_new); |
|
| 451 | 451 | |
| 452 | - $subscription->set_status( $status ); |
|
| 452 | + $subscription->set_status($status); |
|
| 453 | 453 | |
| 454 | 454 | $subscription->save(); |
| 455 | 455 | } |