@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -18,41 +18,41 @@ discard block |
||
18 | 18 | const POST_SETUP_SUCCESS_ACTION = 'wc_stripe_apple_pay_post_setup_success'; |
19 | 19 | |
20 | 20 | public function __construct() { |
21 | - add_action( self::POST_SETUP_SUCCESS_ACTION, array( self::class, 'create_marketing_note' ) ); |
|
21 | + add_action(self::POST_SETUP_SUCCESS_ACTION, array(self::class, 'create_marketing_note')); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Manage notes to show after Apple Pay domain verification. |
26 | 26 | */ |
27 | - public static function notify_on_apple_pay_domain_verification( $verification_complete ) { |
|
28 | - if ( ! class_exists( 'Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes' ) ) { |
|
27 | + public static function notify_on_apple_pay_domain_verification($verification_complete) { |
|
28 | + if ( ! class_exists('Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes')) { |
|
29 | 29 | return; |
30 | 30 | } |
31 | 31 | |
32 | - if ( ! class_exists( 'WC_Data_Store' ) ) { |
|
32 | + if ( ! class_exists('WC_Data_Store')) { |
|
33 | 33 | return; |
34 | 34 | } |
35 | 35 | |
36 | - if ( $verification_complete ) { |
|
37 | - if ( self::should_show_marketing_note() && ! wp_next_scheduled( self::POST_SETUP_SUCCESS_ACTION ) ) { |
|
38 | - wp_schedule_single_event( time() + DAY_IN_SECONDS, self::POST_SETUP_SUCCESS_ACTION ); |
|
36 | + if ($verification_complete) { |
|
37 | + if (self::should_show_marketing_note() && ! wp_next_scheduled(self::POST_SETUP_SUCCESS_ACTION)) { |
|
38 | + wp_schedule_single_event(time() + DAY_IN_SECONDS, self::POST_SETUP_SUCCESS_ACTION); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | // If the domain verification completed after failure note was created, make sure it's marked as actioned. |
42 | 42 | try { |
43 | - $data_store = WC_Data_Store::load( 'admin-note' ); |
|
44 | - $failure_note_ids = $data_store->get_notes_with_name( self::FAILURE_NOTE_NAME ); |
|
45 | - if ( ! empty( $failure_note_ids ) ) { |
|
46 | - $note_id = array_pop( $failure_note_ids ); |
|
47 | - $note = WC_Admin_Notes::get_note( $note_id ); |
|
48 | - if ( false !== $note && WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status() ) { |
|
49 | - $note->set_status( WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED ); |
|
43 | + $data_store = WC_Data_Store::load('admin-note'); |
|
44 | + $failure_note_ids = $data_store->get_notes_with_name(self::FAILURE_NOTE_NAME); |
|
45 | + if ( ! empty($failure_note_ids)) { |
|
46 | + $note_id = array_pop($failure_note_ids); |
|
47 | + $note = WC_Admin_Notes::get_note($note_id); |
|
48 | + if (false !== $note && WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status()) { |
|
49 | + $note->set_status(WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED); |
|
50 | 50 | $note->save(); |
51 | 51 | } |
52 | 52 | } |
53 | - } catch ( Exception $e ) {} // @codingStandardsIgnoreLine. |
|
53 | + } catch (Exception $e) {} // @codingStandardsIgnoreLine. |
|
54 | 54 | } else { |
55 | - if ( empty( $failure_note_ids ) ) { |
|
55 | + if (empty($failure_note_ids)) { |
|
56 | 56 | self::create_failure_note(); |
57 | 57 | } |
58 | 58 | } |
@@ -64,27 +64,27 @@ discard block |
||
64 | 64 | public static function should_show_marketing_note() { |
65 | 65 | // Display to US merchants only. |
66 | 66 | $base_location = wc_get_base_location(); |
67 | - if ( ! $base_location || 'US' !== $base_location['country'] ) { |
|
67 | + if ( ! $base_location || 'US' !== $base_location['country']) { |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | |
71 | 71 | // Make sure Apple Pay is enabled and setup is successful. |
72 | - $stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
73 | - $stripe_enabled = isset( $stripe_settings['enabled'] ) && 'yes' === $stripe_settings['enabled']; |
|
74 | - $button_enabled = isset( $stripe_settings['payment_request'] ) && 'yes' === $stripe_settings['payment_request']; |
|
75 | - $verification_complete = isset( $stripe_settings['apple_pay_domain_set'] ) && 'yes' === $stripe_settings['apple_pay_domain_set']; |
|
76 | - if ( ! $stripe_enabled || ! $button_enabled || ! $verification_complete ) { |
|
72 | + $stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
73 | + $stripe_enabled = isset($stripe_settings['enabled']) && 'yes' === $stripe_settings['enabled']; |
|
74 | + $button_enabled = isset($stripe_settings['payment_request']) && 'yes' === $stripe_settings['payment_request']; |
|
75 | + $verification_complete = isset($stripe_settings['apple_pay_domain_set']) && 'yes' === $stripe_settings['apple_pay_domain_set']; |
|
76 | + if ( ! $stripe_enabled || ! $button_enabled || ! $verification_complete) { |
|
77 | 77 | return false; |
78 | 78 | } |
79 | 79 | |
80 | 80 | // Make sure note doesn't already exist. |
81 | 81 | try { |
82 | - $data_store = WC_Data_Store::load( 'admin-note' ); |
|
83 | - $success_note_ids = $data_store->get_notes_with_name( self::SUCCESS_NOTE_NAME ); |
|
84 | - if ( ! empty( $success_note_ids ) ) { |
|
82 | + $data_store = WC_Data_Store::load('admin-note'); |
|
83 | + $success_note_ids = $data_store->get_notes_with_name(self::SUCCESS_NOTE_NAME); |
|
84 | + if ( ! empty($success_note_ids)) { |
|
85 | 85 | return false; |
86 | 86 | } |
87 | - } catch ( Exception $e ) { |
|
87 | + } catch (Exception $e) { |
|
88 | 88 | return false; // If unable to check, assume it shouldn't show note. |
89 | 89 | } |
90 | 90 | |
@@ -96,19 +96,19 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public static function create_marketing_note() { |
98 | 98 | // Make sure conditions for this note still hold. |
99 | - if ( ! self::should_show_marketing_note() ) { |
|
99 | + if ( ! self::should_show_marketing_note()) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | 103 | $note = new WC_Admin_Note(); |
104 | - $note->set_title( __( 'Boost sales this holiday season with Apple Pay!', 'woocommerce-gateway-stripe' ) ); |
|
105 | - $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' ) ); |
|
106 | - $note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_MARKETING ); |
|
107 | - $note->set_name( self::SUCCESS_NOTE_NAME ); |
|
108 | - $note->set_source( 'woocommerce-gateway-stripe' ); |
|
104 | + $note->set_title(__('Boost sales this holiday season with Apple Pay!', 'woocommerce-gateway-stripe')); |
|
105 | + $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')); |
|
106 | + $note->set_type(WC_Admin_Note::E_WC_ADMIN_NOTE_MARKETING); |
|
107 | + $note->set_name(self::SUCCESS_NOTE_NAME); |
|
108 | + $note->set_source('woocommerce-gateway-stripe'); |
|
109 | 109 | $note->add_action( |
110 | 110 | 'marketing-guide', |
111 | - __( 'See marketing guide', 'woocommerce-gateway-stripe' ), |
|
111 | + __('See marketing guide', 'woocommerce-gateway-stripe'), |
|
112 | 112 | 'https://developer.apple.com/apple-pay/marketing/' |
113 | 113 | ); |
114 | 114 | $note->save(); |
@@ -119,14 +119,14 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public static function create_failure_note() { |
121 | 121 | $note = new WC_Admin_Note(); |
122 | - $note->set_title( __( 'Apple Pay domain verification needed', 'woocommerce-gateway-stripe' ) ); |
|
123 | - $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' ) ); |
|
124 | - $note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL ); |
|
125 | - $note->set_name( self::FAILURE_NOTE_NAME ); |
|
126 | - $note->set_source( 'woocommerce-gateway-stripe' ); |
|
122 | + $note->set_title(__('Apple Pay domain verification needed', 'woocommerce-gateway-stripe')); |
|
123 | + $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')); |
|
124 | + $note->set_type(WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL); |
|
125 | + $note->set_name(self::FAILURE_NOTE_NAME); |
|
126 | + $note->set_source('woocommerce-gateway-stripe'); |
|
127 | 127 | $note->add_action( |
128 | 128 | 'learn-more', |
129 | - __( 'Learn more', 'woocommerce-gateway-stripe' ), |
|
129 | + __('Learn more', 'woocommerce-gateway-stripe'), |
|
130 | 130 | 'https://docs.woocommerce.com/document/stripe/#apple-pay' |
131 | 131 | ); |
132 | 132 | $note->save(); |