1
|
|
|
<?php |
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
3
|
|
|
exit; |
4
|
|
|
} |
5
|
|
|
|
6
|
|
|
use Automattic\WooCommerce\Admin\Notes\WC_Admin_Note; |
7
|
|
|
use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class that adds inbox notifications. |
11
|
|
|
* |
12
|
|
|
* @since 4.5.4 |
13
|
|
|
*/ |
14
|
|
|
class WC_Stripe_Inbox_Notes { |
15
|
|
|
const NOTE_NAME = 'stripe-apple-pay-domain-verification'; |
16
|
|
|
|
17
|
|
|
// TODO Call this only after domain verification has a chance to run |
18
|
|
|
public static function notify_of_apple_pay_domain_verification_if_needed() { |
19
|
|
|
if ( ! class_exists( 'Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes' ) ) { |
20
|
|
|
return; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
if ( ! class_exists( 'WC_Data_Store' ) ) { |
24
|
|
|
return; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
28
|
|
|
$domain_flag_key = 'apple_pay_domain_set'; |
29
|
|
|
$verification_complete = isset( $stripe_settings[ $domain_flag_key ] ) && 'yes' === $stripe_settings[ $domain_flag_key ]; |
30
|
|
|
|
31
|
|
|
// Only show if in the US. |
32
|
|
|
$base_location = wc_get_base_location(); |
33
|
|
|
if ( ! $base_location || 'US' !== $base_location['country'] ) { |
34
|
|
|
return; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$data_store = WC_Data_Store::load( 'admin-note' ); |
38
|
|
|
|
39
|
|
|
// First, see if we've already created this kind of note so we don't do it again. |
40
|
|
|
$note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); |
41
|
|
|
if ( ! empty( $note_ids ) ) { |
42
|
|
|
$note_id = array_pop( $note_ids ); |
43
|
|
|
$note = WC_Admin_Notes::get_note( $note_id ); |
44
|
|
|
if ( false === $note ) { |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// If the domain verification completed after the note was created, make sure it's marked as actioned. |
49
|
|
|
if ( $verification_complete && WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status() ) { |
50
|
|
|
$note->set_status( WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED ); |
51
|
|
|
$note->save(); |
52
|
|
|
} |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$note = new WC_Admin_Note(); |
57
|
|
|
$note->set_title( __( 'Apple Pay domain verification needed', 'woocommerce-admin' ) ); |
58
|
|
|
$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 will need to be in place before Apple Pay will be functional for your customers.', 'woocommerce-admin' ) ); |
59
|
|
|
$note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL ); |
60
|
|
|
$note->set_name( self::NOTE_NAME ); |
61
|
|
|
$note->set_source( 'woocommerce-admin' ); |
62
|
|
|
$note->add_action( |
63
|
|
|
'learn-more', |
64
|
|
|
__( 'Learn more', 'woocommerce-admin' ), |
65
|
|
|
'https://docs.woocommerce.com/document/stripe/#apple-pay' |
66
|
|
|
); |
67
|
|
|
$note->save(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|