@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -19,64 +19,64 @@ discard block |
||
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 |
||
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,24 +120,24 @@ discard block |
||
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 | try { |
128 | 128 | $note = new WC_Admin_Note(); |
129 | - $note->set_title( self::get_success_title() ); |
|
130 | - $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' ) ); |
|
131 | - $note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_MARKETING ); |
|
132 | - $note->set_name( self::SUCCESS_NOTE_NAME ); |
|
133 | - $note->set_source( 'woocommerce-gateway-stripe' ); |
|
129 | + $note->set_title(self::get_success_title()); |
|
130 | + $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')); |
|
131 | + $note->set_type(WC_Admin_Note::E_WC_ADMIN_NOTE_MARKETING); |
|
132 | + $note->set_name(self::SUCCESS_NOTE_NAME); |
|
133 | + $note->set_source('woocommerce-gateway-stripe'); |
|
134 | 134 | $note->add_action( |
135 | 135 | 'marketing-guide', |
136 | - __( 'See marketing guide', 'woocommerce-gateway-stripe' ), |
|
136 | + __('See marketing guide', 'woocommerce-gateway-stripe'), |
|
137 | 137 | 'https://developer.apple.com/apple-pay/marketing/' |
138 | 138 | ); |
139 | 139 | $note->save(); |
140 | - } catch ( Exception $e ) {} // @codingStandardsIgnoreLine. |
|
140 | + } catch (Exception $e) {} // @codingStandardsIgnoreLine. |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -146,18 +146,18 @@ discard block |
||
146 | 146 | public static function create_failure_note() { |
147 | 147 | try { |
148 | 148 | $note = new WC_Admin_Note(); |
149 | - $note->set_title( __( 'Apple Pay domain verification needed', 'woocommerce-gateway-stripe' ) ); |
|
150 | - $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' ) ); |
|
151 | - $note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL ); |
|
152 | - $note->set_name( self::FAILURE_NOTE_NAME ); |
|
153 | - $note->set_source( 'woocommerce-gateway-stripe' ); |
|
149 | + $note->set_title(__('Apple Pay domain verification needed', 'woocommerce-gateway-stripe')); |
|
150 | + $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')); |
|
151 | + $note->set_type(WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL); |
|
152 | + $note->set_name(self::FAILURE_NOTE_NAME); |
|
153 | + $note->set_source('woocommerce-gateway-stripe'); |
|
154 | 154 | $note->add_action( |
155 | 155 | 'learn-more', |
156 | - __( 'Learn more', 'woocommerce-gateway-stripe' ), |
|
156 | + __('Learn more', 'woocommerce-gateway-stripe'), |
|
157 | 157 | 'https://docs.woocommerce.com/document/stripe/#apple-pay' |
158 | 158 | ); |
159 | 159 | $note->save(); |
160 | - } catch ( Exception $e ) {} // @codingStandardsIgnoreLine. |
|
160 | + } catch (Exception $e) {} // @codingStandardsIgnoreLine. |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -166,40 +166,40 @@ discard block |
||
166 | 166 | * on/about 2020 Dec 22. |
167 | 167 | */ |
168 | 168 | public static function cleanup_campaign_2020() { |
169 | - if ( ! class_exists( 'Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes') ) { |
|
169 | + if ( ! class_exists('Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes')) { |
|
170 | 170 | return; |
171 | 171 | } |
172 | 172 | |
173 | - if ( ! class_exists( 'WC_Data_Store' ) ) { |
|
173 | + if ( ! class_exists('WC_Data_Store')) { |
|
174 | 174 | return; |
175 | 175 | } |
176 | 176 | |
177 | 177 | $note_ids = array(); |
178 | 178 | |
179 | 179 | try { |
180 | - $data_store = WC_Data_Store::load( 'admin-note' ); |
|
181 | - $note_ids = $data_store->get_notes_with_name( self::SUCCESS_NOTE_NAME ); |
|
182 | - if ( empty( $note_ids ) ) { |
|
180 | + $data_store = WC_Data_Store::load('admin-note'); |
|
181 | + $note_ids = $data_store->get_notes_with_name(self::SUCCESS_NOTE_NAME); |
|
182 | + if (empty($note_ids)) { |
|
183 | 183 | return; |
184 | 184 | } |
185 | - } catch ( Exception $e ) { |
|
185 | + } catch (Exception $e) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
189 | 189 | $deleted_an_unactioned_note = false; |
190 | 190 | |
191 | - foreach ( (array) $note_ids as $note_id ) { |
|
191 | + foreach ((array) $note_ids as $note_id) { |
|
192 | 192 | try { |
193 | - $note = new WC_Admin_Note( $note_id ); |
|
194 | - if ( WC_Admin_Note::E_WC_ADMIN_NOTE_UNACTIONED == $note->get_status() ) { |
|
193 | + $note = new WC_Admin_Note($note_id); |
|
194 | + if (WC_Admin_Note::E_WC_ADMIN_NOTE_UNACTIONED == $note->get_status()) { |
|
195 | 195 | $note->delete(); |
196 | 196 | $deleted_an_unactioned_note = true; |
197 | 197 | } |
198 | - unset( $note ); |
|
199 | - } catch ( Exception $e ) {} // @codingStandardsIgnoreLine. |
|
198 | + unset($note); |
|
199 | + } catch (Exception $e) {} // @codingStandardsIgnoreLine. |
|
200 | 200 | } |
201 | 201 | |
202 | - if ( $deleted_an_unactioned_note ) { |
|
202 | + if ($deleted_an_unactioned_note) { |
|
203 | 203 | self::create_marketing_note(); |
204 | 204 | } |
205 | 205 | } |