Skip to content

Commit c9b8091

Browse files
wjrosadiegocurbelo
andauthored
Adding a promotional note for BNPLs (#4441)
* Adding a promotional note for BNPLs * Changelog and readme entries * Unit test * Renaming variable in loop to avoid override * Fix changelog entry * Replacing the gateway ID check condition with an in_array call * Update includes/notes/class-wc-stripe-bnpl-promotion-note.php Co-authored-by: Diego Curbelo <[email protected]> --------- Co-authored-by: Diego Curbelo <[email protected]>
1 parent ff518d2 commit c9b8091

File tree

6 files changed

+160
-2
lines changed

6 files changed

+160
-2
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.6.0 - xxxx-xx-xx =
4+
* Add - Introduces a new marketing note to promote BNPLs (Buy Now Pay Later) payment methods (Klarna and Affirm) on WooCommerce admin home page
45
* Fix - Fixes some inconsistencies related to the Optimized Checkout feature and improves its unit tests
56
* Fix - Throws a specific exception on an edge case where a saved payment method could not be found when processing an order in the new checkout experience
67
* Fix - Checks if the store has other BNPL extensions installed before displaying the promotional banner

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public static function are_inbox_notes_supported() {
4646
return trait_exists( 'Automattic\WooCommerce\Admin\Notes\NoteTraits' ) && class_exists( 'Automattic\WooCommerce\Admin\Notes\Note' );
4747
}
4848

49+
/**
50+
* Create UPE notes.
51+
*/
4952
public static function create_upe_notes() {
5053
if ( ! self::are_inbox_notes_supported() ) {
5154
return;
@@ -54,8 +57,13 @@ public static function create_upe_notes() {
5457
require_once WC_STRIPE_PLUGIN_PATH . '/includes/notes/class-wc-stripe-upe-availability-note.php';
5558
WC_Stripe_UPE_Availability_Note::init();
5659

60+
$gateway = WC_Stripe::get_instance()->get_main_stripe_gateway();
61+
5762
require_once WC_STRIPE_PLUGIN_PATH . '/includes/notes/class-wc-stripe-upe-stripelink-note.php';
58-
WC_Stripe_UPE_StripeLink_Note::init( WC_Stripe::get_instance()->get_main_stripe_gateway() );
63+
WC_Stripe_UPE_StripeLink_Note::init( $gateway );
64+
65+
require_once WC_STRIPE_PLUGIN_PATH . '/includes/notes/class-wc-stripe-bnpl-promotion-note.php';
66+
WC_Stripe_BNPL_Promotion_Note::init( $gateway );
5967
}
6068

6169
public static function get_campaign_2020_cutoff() {
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/**
3+
* Display a notice to merchants to promote BNPL (Buy Now Pay Later) payment methods.
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_BNPL_Promotion_Note
16+
*/
17+
class WC_Stripe_BNPL_Promotion_Note {
18+
use NoteTraits;
19+
20+
/**
21+
* Name of the note for use in the database.
22+
*/
23+
const NOTE_NAME = 'wc-stripe-bnpl-promotion-note';
24+
25+
/**
26+
* Link to enable the UPE in store.
27+
*/
28+
const LEARN_MORE_LINK = 'https://woocommerce.com/document/stripe/setup-and-configuration/additional-payment-methods/';
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( __( 'Offer more ways to pay with Buy Now, Pay Later', 'woocommerce-gateway-stripe' ) );
38+
$message = __( 'Flexible pay-over-time options can boost revenue by up to 14%.* Affirm and Klarna payments are auto-enabled with Stripe for eligible merchants.', 'woocommerce-gateway-stripe' );
39+
$message .= '<br /><br />';
40+
$message .= __( '*Source: Stripe 2024', 'woocommerce-gateway-stripe' );
41+
$note->set_content( $message );
42+
$note->set_type( $note_class::E_WC_ADMIN_NOTE_MARKETING );
43+
$note->set_name( self::NOTE_NAME );
44+
$note->set_source( 'woocommerce-gateway-stripe' );
45+
$note->add_action(
46+
self::NOTE_NAME,
47+
__( 'Learn more', 'woocommerce-gateway-stripe' ),
48+
self::LEARN_MORE_LINK,
49+
$note_class::E_WC_ADMIN_NOTE_UNACTIONED,
50+
true
51+
);
52+
53+
return $note;
54+
}
55+
56+
/**
57+
* Get the class type to be used for the note.
58+
*
59+
* @return string
60+
*/
61+
private static function get_note_class() {
62+
if ( class_exists( 'Automattic\WooCommerce\Admin\Notes\Note' ) ) {
63+
return Note::class;
64+
} else {
65+
return WC_Admin_Note::class;
66+
}
67+
}
68+
69+
/**
70+
* Init BNPL promotion notification
71+
*
72+
* @param WC_Stripe_Payment_Gateway $gateway
73+
*
74+
* @return void
75+
* @throws \Automattic\WooCommerce\Admin\Notes\NotesUnavailableException
76+
*/
77+
public static function init( WC_Stripe_Payment_Gateway $gateway ) {
78+
/**
79+
* No need to display the admin inbox note when
80+
* - Below version 9.7
81+
* - Store has any BNPLs enabled
82+
* - Other BNPL extensions are active
83+
* - Stripe is not enabled
84+
*/
85+
if ( ! defined( 'WC_STRIPE_VERSION' ) || version_compare( WC_STRIPE_VERSION, '9.7', '<' ) ) {
86+
return;
87+
}
88+
89+
$available_upe_payment_methods = $gateway->get_upe_enabled_payment_method_ids();
90+
foreach ( WC_Stripe_Payment_Methods::BNPL_PAYMENT_METHODS as $bnpl_payment_method ) {
91+
if ( in_array( $bnpl_payment_method, $available_upe_payment_methods, true ) ) {
92+
return;
93+
}
94+
}
95+
96+
$has_other_bnpl_plugins_active = false;
97+
$available_payment_gateways = WC()->payment_gateways->payment_gateways;
98+
$other_bnpl_gateway_ids = [ 'affirm', 'klarna_payments' ];
99+
foreach ( $available_payment_gateways as $available_payment_gateway ) {
100+
if ( in_array( $available_payment_gateway->id, $other_bnpl_gateway_ids, true ) && 'yes' === $available_payment_gateway->enabled ) {
101+
$has_other_bnpl_plugins_active = true;
102+
break;
103+
}
104+
}
105+
if ( $has_other_bnpl_plugins_active ) {
106+
return;
107+
}
108+
109+
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
110+
$stripe_enabled = isset( $stripe_settings['enabled'] ) && 'yes' === $stripe_settings['enabled'];
111+
if ( ! $stripe_enabled ) {
112+
return;
113+
}
114+
115+
self::possibly_add_note();
116+
}
117+
}

readme.txt

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

113113
= 9.6.0 - xxxx-xx-xx =
114114

115+
* Add - Introduces a new marketing note to promote BNPLs (Buy Now Pay Later) payment methods (Klarna and Affirm) on WooCommerce admin home page
115116
* Fix - Fixes some inconsistencies related to the Optimized Checkout feature and improves its unit tests
116117
* Fix - Throws a specific exception on an edge case where a saved payment method could not be found when processing an order in the new checkout experience
117118
* Fix - Checks if the store has other BNPL extensions installed before displaying the promotional banner
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_BNPL_Promotion_Note;
6+
use WP_UnitTestCase;
7+
8+
/**
9+
* Class WC_Stripe_BNPL_Promotion_Note_Test
10+
*
11+
* @package WooCommerce/Stripe/WC_Stripe_BNPL_Promotion_Note
12+
*
13+
* Class WC_Stripe_BNPL_Promotion_Note tests.
14+
*/
15+
class WC_Stripe_BNPL_Promotion_Note_Test extends WP_UnitTestCase {
16+
public function test_get_note() {
17+
require_once WC_STRIPE_PLUGIN_PATH . '/includes/notes/class-wc-stripe-bnpl-promotion-note.php';
18+
$note = WC_Stripe_BNPL_Promotion_Note::get_note();
19+
20+
$this->assertSame( 'Offer more ways to pay with Buy Now, Pay Later', $note->get_title() );
21+
$this->assertSame( 'Flexible pay-over-time options can boost revenue by up to 14%.* Affirm and Klarna payments are auto-enabled with Stripe for eligible merchants.<br /><br />*Source: Stripe 2024', $note->get_content() );
22+
$this->assertSame( 'marketing', $note->get_type() );
23+
$this->assertSame( 'wc-stripe-bnpl-promotion-note', $note->get_name() );
24+
$this->assertSame( 'woocommerce-gateway-stripe', $note->get_source() );
25+
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 );
30+
}
31+
}

tests/phpunit/WC_Stripe_UPE_Availability_Note_Test.php renamed to tests/phpunit/Notes/WC_Stripe_UPE_Availability_Note_Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace WooCommerce\Stripe\Tests;
3+
namespace WooCommerce\Stripe\Tests\Notes;
44

55
use WC_Stripe_UPE_Availability_Note;
66
use WP_UnitTestCase;

0 commit comments

Comments
 (0)