Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Show Activate payments notice in WooPayments Settings only for test accounts.
193 changes: 174 additions & 19 deletions includes/admin/class-wc-payments-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ class WC_Payments_Admin_Settings {
*/
private $gateway;

/**
* Instance of WC_Payments_Account
*
* @var WC_Payments_Account
*/
private $account;

/**
* Set of parameters to build the URL to the gateway's settings page.
*
Expand All @@ -32,9 +39,11 @@ class WC_Payments_Admin_Settings {
* Initialize class actions.
*
* @param WC_Payment_Gateway_WCPay $gateway Payment Gateway.
* @param WC_Payments_Account $account The account service.
*/
public function __construct( WC_Payment_Gateway_WCPay $gateway ) {
public function __construct( WC_Payment_Gateway_WCPay $gateway, WC_Payments_Account $account ) {
$this->gateway = $gateway;
$this->account = $account;
}

/**
Expand All @@ -43,44 +52,132 @@ public function __construct( WC_Payment_Gateway_WCPay $gateway ) {
* @return void
*/
public function init_hooks() {
add_action( 'woocommerce_woocommerce_payments_admin_notices', [ $this, 'display_test_mode_notice' ] );
add_action( 'woocommerce_woocommerce_payments_admin_notices', [ $this, 'maybe_show_test_mode_notice' ] );
add_action( 'woocommerce_woocommerce_payments_admin_notices', [ $this, 'maybe_show_test_account_notice' ] );
add_action( 'woocommerce_woocommerce_payments_admin_notices', [ $this, 'maybe_show_sandbox_account_notice' ] );
add_filter( 'plugin_action_links_' . plugin_basename( WCPAY_PLUGIN_FILE ), [ $this, 'add_plugin_links' ] );
}

/**
* Add notice explaining test mode when it's enabled.
* Add notice about payments being in test mode when using a live account.
*
* This notice is mutually exclusive with the test account and sandbox account notices.
*
* @see self::maybe_show_test_account_notice()
* @see self::maybe_show_sandbox_account_notice()
*/
public function display_test_mode_notice() {
if ( WC_Payments::mode()->is_test() ) {
?>
<div id="wcpay-test-mode-notice" class="notice notice-warning">
<p>
<b><?php esc_html_e( 'You are using a test account. ', 'woocommerce-payments' ); ?></b>
public function maybe_show_test_mode_notice() {
// If there is no valid account connected, bail.
if ( ! $this->gateway->is_connected() || ! $this->account->is_stripe_account_valid() ) {
return;
}

// If this is not a live account, bail since we will inform the user about the test account instead.
if ( ! $this->account->get_is_live() ) {
return;
}

// If the test mode is not enabled, bail.
if ( ! WC_Payments::mode()->is_test() ) {
return;
}

// Output the notice.
?>
<div id="wcpay-test-mode-notice" class="notice notice-warning">
<p>
<b>
<?php
printf(
wp_kses_post(
/* translators: %s: URL to learn more */
__( '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' ),
),
esc_url( 'https://woocommerce.com/document/woopayments/startup-guide/#sign-up-process' )
/* translators: %s: WooPayments */
esc_html__( '%s is in test mode — all transactions are simulated!', 'woocommerce-payments' ) . ' ',
'WooPayments'
);
?>
</p>
</b>
<?php
printf(
/* translators: 1: Anchor opening tag; 2: Anchor closing tag */
esc_html__( 'You can use %1$stest card numbers%2$s to simulate various types of transactions.', 'woocommerce-payments' ),
'<a href="' . esc_url( 'https://woocommerce.com/document/woopayments/testing-and-troubleshooting/testing/#test-cards' ) . '" target="_blank" rel="noreferrer noopener">',
'</a>'
);
?>
</p>
</div>
<?php
}

/**
* Add notice to activate payments when a test account is in use.
*
* This notice is mutually exclusive with the test mode and sandbox account notices.
*
* @see self::maybe_show_test_mode_notice()
* @see self::maybe_show_sandbox_account_notice()
*/
public function maybe_show_test_account_notice() {
// If there is no valid account connected, bail.
if ( ! $this->gateway->is_connected() || ! $this->account->is_stripe_account_valid() ) {
return;
}

// If this is a live account, bail.
if ( $this->account->get_is_live() ) {
return;
}

// If this is NOT a test [drive] account, bail.
$account_status = $this->account->get_account_status_data();
if ( empty( $account_status['testDrive'] ) ) {
return;
}

// Output the notice.
?>
<div id="wcpay-test-account-notice" class="notice notice-warning">
<p>
<b><?php echo esc_html__( 'You are using a test account.', 'woocommerce-payments' ) . ' '; ?></b>
<?php
if ( ! WC_Payments::mode()->is_dev() ) {
printf(
/* translators: %s: URL to learn more */
esc_html__( 'Provide additional details about your business so you can begin accepting real payments. %1$sLearn more%2$s', 'woocommerce-payments' ),
'<a href="' . esc_url( 'https://woocommerce.com/document/woopayments/startup-guide/#sign-up-process' ) . '" target="_blank" rel="noreferrer noopener">',
'</a>'
);
} else {
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' );
echo '</br>';
printf(
/* translators: 1: Anchor opening tag; 2: Anchor closing tag; 3: Anchor opening tag; 4: Anchor closing tag */
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' ),
'<a href="' . esc_url( 'https://make.wordpress.org/core/2020/08/27/wordpress-environment-types/' ) . '" target="_blank" rel="noreferrer noopener">',
'</a>',
'<a href="' . esc_url( 'https://woocommerce.com/document/woopayments/testing-and-troubleshooting/test-accounts/#developer-notes' ) . '" target="_blank" rel="noreferrer noopener">',
'</a>'
);
}
?>
</p>
<?php if ( ! WC_Payments::mode()->is_dev() ) { ?>
<p>
<a id="wcpay-activate-payments-button" href="#" class="button button-secondary">
<?php esc_html_e( 'Activate payments', 'woocommerce-payments' ); ?>
</a>
</p>
</div>
<?php } ?>
</div>
<?php if ( ! WC_Payments::mode()->is_dev() ) { ?>
<script type="text/javascript">
// We dispatch an event to trigger the modal.
// The listener is in the general-settings/index.js file.
document.addEventListener( 'DOMContentLoaded', function() {
document.addEventListener( 'DOMContentLoaded', function () {
var activateButton = document.getElementById( 'wcpay-activate-payments-button' );
if ( ! activateButton ) {
if ( !activateButton ) {
return;
}
activateButton.addEventListener( 'click', function( e ) {
activateButton.addEventListener( 'click', function ( e ) {
e.preventDefault();
document.dispatchEvent( new CustomEvent( 'wcpay:activate_payments' ) );
} );
Expand All @@ -90,6 +187,64 @@ public function display_test_mode_notice() {
}
}

/**
* Add notice to inform that a sandbox account is in use.
*
* This notice is mutually exclusive with the test mode and test account notices.
*
* @see self::maybe_show_test_mode_notice()
* @see self::maybe_show_test_account_notice()
*/
public function maybe_show_sandbox_account_notice() {
// If there is no valid account connected, bail.
if ( ! $this->gateway->is_connected() || ! $this->account->is_stripe_account_valid() ) {
return;
}

// If this is a live account, bail.
if ( $this->account->get_is_live() ) {
return;
}

// If this is a test [drive] account, bail.
$account_status = $this->account->get_account_status_data();
if ( ! empty( $account_status['testDrive'] ) ) {
return;
}

// Output the notice.
?>
<div id="wcpay-test-account-notice" class="notice notice-warning">
<p>
<b><?php echo esc_html__( 'You are using a sandbox test account.', 'woocommerce-payments' ) . ' '; ?></b>
<?php
if ( ! WC_Payments::mode()->is_dev() ) {
printf(
/* translators: 1: Anchor opening tag; 2: Anchor closing tag; 3: Anchor opening tag; 4: Anchor closing tag */
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' ),
'<a href="' . esc_url( 'https://woocommerce.com/document/woopayments/startup-guide/#resetting' ) . '" target="_blank" rel="noreferrer noopener">',
'</a>',
'<a href="' . esc_url( 'https://woocommerce.com/document/woopayments/startup-guide/#sign-up-process' ) . '" target="_blank" rel="noreferrer noopener">',
'</a>',
);
} else {
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' );
echo '</br>';
printf(
/* translators: 1: Anchor opening tag; 2: Anchor closing tag; 3: Anchor opening tag; 4: Anchor closing tag */
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' ),
'<a href="' . esc_url( 'https://make.wordpress.org/core/2020/08/27/wordpress-environment-types/' ) . '" target="_blank" rel="noreferrer noopener">',
'</a>',
'<a href="' . esc_url( 'https://woocommerce.com/document/woopayments/testing-and-troubleshooting/test-accounts/#developer-notes' ) . '" target="_blank" rel="noreferrer noopener">',
'</a>'
);
}
?>
</p>
</div>
<?php
}

/**
* Adds links to the plugin's row in the "Plugins" Wp-Admin page.
*
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ function () {
);
$admin->init_hooks();

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

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