swissChili | f0cbdc3 | 2023-01-05 17:21:38 -0500 | [diff] [blame] | 1 | <?php |
| 2 | /** |
| 3 | * Display a notice to merchants to inform about UPE. |
| 4 | * |
| 5 | * @package WooCommerce\Payments\Admin |
| 6 | */ |
| 7 | |
| 8 | use Automattic\WooCommerce\Admin\Notes\NoteTraits; |
| 9 | use Automattic\WooCommerce\Admin\Notes\Note; |
| 10 | use Automattic\WooCommerce\Admin\Notes\WC_Admin_Note; |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | /** |
| 15 | * Class WC_Stripe_UPE_Availability_Note |
| 16 | */ |
| 17 | class WC_Stripe_UPE_Availability_Note { |
| 18 | use NoteTraits; |
| 19 | |
| 20 | /** |
| 21 | * Name of the note for use in the database. |
| 22 | */ |
| 23 | const NOTE_NAME = 'wc-stripe-upe-availability-note'; |
| 24 | |
| 25 | /** |
| 26 | * Link to enable the UPE in store. |
| 27 | */ |
| 28 | const ENABLE_IN_STORE_LINK = '?page=wc-settings&tab=checkout§ion=stripe&panel=settings&highlight=enable-upe'; |
| 29 | |
| 30 | |
| 31 | /** |
| 32 | * Get the note. |
| 33 | */ |
| 34 | public static function get_note() { |
| 35 | $note_class = self::get_note_class(); |
| 36 | $note = new $note_class(); |
| 37 | |
| 38 | $note->set_title( __( 'Boost your sales with the new payment experience in Stripe', 'woocommerce-gateway-stripe' ) ); |
| 39 | $message = sprintf( |
| 40 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
| 41 | __( 'Get early access to an improved checkout experience, now available to select merchants. %1$sLearn more%2$s.', 'woocommerce-gateway-stripe' ), |
| 42 | '<a href="https://woocommerce.com/document/stripe/#new-checkout-experience" target="_blank">', |
| 43 | '</a>' |
| 44 | ); |
| 45 | $note->set_content( $message ); |
| 46 | $note->set_type( $note_class::E_WC_ADMIN_NOTE_INFORMATIONAL ); |
| 47 | $note->set_name( self::NOTE_NAME ); |
| 48 | $note->set_source( 'woocommerce-gateway-stripe' ); |
| 49 | $note->add_action( |
| 50 | self::NOTE_NAME, |
| 51 | __( 'Enable in your store', 'woocommerce-gateway-stripe' ), |
| 52 | self::ENABLE_IN_STORE_LINK, |
| 53 | $note_class::E_WC_ADMIN_NOTE_UNACTIONED, |
| 54 | true |
| 55 | ); |
| 56 | |
| 57 | return $note; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Get the class type to be used for the note. |
| 62 | * |
| 63 | * @return string |
| 64 | */ |
| 65 | private static function get_note_class() { |
| 66 | if ( class_exists( 'Automattic\WooCommerce\Admin\Notes\Note' ) ) { |
| 67 | return Note::class; |
| 68 | } else { |
| 69 | return WC_Admin_Note::class; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | public static function init() { |
| 74 | /** |
| 75 | * No need to display the admin inbox note when |
| 76 | * - UPE preview is disabled |
| 77 | * - UPE is already enabled |
| 78 | * - UPE has been manually disabled |
| 79 | * - Stripe is not enabled |
| 80 | */ |
| 81 | if ( ! WC_Stripe_Feature_Flags::is_upe_preview_enabled() ) { |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | if ( WC_Stripe_Feature_Flags::is_upe_checkout_enabled() ) { |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | if ( WC_Stripe_Feature_Flags::did_merchant_disable_upe() ) { |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | if ( ! woocommerce_gateway_stripe()->connect->is_connected() ) { |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | $stripe_settings = get_option( 'woocommerce_stripe_settings', [] ); |
| 98 | $stripe_enabled = isset( $stripe_settings['enabled'] ) && 'yes' === $stripe_settings['enabled']; |
| 99 | if ( ! $stripe_enabled ) { |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | self::possibly_add_note(); |
| 104 | } |
| 105 | } |