Skip to content

Commit fe84136

Browse files
mordethvladolaru
andauthored
Show Activate payments notice in WooPayments Settings only for test accounts (#10978)
Co-authored-by: Vlad Olaru <[email protected]> Co-authored-by: Vlad Olaru <[email protected]>
1 parent 46acfca commit fe84136

File tree

4 files changed

+613
-27
lines changed

4 files changed

+613
-27
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fix
3+
4+
Show Activate payments notice in WooPayments Settings only for test accounts.

includes/admin/class-wc-payments-admin-settings.php

Lines changed: 174 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ class WC_Payments_Admin_Settings {
1717
*/
1818
private $gateway;
1919

20+
/**
21+
* Instance of WC_Payments_Account
22+
*
23+
* @var WC_Payments_Account
24+
*/
25+
private $account;
26+
2027
/**
2128
* Set of parameters to build the URL to the gateway's settings page.
2229
*
@@ -32,9 +39,11 @@ class WC_Payments_Admin_Settings {
3239
* Initialize class actions.
3340
*
3441
* @param WC_Payment_Gateway_WCPay $gateway Payment Gateway.
42+
* @param WC_Payments_Account $account The account service.
3543
*/
36-
public function __construct( WC_Payment_Gateway_WCPay $gateway ) {
44+
public function __construct( WC_Payment_Gateway_WCPay $gateway, WC_Payments_Account $account ) {
3745
$this->gateway = $gateway;
46+
$this->account = $account;
3847
}
3948

4049
/**
@@ -43,44 +52,132 @@ public function __construct( WC_Payment_Gateway_WCPay $gateway ) {
4352
* @return void
4453
*/
4554
public function init_hooks() {
46-
add_action( 'woocommerce_woocommerce_payments_admin_notices', [ $this, 'display_test_mode_notice' ] );
55+
add_action( 'woocommerce_woocommerce_payments_admin_notices', [ $this, 'maybe_show_test_mode_notice' ] );
56+
add_action( 'woocommerce_woocommerce_payments_admin_notices', [ $this, 'maybe_show_test_account_notice' ] );
57+
add_action( 'woocommerce_woocommerce_payments_admin_notices', [ $this, 'maybe_show_sandbox_account_notice' ] );
4758
add_filter( 'plugin_action_links_' . plugin_basename( WCPAY_PLUGIN_FILE ), [ $this, 'add_plugin_links' ] );
4859
}
4960

5061
/**
51-
* Add notice explaining test mode when it's enabled.
62+
* Add notice about payments being in test mode when using a live account.
63+
*
64+
* This notice is mutually exclusive with the test account and sandbox account notices.
65+
*
66+
* @see self::maybe_show_test_account_notice()
67+
* @see self::maybe_show_sandbox_account_notice()
5268
*/
53-
public function display_test_mode_notice() {
54-
if ( WC_Payments::mode()->is_test() ) {
55-
?>
56-
<div id="wcpay-test-mode-notice" class="notice notice-warning">
57-
<p>
58-
<b><?php esc_html_e( 'You are using a test account. ', 'woocommerce-payments' ); ?></b>
69+
public function maybe_show_test_mode_notice() {
70+
// If there is no valid account connected, bail.
71+
if ( ! $this->gateway->is_connected() || ! $this->account->is_stripe_account_valid() ) {
72+
return;
73+
}
74+
75+
// If this is not a live account, bail since we will inform the user about the test account instead.
76+
if ( ! $this->account->get_is_live() ) {
77+
return;
78+
}
79+
80+
// If the test mode is not enabled, bail.
81+
if ( ! WC_Payments::mode()->is_test() ) {
82+
return;
83+
}
84+
85+
// Output the notice.
86+
?>
87+
<div id="wcpay-test-mode-notice" class="notice notice-warning">
88+
<p>
89+
<b>
5990
<?php
6091
printf(
61-
wp_kses_post(
62-
/* translators: %s: URL to learn more */
63-
__( 'Provide additional details about your business so you can begin accepting real payments. <a href="%s" target="_blank" rel="noreferrer noopener">Learn more</a>', 'woocommerce-payments' ),
64-
),
65-
esc_url( 'https://woocommerce.com/document/woopayments/startup-guide/#sign-up-process' )
92+
/* translators: %s: WooPayments */
93+
esc_html__( '%s is in test mode — all transactions are simulated!', 'woocommerce-payments' ) . ' ',
94+
'WooPayments'
6695
);
6796
?>
68-
</p>
97+
</b>
98+
<?php
99+
printf(
100+
/* translators: 1: Anchor opening tag; 2: Anchor closing tag */
101+
esc_html__( 'You can use %1$stest card numbers%2$s to simulate various types of transactions.', 'woocommerce-payments' ),
102+
'<a href="' . esc_url( 'https://woocommerce.com/document/woopayments/testing-and-troubleshooting/testing/#test-cards' ) . '" target="_blank" rel="noreferrer noopener">',
103+
'</a>'
104+
);
105+
?>
106+
</p>
107+
</div>
108+
<?php
109+
}
110+
111+
/**
112+
* Add notice to activate payments when a test account is in use.
113+
*
114+
* This notice is mutually exclusive with the test mode and sandbox account notices.
115+
*
116+
* @see self::maybe_show_test_mode_notice()
117+
* @see self::maybe_show_sandbox_account_notice()
118+
*/
119+
public function maybe_show_test_account_notice() {
120+
// If there is no valid account connected, bail.
121+
if ( ! $this->gateway->is_connected() || ! $this->account->is_stripe_account_valid() ) {
122+
return;
123+
}
124+
125+
// If this is a live account, bail.
126+
if ( $this->account->get_is_live() ) {
127+
return;
128+
}
129+
130+
// If this is NOT a test [drive] account, bail.
131+
$account_status = $this->account->get_account_status_data();
132+
if ( empty( $account_status['testDrive'] ) ) {
133+
return;
134+
}
135+
136+
// Output the notice.
137+
?>
138+
<div id="wcpay-test-account-notice" class="notice notice-warning">
139+
<p>
140+
<b><?php echo esc_html__( 'You are using a test account.', 'woocommerce-payments' ) . ' '; ?></b>
141+
<?php
142+
if ( ! WC_Payments::mode()->is_dev() ) {
143+
printf(
144+
/* translators: %s: URL to learn more */
145+
esc_html__( 'Provide additional details about your business so you can begin accepting real payments. %1$sLearn more%2$s', 'woocommerce-payments' ),
146+
'<a href="' . esc_url( 'https://woocommerce.com/document/woopayments/startup-guide/#sign-up-process' ) . '" target="_blank" rel="noreferrer noopener">',
147+
'</a>'
148+
);
149+
} else {
150+
esc_html_e( '⚠️ Development mode is enabled for the store! There can be no live onboarding process while using development, testing, or staging WordPress environments!', 'woocommerce-payments' );
151+
echo '</br>';
152+
printf(
153+
/* translators: 1: Anchor opening tag; 2: Anchor closing tag; 3: Anchor opening tag; 4: Anchor closing tag */
154+
esc_html__( 'To begin accepting real payments, please go to the live store or change your %1$sWordPress environment%2$s to a production one. %3$sLearn more%4$s', 'woocommerce-payments' ),
155+
'<a href="' . esc_url( 'https://make.wordpress.org/core/2020/08/27/wordpress-environment-types/' ) . '" target="_blank" rel="noreferrer noopener">',
156+
'</a>',
157+
'<a href="' . esc_url( 'https://woocommerce.com/document/woopayments/testing-and-troubleshooting/test-accounts/#developer-notes' ) . '" target="_blank" rel="noreferrer noopener">',
158+
'</a>'
159+
);
160+
}
161+
?>
162+
</p>
163+
<?php if ( ! WC_Payments::mode()->is_dev() ) { ?>
69164
<p>
70165
<a id="wcpay-activate-payments-button" href="#" class="button button-secondary">
71166
<?php esc_html_e( 'Activate payments', 'woocommerce-payments' ); ?>
72167
</a>
73168
</p>
74-
</div>
169+
<?php } ?>
170+
</div>
171+
<?php if ( ! WC_Payments::mode()->is_dev() ) { ?>
75172
<script type="text/javascript">
76173
// We dispatch an event to trigger the modal.
77174
// The listener is in the general-settings/index.js file.
78-
document.addEventListener( 'DOMContentLoaded', function() {
175+
document.addEventListener( 'DOMContentLoaded', function () {
79176
var activateButton = document.getElementById( 'wcpay-activate-payments-button' );
80-
if ( ! activateButton ) {
177+
if ( !activateButton ) {
81178
return;
82179
}
83-
activateButton.addEventListener( 'click', function( e ) {
180+
activateButton.addEventListener( 'click', function ( e ) {
84181
e.preventDefault();
85182
document.dispatchEvent( new CustomEvent( 'wcpay:activate_payments' ) );
86183
} );
@@ -90,6 +187,64 @@ public function display_test_mode_notice() {
90187
}
91188
}
92189

190+
/**
191+
* Add notice to inform that a sandbox account is in use.
192+
*
193+
* This notice is mutually exclusive with the test mode and test account notices.
194+
*
195+
* @see self::maybe_show_test_mode_notice()
196+
* @see self::maybe_show_test_account_notice()
197+
*/
198+
public function maybe_show_sandbox_account_notice() {
199+
// If there is no valid account connected, bail.
200+
if ( ! $this->gateway->is_connected() || ! $this->account->is_stripe_account_valid() ) {
201+
return;
202+
}
203+
204+
// If this is a live account, bail.
205+
if ( $this->account->get_is_live() ) {
206+
return;
207+
}
208+
209+
// If this is a test [drive] account, bail.
210+
$account_status = $this->account->get_account_status_data();
211+
if ( ! empty( $account_status['testDrive'] ) ) {
212+
return;
213+
}
214+
215+
// Output the notice.
216+
?>
217+
<div id="wcpay-test-account-notice" class="notice notice-warning">
218+
<p>
219+
<b><?php echo esc_html__( 'You are using a sandbox test account.', 'woocommerce-payments' ) . ' '; ?></b>
220+
<?php
221+
if ( ! WC_Payments::mode()->is_dev() ) {
222+
printf(
223+
/* translators: 1: Anchor opening tag; 2: Anchor closing tag; 3: Anchor opening tag; 4: Anchor closing tag */
224+
esc_html__( 'To begin accepting real payments you will need to first %1$sreset your account%2$s and, then, provide additional details about your business. %3$sLearn more%4$s', 'woocommerce-payments' ),
225+
'<a href="' . esc_url( 'https://woocommerce.com/document/woopayments/startup-guide/#resetting' ) . '" target="_blank" rel="noreferrer noopener">',
226+
'</a>',
227+
'<a href="' . esc_url( 'https://woocommerce.com/document/woopayments/startup-guide/#sign-up-process' ) . '" target="_blank" rel="noreferrer noopener">',
228+
'</a>',
229+
);
230+
} else {
231+
esc_html_e( '⚠️ Development mode is enabled for the store! There can be no live onboarding process while using development, testing, or staging WordPress environments!', 'woocommerce-payments' );
232+
echo '</br>';
233+
printf(
234+
/* translators: 1: Anchor opening tag; 2: Anchor closing tag; 3: Anchor opening tag; 4: Anchor closing tag */
235+
esc_html__( 'To begin accepting real payments, please go to the live store or change your %1$sWordPress environment%2$s to a production one. %3$sLearn more%4$s', 'woocommerce-payments' ),
236+
'<a href="' . esc_url( 'https://make.wordpress.org/core/2020/08/27/wordpress-environment-types/' ) . '" target="_blank" rel="noreferrer noopener">',
237+
'</a>',
238+
'<a href="' . esc_url( 'https://woocommerce.com/document/woopayments/testing-and-troubleshooting/test-accounts/#developer-notes' ) . '" target="_blank" rel="noreferrer noopener">',
239+
'</a>'
240+
);
241+
}
242+
?>
243+
</p>
244+
</div>
245+
<?php
246+
}
247+
93248
/**
94249
* Adds links to the plugin's row in the "Plugins" Wp-Admin page.
95250
*

includes/class-wc-payments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ function () {
750750
);
751751
$admin->init_hooks();
752752

753-
$admin_settings = new WC_Payments_Admin_Settings( self::get_gateway() );
753+
$admin_settings = new WC_Payments_Admin_Settings( self::get_gateway(), self::get_account_service() );
754754
$admin_settings->init_hooks();
755755

756756
// Use tracks loader only in admin screens because it relies on WC_Tracks loaded by WC_Admin.

0 commit comments

Comments
 (0)