Completed
Push — master ( 949330...bc25c6 )
by
unknown
13s queued 10s
created
includes/admin/class-wc-stripe-inbox-notes.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -19,64 +19,64 @@  discard block
 block discarded – undo
19 19
 	const CAMPAIGN_2020_CLEANUP_ACTION = 'wc_stripe_apple_pay_2020_cleanup';
20 20
 
21 21
 	public function __construct() {
22
-		add_action( self::POST_SETUP_SUCCESS_ACTION, array( self::class, 'create_marketing_note' ) );
23
-		add_action( self::CAMPAIGN_2020_CLEANUP_ACTION, array( self::class, 'cleanup_campaign_2020' ) );
22
+		add_action(self::POST_SETUP_SUCCESS_ACTION, array(self::class, 'create_marketing_note'));
23
+		add_action(self::CAMPAIGN_2020_CLEANUP_ACTION, array(self::class, 'cleanup_campaign_2020'));
24 24
 
25 25
 		// Schedule a 2020 holiday campaign cleanup action if needed.
26 26
 		// First, check to see if we are still before the cutoff.
27 27
 		// We don't need to (re)schedule this after the cutoff.
28
-		if ( current_time( 'timestamp', true ) < self::get_campaign_2020_cutoff() ) {
28
+		if (current_time('timestamp', true) < self::get_campaign_2020_cutoff()) {
29 29
 			// If we don't have the clean up action scheduled, add it.
30
-			if ( ! wp_next_scheduled( self::CAMPAIGN_2020_CLEANUP_ACTION ) ) {
31
-				wp_schedule_single_event( self::get_campaign_2020_cutoff(), self::CAMPAIGN_2020_CLEANUP_ACTION );
30
+			if ( ! wp_next_scheduled(self::CAMPAIGN_2020_CLEANUP_ACTION)) {
31
+				wp_schedule_single_event(self::get_campaign_2020_cutoff(), self::CAMPAIGN_2020_CLEANUP_ACTION);
32 32
 			}
33 33
 		}
34 34
 	}
35 35
 
36 36
 	public static function get_campaign_2020_cutoff() {
37
-		return strtotime( '22 December 2020' );
37
+		return strtotime('22 December 2020');
38 38
 	}
39 39
 
40 40
 	public static function get_success_title() {
41
-		if ( current_time( 'timestamp', true ) < self::get_campaign_2020_cutoff() ) {
42
-			return __( 'Boost sales this holiday season with Apple Pay!', 'woocommerce-gateway-stripe' );
41
+		if (current_time('timestamp', true) < self::get_campaign_2020_cutoff()) {
42
+			return __('Boost sales this holiday season with Apple Pay!', 'woocommerce-gateway-stripe');
43 43
 		}
44 44
 
45
-		return__( 'Boost sales with Apple Pay!', 'woocommerce-gateway-stripe' );
45
+		return__('Boost sales with Apple Pay!', 'woocommerce-gateway-stripe');
46 46
 	}
47 47
 
48 48
 	/**
49 49
 	 * Manage notes to show after Apple Pay domain verification.
50 50
 	 */
51
-	public static function notify_on_apple_pay_domain_verification( $verification_complete ) {
52
-		if ( ! class_exists( 'Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes' ) ) {
51
+	public static function notify_on_apple_pay_domain_verification($verification_complete) {
52
+		if ( ! class_exists('Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes')) {
53 53
 			return;
54 54
 		}
55 55
 
56
-		if ( ! class_exists( 'WC_Data_Store' ) ) {
56
+		if ( ! class_exists('WC_Data_Store')) {
57 57
 			return;
58 58
 		}
59 59
 
60
-		if ( $verification_complete ) {
61
-			if ( self::should_show_marketing_note() && ! wp_next_scheduled( self::POST_SETUP_SUCCESS_ACTION ) ) {
62
-				wp_schedule_single_event( time() + DAY_IN_SECONDS, self::POST_SETUP_SUCCESS_ACTION );
60
+		if ($verification_complete) {
61
+			if (self::should_show_marketing_note() && ! wp_next_scheduled(self::POST_SETUP_SUCCESS_ACTION)) {
62
+				wp_schedule_single_event(time() + DAY_IN_SECONDS, self::POST_SETUP_SUCCESS_ACTION);
63 63
 			}
64 64
 
65 65
 			// If the domain verification completed after failure note was created, make sure it's marked as actioned.
66 66
 			try {
67
-				$data_store       = WC_Data_Store::load( 'admin-note' );
68
-				$failure_note_ids = $data_store->get_notes_with_name( self::FAILURE_NOTE_NAME );
69
-				if ( ! empty( $failure_note_ids ) ) {
70
-					$note_id = array_pop( $failure_note_ids );
71
-					$note    = WC_Admin_Notes::get_note( $note_id );
72
-					if ( false !== $note && WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status() ) {
73
-						$note->set_status( WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED );
67
+				$data_store       = WC_Data_Store::load('admin-note');
68
+				$failure_note_ids = $data_store->get_notes_with_name(self::FAILURE_NOTE_NAME);
69
+				if ( ! empty($failure_note_ids)) {
70
+					$note_id = array_pop($failure_note_ids);
71
+					$note    = WC_Admin_Notes::get_note($note_id);
72
+					if (false !== $note && WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status()) {
73
+						$note->set_status(WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED);
74 74
 						$note->save();
75 75
 					}
76 76
 				}
77
-			} catch ( Exception $e ) {}  // @codingStandardsIgnoreLine.
77
+			} catch (Exception $e) {}  // @codingStandardsIgnoreLine.
78 78
 		} else {
79
-			if ( empty( $failure_note_ids ) ) {
79
+			if (empty($failure_note_ids)) {
80 80
 				self::create_failure_note();
81 81
 			}
82 82
 		}
@@ -88,27 +88,27 @@  discard block
 block discarded – undo
88 88
 	public static function should_show_marketing_note() {
89 89
 		// Display to US merchants only.
90 90
 		$base_location = wc_get_base_location();
91
-		if ( ! $base_location || 'US' !== $base_location['country'] ) {
91
+		if ( ! $base_location || 'US' !== $base_location['country']) {
92 92
 			return false;
93 93
 		}
94 94
 
95 95
 		// Make sure Apple Pay is enabled and setup is successful.
96
-		$stripe_settings       = get_option( 'woocommerce_stripe_settings', array() );
97
-		$stripe_enabled        = isset( $stripe_settings['enabled'] ) && 'yes' === $stripe_settings['enabled'];
98
-		$button_enabled        = isset( $stripe_settings['payment_request'] ) && 'yes' === $stripe_settings['payment_request'];
99
-		$verification_complete = isset( $stripe_settings['apple_pay_domain_set'] ) && 'yes' === $stripe_settings['apple_pay_domain_set'];
100
-		if ( ! $stripe_enabled || ! $button_enabled || ! $verification_complete ) {
96
+		$stripe_settings       = get_option('woocommerce_stripe_settings', array());
97
+		$stripe_enabled        = isset($stripe_settings['enabled']) && 'yes' === $stripe_settings['enabled'];
98
+		$button_enabled        = isset($stripe_settings['payment_request']) && 'yes' === $stripe_settings['payment_request'];
99
+		$verification_complete = isset($stripe_settings['apple_pay_domain_set']) && 'yes' === $stripe_settings['apple_pay_domain_set'];
100
+		if ( ! $stripe_enabled || ! $button_enabled || ! $verification_complete) {
101 101
 			return false;
102 102
 		}
103 103
 
104 104
 		// Make sure note doesn't already exist.
105 105
 		try {
106
-			$data_store       = WC_Data_Store::load( 'admin-note' );
107
-			$success_note_ids = $data_store->get_notes_with_name( self::SUCCESS_NOTE_NAME );
108
-			if ( ! empty( $success_note_ids ) ) {
106
+			$data_store       = WC_Data_Store::load('admin-note');
107
+			$success_note_ids = $data_store->get_notes_with_name(self::SUCCESS_NOTE_NAME);
108
+			if ( ! empty($success_note_ids)) {
109 109
 				return false;
110 110
 			}
111
-		} catch ( Exception $e ) {
111
+		} catch (Exception $e) {
112 112
 			return false; // If unable to check, assume it shouldn't show note.
113 113
 		}
114 114
 
@@ -120,19 +120,19 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	public static function create_marketing_note() {
122 122
 		// Make sure conditions for this note still hold.
123
-		if ( ! self::should_show_marketing_note() ) {
123
+		if ( ! self::should_show_marketing_note()) {
124 124
 			return;
125 125
 		}
126 126
 
127 127
 		$note = new WC_Admin_Note();
128
-		$note->set_title( self::get_success_title() );
129
-		$note->set_content( __( 'Now that you accept Apple Pay® with Stripe, you can increase conversion rates by letting your customers know that Apple Pay is available. Here’s a marketing guide to help you get started.', 'woocommerce-gateway-stripe' ) );
130
-		$note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_MARKETING );
131
-		$note->set_name( self::SUCCESS_NOTE_NAME );
132
-		$note->set_source( 'woocommerce-gateway-stripe' );
128
+		$note->set_title(self::get_success_title());
129
+		$note->set_content(__('Now that you accept Apple Pay® with Stripe, you can increase conversion rates by letting your customers know that Apple Pay is available. Here’s a marketing guide to help you get started.', 'woocommerce-gateway-stripe'));
130
+		$note->set_type(WC_Admin_Note::E_WC_ADMIN_NOTE_MARKETING);
131
+		$note->set_name(self::SUCCESS_NOTE_NAME);
132
+		$note->set_source('woocommerce-gateway-stripe');
133 133
 		$note->add_action(
134 134
 			'marketing-guide',
135
-			__( 'See marketing guide', 'woocommerce-gateway-stripe' ),
135
+			__('See marketing guide', 'woocommerce-gateway-stripe'),
136 136
 			'https://developer.apple.com/apple-pay/marketing/'
137 137
 		);
138 138
 		$note->save();
@@ -143,14 +143,14 @@  discard block
 block discarded – undo
143 143
 	 */
144 144
 	public static function create_failure_note() {
145 145
 		$note = new WC_Admin_Note();
146
-		$note->set_title( __( 'Apple Pay domain verification needed', 'woocommerce-gateway-stripe' ) );
147
-		$note->set_content( __( 'The WooCommerce Stripe Gateway extension attempted to perform domain verification on behalf of your store, but was unable to do so. This must be resolved before Apple Pay can be offered to your customers.', 'woocommerce-gateway-stripe' ) );
148
-		$note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
149
-		$note->set_name( self::FAILURE_NOTE_NAME );
150
-		$note->set_source( 'woocommerce-gateway-stripe' );
146
+		$note->set_title(__('Apple Pay domain verification needed', 'woocommerce-gateway-stripe'));
147
+		$note->set_content(__('The WooCommerce Stripe Gateway extension attempted to perform domain verification on behalf of your store, but was unable to do so. This must be resolved before Apple Pay can be offered to your customers.', 'woocommerce-gateway-stripe'));
148
+		$note->set_type(WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL);
149
+		$note->set_name(self::FAILURE_NOTE_NAME);
150
+		$note->set_source('woocommerce-gateway-stripe');
151 151
 		$note->add_action(
152 152
 			'learn-more',
153
-			__( 'Learn more', 'woocommerce-gateway-stripe' ),
153
+			__('Learn more', 'woocommerce-gateway-stripe'),
154 154
 			'https://docs.woocommerce.com/document/stripe/#apple-pay'
155 155
 		);
156 156
 		$note->save();
@@ -162,38 +162,38 @@  discard block
 block discarded – undo
162 162
 	 * on/about 2020 Dec 22.
163 163
 	 */
164 164
 	public static function cleanup_campaign_2020() {
165
-		if ( ! class_exists( 'Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes') ) {
165
+		if ( ! class_exists('Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes')) {
166 166
 			return;
167 167
 		}
168 168
 
169
-		if ( ! class_exists( 'WC_Data_Store' ) ) {
169
+		if ( ! class_exists('WC_Data_Store')) {
170 170
 			return;
171 171
 		}
172 172
 
173 173
 		$note_ids = array();
174 174
 
175 175
 		try {
176
-			$data_store = WC_Data_Store::load( 'admin-note' );
177
-			$note_ids   = $data_store->get_notes_with_name( self::SUCCESS_NOTE_NAME );
178
-			if ( empty( $note_ids ) ) {
176
+			$data_store = WC_Data_Store::load('admin-note');
177
+			$note_ids   = $data_store->get_notes_with_name(self::SUCCESS_NOTE_NAME);
178
+			if (empty($note_ids)) {
179 179
 				return;
180 180
 			}
181
-		} catch ( Exception $e ) {
181
+		} catch (Exception $e) {
182 182
 			return;
183 183
 		}
184 184
 
185 185
 		$deleted_an_unactioned_note = false;
186 186
 
187
-		foreach ( (array) $note_ids as $note_id ) {
188
-			$note = new WC_Admin_Note( $note_id );
189
-			if ( WC_Admin_Note::E_WC_ADMIN_NOTE_UNACTIONED == $note->get_status() ) {
187
+		foreach ((array) $note_ids as $note_id) {
188
+			$note = new WC_Admin_Note($note_id);
189
+			if (WC_Admin_Note::E_WC_ADMIN_NOTE_UNACTIONED == $note->get_status()) {
190 190
 				$note->delete();
191 191
 				$deleted_an_unactioned_note = true;
192 192
 			}
193
-			unset( $note );
193
+			unset($note);
194 194
 		}
195 195
 
196
-		if ( $deleted_an_unactioned_note ) {
196
+		if ($deleted_an_unactioned_note) {
197 197
 			self::create_marketing_note();
198 198
 		}
199 199
 	}
Please login to merge, or discard this patch.