Completed
Push — develop ( ed9728...4cab8a )
by Reüel
04:48
created
src/Extension.php 1 patch
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -47,21 +47,21 @@  discard block
 block discarded – undo
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
-		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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
118 118
 				// @see 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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
191 191
 				$transaction->status          = MeprTransaction::$pending_str;
192 192
 				$transaction->subscription_id = $subscription->id;
193 193
 
194
-				$transaction->set_gross( $payment->get_amount()->get_amount() );
194
+				$transaction->set_gross($payment->get_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,26 +222,26 @@  discard block
 block discarded – undo
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
 				}
231 231
 			}
232 232
 		}
233 233
 
234
-		$should_update = ! MemberPress::transaction_has_status( $transaction, array(
234
+		$should_update = ! MemberPress::transaction_has_status($transaction, array(
235 235
 			MeprTransaction::$failed_str,
236 236
 			MeprTransaction::$complete_str,
237
-		) );
237
+		));
238 238
 
239
-		if ( $should_update ) {
239
+		if ($should_update) {
240 240
 			$gateway = new Gateway();
241 241
 
242 242
 			$gateway->mp_txn = $transaction;
243 243
 
244
-			switch ( $payment->get_status() ) {
244
+			switch ($payment->get_status()) {
245 245
 				case Statuses::CANCELLED:
246 246
 				case Statuses::EXPIRED:
247 247
 				case Statuses::FAILURE:
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 
250 250
 					break;
251 251
 				case Statuses::SUCCESS:
252
-					if ( $payment->get_recurring() ) {
252
+					if ($payment->get_recurring()) {
253 253
 						$gateway->record_subscription_payment();
254 254
 					} else {
255 255
 						$gateway->record_payment();
@@ -268,25 +268,25 @@  discard block
 block discarded – undo
268 268
 	 *
269 269
 	 * @param int $subscription_id MemberPress subscription id.
270 270
 	 */
271
-	public function subscription_pre_delete( $subscription_id ) {
272
-		$subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $subscription_id );
271
+	public function subscription_pre_delete($subscription_id) {
272
+		$subscription = get_pronamic_subscription_by_meta('_pronamic_subscription_source_id', $subscription_id);
273 273
 
274
-		if ( ! $subscription ) {
274
+		if ( ! $subscription) {
275 275
 			return;
276 276
 		}
277 277
 
278 278
 		// Add note.
279 279
 		$note = sprintf(
280 280
 			/* translators: %s: MemberPress */
281
-			__( '%s subscription deleted.', 'pronamic_ideal' ),
282
-			__( 'MemberPress', 'pronamic_ideal' )
281
+			__('%s subscription deleted.', 'pronamic_ideal'),
282
+			__('MemberPress', 'pronamic_ideal')
283 283
 		);
284 284
 
285
-		$subscription->add_note( $note );
285
+		$subscription->add_note($note);
286 286
 
287 287
 		// The status of canceled or completed subscriptions will not be changed automatically.
288
-		if ( ! in_array( $subscription->get_status(), array( Statuses::CANCELLED, Statuses::COMPLETED ), true ) ) {
289
-			$subscription->set_status( Statuses::CANCELLED );
288
+		if ( ! in_array($subscription->get_status(), array(Statuses::CANCELLED, Statuses::COMPLETED), true)) {
289
+			$subscription->set_status(Statuses::CANCELLED);
290 290
 
291 291
 			$subscription->save();
292 292
 		}
@@ -300,18 +300,18 @@  discard block
 block discarded – undo
300 300
 	 *
301 301
 	 * @return string
302 302
 	 */
303
-	public static function source_text( $text, Payment $payment ) {
304
-		$text = __( 'MemberPress', 'pronamic_ideal' ) . '<br />';
303
+	public static function source_text($text, Payment $payment) {
304
+		$text = __('MemberPress', 'pronamic_ideal') . '<br />';
305 305
 
306 306
 		$text .= sprintf(
307 307
 			'<a href="%s">%s</a>',
308
-			add_query_arg( array(
308
+			add_query_arg(array(
309 309
 				'page'   => 'memberpress-trans',
310 310
 				'action' => 'edit',
311 311
 				'id'     => $payment->source_id,
312
-			), admin_url( 'admin.php' ) ),
312
+			), admin_url('admin.php')),
313 313
 			/* translators: %s: payment source id */
314
-			sprintf( __( 'Transaction %s', 'pronamic_ideal' ), $payment->source_id )
314
+			sprintf(__('Transaction %s', 'pronamic_ideal'), $payment->source_id)
315 315
 		);
316 316
 
317 317
 		return $text;
@@ -325,17 +325,17 @@  discard block
 block discarded – undo
325 325
 	 *
326 326
 	 * @return string
327 327
 	 */
328
-	public static function subscription_source_text( $text, Subscription $subscription ) {
329
-		$text = __( 'MemberPress', 'pronamic_ideal' ) . '<br />';
328
+	public static function subscription_source_text($text, Subscription $subscription) {
329
+		$text = __('MemberPress', 'pronamic_ideal') . '<br />';
330 330
 
331 331
 		$text .= sprintf(
332 332
 			'<a href="%s">%s</a>',
333
-			add_query_arg( array(
333
+			add_query_arg(array(
334 334
 				'page'         => 'memberpress-subscriptions',
335 335
 				'subscription' => $subscription->source_id,
336
-			), admin_url( 'admin.php' ) ),
336
+			), admin_url('admin.php')),
337 337
 			/* translators: %s: payment source id */
338
-			sprintf( __( 'Subscription %s', 'pronamic_ideal' ), $subscription->source_id )
338
+			sprintf(__('Subscription %s', 'pronamic_ideal'), $subscription->source_id)
339 339
 		);
340 340
 
341 341
 		return $text;
@@ -349,8 +349,8 @@  discard block
 block discarded – undo
349 349
 	 *
350 350
 	 * @return string
351 351
 	 */
352
-	public static function source_description( $description, Payment $payment ) {
353
-		return __( 'MemberPress Transaction', 'pronamic_ideal' );
352
+	public static function source_description($description, Payment $payment) {
353
+		return __('MemberPress Transaction', 'pronamic_ideal');
354 354
 	}
355 355
 
356 356
 	/**
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
 	 *
362 362
 	 * @return string
363 363
 	 */
364
-	public static function subscription_source_description( $description, Subscription $subscription ) {
365
-		return __( 'MemberPress Subscription', 'pronamic_ideal' );
364
+	public static function subscription_source_description($description, Subscription $subscription) {
365
+		return __('MemberPress Subscription', 'pronamic_ideal');
366 366
 	}
367 367
 
368 368
 	/**
@@ -373,12 +373,12 @@  discard block
 block discarded – undo
373 373
 	 *
374 374
 	 * @return string
375 375
 	 */
376
-	public static function source_url( $url, Payment $payment ) {
377
-		$url = add_query_arg( array(
376
+	public static function source_url($url, Payment $payment) {
377
+		$url = add_query_arg(array(
378 378
 			'page'   => 'memberpress-trans',
379 379
 			'action' => 'edit',
380 380
 			'id'     => $payment->source_id,
381
-		), admin_url( 'admin.php' ) );
381
+		), admin_url('admin.php'));
382 382
 
383 383
 		return $url;
384 384
 	}
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
 	 *
392 392
 	 * @return string
393 393
 	 */
394
-	public static function subscription_source_url( $url, Subscription $subscription ) {
395
-		$url = add_query_arg( array(
394
+	public static function subscription_source_url($url, Subscription $subscription) {
395
+		$url = add_query_arg(array(
396 396
 			'page'         => 'memberpress-subscriptions',
397 397
 			'subscription' => $subscription->source_id,
398
-		), admin_url( 'admin.php' ) );
398
+		), admin_url('admin.php'));
399 399
 
400 400
 		return $url;
401 401
 	}
@@ -411,16 +411,16 @@  discard block
 block discarded – undo
411 411
 	 * @param string           $status_new               New status identifier.
412 412
 	 * @param MeprSubscription $memberpress_subscription MemberPress subscription object.
413 413
 	 */
414
-	public function memberpress_subscription_transition_status( $status_old, $status_new, $memberpress_subscription ) {
415
-		$subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $memberpress_subscription->id );
414
+	public function memberpress_subscription_transition_status($status_old, $status_new, $memberpress_subscription) {
415
+		$subscription = get_pronamic_subscription_by_meta('_pronamic_subscription_source_id', $memberpress_subscription->id);
416 416
 
417
-		if ( empty( $subscription ) ) {
417
+		if (empty($subscription)) {
418 418
 			return;
419 419
 		}
420 420
 
421
-		$status = SubscriptionStatuses::transform( $status_new );
421
+		$status = SubscriptionStatuses::transform($status_new);
422 422
 
423
-		$subscription->set_status( $status );
423
+		$subscription->set_status($status);
424 424
 
425 425
 		$subscription->save();
426 426
 	}
Please login to merge, or discard this patch.