Skip to content

Commit 8daa5f6

Browse files
wjrosamalithsen
andauthored
Introducing a note to promote OC (#4493)
* Introducing a note to promote OC * Including note class * Changelog and readme entries * Fix learn more link * Fix learn more link * Unit test * Removing note when OC is enabled --------- Co-authored-by: Malith Senaweera <[email protected]>
1 parent ccf944e commit 8daa5f6

7 files changed

+147
-5
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 9.7.0 - xxxx-xx-xx =
4+
* Add - Introduces a new inbox note to promote the Optimized Checkout feature on version 9.8 and later
45
* Update - Removes BNPL payment methods (Klarna and Affirm) when other official plugins are active
56
* Fix - Moves the existing order lock functionality earlier in the order processing flow to prevent duplicate processing requests
67
* Add - Adds two new safety filters to the subscriptions detached debug tool: `wc_stripe_detached_subscriptions_maximum_time` and `wc_stripe_detached_subscriptions_maximum_count`

includes/admin/class-wc-stripe-inbox-notes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public static function create_upe_notes() {
6464

6565
require_once WC_STRIPE_PLUGIN_PATH . '/includes/notes/class-wc-stripe-bnpl-promotion-note.php';
6666
WC_Stripe_BNPL_Promotion_Note::init( $gateway );
67+
68+
require_once WC_STRIPE_PLUGIN_PATH . '/includes/notes/class-wc-stripe-oc-promotion-note.php';
69+
WC_Stripe_OC_Promotion_Note::init( $gateway );
6770
}
6871

6972
public static function get_campaign_2020_cutoff() {

includes/notes/class-wc-stripe-bnpl-promotion-note.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class WC_Stripe_BNPL_Promotion_Note {
2323
const NOTE_NAME = 'wc-stripe-bnpl-promotion-note';
2424

2525
/**
26-
* Link to enable the UPE in store.
26+
* Link to learn more about BNPLs.
2727
*/
2828
const LEARN_MORE_LINK = 'https://woocommerce.com/document/stripe/setup-and-configuration/additional-payment-methods/';
2929

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* Display a notice to merchants to promote OC (Optimized Checkout).
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_OC_Promotion_Note
16+
*/
17+
class WC_Stripe_OC_Promotion_Note {
18+
use NoteTraits;
19+
20+
/**
21+
* Name of the note for use in the database.
22+
*/
23+
const NOTE_NAME = 'wc-stripe-oc-promotion-note';
24+
25+
/**
26+
* Link to learn more about OC.
27+
*/
28+
const LEARN_MORE_LINK = 'https://woocommerce.com/document/stripe/admin-experience/optimized-checkout-suite/';
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 conversions with Stripe\'s Optimized Checkout Suite', 'woocommerce-gateway-stripe' ) );
38+
$note->set_content( __( 'Optimize your checkout for more sales by automatically displaying the most relevant payment methods for each customer.', 'woocommerce-gateway-stripe' ) );
39+
$note->set_type( $note_class::E_WC_ADMIN_NOTE_MARKETING );
40+
$note->set_name( self::NOTE_NAME );
41+
$note->set_source( 'woocommerce-gateway-stripe' );
42+
$note->add_action(
43+
self::NOTE_NAME,
44+
__( 'Learn more', 'woocommerce-gateway-stripe' ),
45+
self::LEARN_MORE_LINK,
46+
$note_class::E_WC_ADMIN_NOTE_UNACTIONED,
47+
true
48+
);
49+
50+
return $note;
51+
}
52+
53+
/**
54+
* Get the class type to be used for the note.
55+
*
56+
* @return string
57+
*/
58+
private static function get_note_class() {
59+
if ( class_exists( 'Automattic\WooCommerce\Admin\Notes\Note' ) ) {
60+
return Note::class;
61+
} else {
62+
return WC_Admin_Note::class;
63+
}
64+
}
65+
66+
/**
67+
* Init OC promotion notification
68+
*
69+
* @param WC_Stripe_Payment_Gateway $gateway
70+
*
71+
* @return void
72+
* @throws \Automattic\WooCommerce\Admin\Notes\NotesUnavailableException
73+
*/
74+
public static function init( WC_Stripe_Payment_Gateway $gateway ) {
75+
/**
76+
* No need to display the admin inbox note when
77+
* - Below version 9.8
78+
* - OC is already enabled
79+
* - Stripe is not enabled
80+
*/
81+
if ( ! defined( 'WC_STRIPE_VERSION' ) || version_compare( WC_STRIPE_VERSION, '9.8', '<' ) ) {
82+
return;
83+
}
84+
85+
if ( $gateway->is_oc_enabled() ) {
86+
return;
87+
}
88+
89+
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
90+
$stripe_enabled = isset( $stripe_settings['enabled'] ) && 'yes' === $stripe_settings['enabled'];
91+
if ( ! $stripe_enabled ) {
92+
return;
93+
}
94+
95+
self::possibly_add_note();
96+
}
97+
98+
/**
99+
* Should this note exist?
100+
*
101+
* @inheritDoc
102+
*/
103+
public static function is_applicable() {
104+
return ! WC_Stripe::get_instance()->get_main_stripe_gateway()->is_oc_enabled();
105+
}
106+
}

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
111111
== Changelog ==
112112

113113
= 9.7.0 - xxxx-xx-xx =
114+
* Add - Introduces a new inbox note to promote the Optimized Checkout feature on version 9.8 and later
114115
* Update - Removes BNPL payment methods (Klarna and Affirm) when other official plugins are active
115116
* Fix - Moves the existing order lock functionality earlier in the order processing flow to prevent duplicate processing requests
116117
* Add - Adds two new safety filters to the subscriptions detached debug tool: `wc_stripe_detached_subscriptions_maximum_time` and `wc_stripe_detached_subscriptions_maximum_count`

tests/phpunit/Notes/WC_Stripe_BNPL_Promotion_Note_Test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public function test_get_note() {
2323
$this->assertSame( 'wc-stripe-bnpl-promotion-note', $note->get_name() );
2424
$this->assertSame( 'woocommerce-gateway-stripe', $note->get_source() );
2525

26-
list( $enable_upe_action ) = $note->get_actions();
27-
$this->assertSame( 'wc-stripe-bnpl-promotion-note', $enable_upe_action->name );
28-
$this->assertSame( 'Learn more', $enable_upe_action->label );
29-
$this->assertSame( 'https://woocommerce.com/document/stripe/setup-and-configuration/additional-payment-methods/', $enable_upe_action->query );
26+
list( $learn_more_action ) = $note->get_actions();
27+
$this->assertSame( 'wc-stripe-bnpl-promotion-note', $learn_more_action->name );
28+
$this->assertSame( 'Learn more', $learn_more_action->label );
29+
$this->assertSame( 'https://woocommerce.com/document/stripe/setup-and-configuration/additional-payment-methods/', $learn_more_action->query );
3030
}
3131
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace WooCommerce\Stripe\Tests\Notes;
4+
5+
use WC_Stripe_OC_Promotion_Note;
6+
use WP_UnitTestCase;
7+
8+
/**
9+
* Class WC_Stripe_OC_Promotion_Note_Test
10+
*
11+
* @package WooCommerce/Stripe/WC_Stripe_OC_Promotion_Note
12+
*
13+
* Class WC_Stripe_OC_Promotion_Note tests.
14+
*/
15+
class WC_Stripe_OC_Promotion_Note_Test extends WP_UnitTestCase {
16+
public function test_get_note() {
17+
require_once WC_STRIPE_PLUGIN_PATH . '/includes/notes/class-wc-stripe-oc-promotion-note.php';
18+
$note = WC_Stripe_OC_Promotion_Note::get_note();
19+
20+
$this->assertSame( 'Increase conversions with Stripe\'s Optimized Checkout Suite', $note->get_title() );
21+
$this->assertSame( 'Optimize your checkout for more sales by automatically displaying the most relevant payment methods for each customer.', $note->get_content() );
22+
$this->assertSame( 'marketing', $note->get_type() );
23+
$this->assertSame( 'wc-stripe-oc-promotion-note', $note->get_name() );
24+
$this->assertSame( 'woocommerce-gateway-stripe', $note->get_source() );
25+
26+
list( $learn_more_action ) = $note->get_actions();
27+
$this->assertSame( 'wc-stripe-oc-promotion-note', $learn_more_action->name );
28+
$this->assertSame( 'Learn more', $learn_more_action->label );
29+
$this->assertSame( 'https://woocommerce.com/document/stripe/admin-experience/optimized-checkout-suite/', $learn_more_action->query );
30+
}
31+
}

0 commit comments

Comments
 (0)