Completed
Pull Request — master (#1337)
by
unknown
01:52
created

WC_Stripe_Inbox_Notes   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 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
	// 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
		$data_store = WC_Data_Store::load( 'admin-note' );
32
33
		// First, see if we've already created this kind of note so we don't do it again.
34
		$note_ids = $data_store->get_notes_with_name( self::NOTE_NAME );
35
		if ( ! empty( $note_ids ) ) {
36
			$note_id = array_pop( $note_ids );
37
			$note    = WC_Admin_Notes::get_note( $note_id );
38
			if ( false === $note ) {
39
				return;
40
			}
41
42
			// If the domain verification completed after the note was created, make sure it's marked as actioned.
43
			if ( $verification_complete && WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status() ) {
44
				$note->set_status( WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED );
45
				$note->save();
46
			}
47
			return;
48
		}
49
50
		$note = new WC_Admin_Note();
51
		$note->set_title( __( 'Apple Pay domain verification needed', 'woocommerce-admin' ) );
52
		$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' ) );
53
		$note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
54
		$note->set_name( self::NOTE_NAME );
55
		$note->set_source( 'woocommerce-admin' );
56
		$note->add_action(
57
			'learn-more',
58
			__( 'Learn more', 'woocommerce-admin' ),
59
			'https://docs.woocommerce.com/document/stripe/#apple-pay'
60
		);
61
		$note->save();
62
	}
63
}
64