swissChili | f0cbdc3 | 2023-01-05 17:21:38 -0500 | [diff] [blame] | 1 | <?php |
| 2 | /** |
| 3 | * Display a notice to merchants to inform about Stripe Link. |
| 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_StripeLink_Note |
| 16 | */ |
| 17 | class WC_Stripe_UPE_StripeLink_Note { |
| 18 | use NoteTraits; |
| 19 | |
| 20 | /** |
| 21 | * Name of the note for use in the database. |
| 22 | */ |
| 23 | const NOTE_NAME = 'wc-stripe-upe-stripelink-note'; |
| 24 | |
| 25 | /** |
| 26 | * Link to Stripe Link documentation. |
| 27 | */ |
| 28 | const NOTE_DOCUMENTATION_URL = 'https://woocommerce.com/document/stripe/#stripe-link'; |
| 29 | |
| 30 | /** |
| 31 | * Get the note. |
| 32 | */ |
| 33 | public static function get_note() { |
| 34 | $note_class = self::get_note_class(); |
| 35 | $note = new $note_class(); |
| 36 | |
| 37 | $note->set_title( __( 'Increase conversion at checkout', 'woocommerce-gateway-stripe' ) ); |
| 38 | $note->set_content( __( 'Reduce cart abandonment and create a frictionless checkout experience with Link by Stripe. Link autofills your customer’s payment and shipping details so they can check out in just six seconds with the Link optimized experience.', 'woocommerce-gateway-stripe' ) ); |
| 39 | |
| 40 | $note->set_type( $note_class::E_WC_ADMIN_NOTE_INFORMATIONAL ); |
| 41 | $note->set_name( self::NOTE_NAME ); |
| 42 | $note->set_source( 'woocommerce-gateway-stripe' ); |
| 43 | $note->add_action( |
| 44 | self::NOTE_NAME, |
| 45 | __( 'Set up now', 'woocommerce-gateway-stripe' ), |
| 46 | self::NOTE_DOCUMENTATION_URL, |
| 47 | $note_class::E_WC_ADMIN_NOTE_UNACTIONED, |
| 48 | true |
| 49 | ); |
| 50 | |
| 51 | return $note; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Get the class type to be used for the note. |
| 56 | * |
| 57 | * @return string |
| 58 | */ |
| 59 | private static function get_note_class() { |
| 60 | if ( class_exists( 'Automattic\WooCommerce\Admin\Notes\Note' ) ) { |
| 61 | return Note::class; |
| 62 | } else { |
| 63 | return WC_Admin_Note::class; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Init Link payment method notification |
| 69 | * |
| 70 | * @param WC_Stripe_Payment_Gateway $gateway |
| 71 | * |
| 72 | * @return void |
| 73 | * @throws \Automattic\WooCommerce\Admin\Notes\NotesUnavailableException |
| 74 | */ |
| 75 | public static function init( WC_Stripe_Payment_Gateway $gateway ) { |
| 76 | if ( ! WC_Stripe_Feature_Flags::is_upe_checkout_enabled() ) { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | // Check if Link payment is available. |
| 81 | $available_upe_payment_methods = $gateway->get_upe_available_payment_methods(); |
| 82 | |
| 83 | if ( ! in_array( WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID, $available_upe_payment_methods, true ) ) { |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | if ( ! is_a( $gateway, 'WC_Stripe_UPE_Payment_Gateway' ) ) { |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | // If store currency is not USD, skip |
| 92 | if ( 'USD' !== get_woocommerce_currency() ) { |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | // Retrieve enabled payment methods at checkout. |
| 97 | $enabled_payment_methods = $gateway->get_upe_enabled_at_checkout_payment_method_ids(); |
| 98 | // If card payment method is not enabled, skip. If Link payment method is enabled, skip. |
| 99 | if ( |
| 100 | ! in_array( WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID, $enabled_payment_methods, true ) || |
| 101 | in_array( WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID, $enabled_payment_methods, true ) |
| 102 | ) { |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | self::possibly_add_note(); |
| 107 | } |
| 108 | } |