Completed
Pull Request — master (#1337)
by
unknown
02:39 queued 54s
created

WC_Stripe_Inbox_Notes   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 49
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B notify_of_apple_pay_domain_verification_if_needed() 0 45 8
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
	public static function notify_of_apple_pay_domain_verification_if_needed() {
18
		if ( ! class_exists( 'Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes' ) ) {
19
			return;
20
		}
21
22
		if ( ! class_exists( 'WC_Data_Store' ) ) {
23
			return;
24
		}
25
26
		$stripe_settings       = get_option( 'woocommerce_stripe_settings', array() );
27
		$domain_flag_key       = 'apple_pay_domain_set';
28
		$verification_complete = isset( $stripe_settings[ $domain_flag_key ] ) && 'yes' === $stripe_settings[ $domain_flag_key ];
29
30
		$data_store = WC_Data_Store::load( 'admin-note' );
31
32
		// First, see if we've already created this kind of note so we don't do it again.
33
		$note_ids = $data_store->get_notes_with_name( self::NOTE_NAME );
34
		if ( ! empty( $note_ids ) ) {
35
			$note_id = array_pop( $note_ids );
36
			$note    = WC_Admin_Notes::get_note( $note_id );
37
			if ( false === $note ) {
38
				return;
39
			}
40
41
			// If the domain verification completed after the note was created, make sure it's marked as actioned.
42
			if ( $verification_complete && WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status() ) {
43
				$note->set_status( WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED );
44
				$note->save();
45
			}
46
			return;
47
		}
48
49
		$note = new WC_Admin_Note();
50
		$note->set_title( __( 'Apple Pay domain verification needed', 'woocommerce-admin' ) );
51
		$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-admin' ) );
52
		$note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
53
		$note->set_name( self::NOTE_NAME );
54
		$note->set_source( 'woocommerce-admin' );
55
		$note->add_action(
56
			'learn-more',
57
			__( 'Learn more', 'woocommerce-admin' ),
58
			'https://docs.woocommerce.com/document/stripe/#apple-pay'
59
		);
60
		$note->save();
61
	}
62
}
63