Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

Commit

Permalink
feature: messages after the plugin installation
Browse files Browse the repository at this point in the history
  • Loading branch information
sfwill-dev committed Jan 7, 2021
1 parent 71e8782 commit 1461293
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 48 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Também será necessário utilizar o plugin [WooCommerce Extra Checkout Fields f

Pronto, sua loja já pode receber pagamentos pelo Pagar.me.

Mais informações sobre as configurações do plugin em: [https://docs.pagar.me/v2/docs/configurando-o-plugin-pagarme-woocommerce](https://docs.pagar.me/v2/docs/configurando-o-plugin-pagarme-woocommerce).

## Frequently Asked Questions ##

### Qual é a licença do plugin? ###
Expand Down
6 changes: 4 additions & 2 deletions includes/admin/views/html-notice-missing-brazilian-market.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

?>

<div class="error">
<p><strong><?php esc_html_e( 'WooCommerce Pagar.me', 'woocommerce-pagarme' ); ?></strong> <?php esc_html_e( 'depends on the last version of Brazilian Market to work!', 'woocommerce-pagarme' ); ?></p>
<div class="updated notice is-dismissible">
<p><strong><?php esc_html_e( 'WooCommerce Pagar.me', 'woocommerce-pagarme' ); ?></strong> <?php esc_html_e( 'recommends using the last version of Brazilian Market plugin to work!', 'woocommerce-pagarme' ); ?></p>

<?php if ( $is_installed && current_user_can( 'install_plugins' ) ) : ?>
<p><a href="<?php echo esc_url( wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=woocommerce-extra-checkout-fields-for-brazil/woocommerce-extra-checkout-fields-for-brazil.php&plugin_status=active' ), 'activate-plugin_woocommerce-extra-checkout-fields-for-brazil/woocommerce-extra-checkout-fields-for-brazil.php' ) ); ?>" class="button button-primary"><?php esc_html_e( 'Active Brazilian Market', 'woocommerce-pagarme' ); ?></a></p>
Expand All @@ -30,4 +30,6 @@
<p><a href="https://wordpress.org/plugins/woocommerce-extra-checkout-fields-for-brazil/" class="button button-primary"><?php esc_html_e( 'Install Brazilian Market', 'woocommerce-pagarme' ); ?></a></p>
<?php endif; ?>
<?php endif; ?>

<p><a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'woocommerce-pagarme-hide-notice', 'missing_brazilian_market' ) ) ); ?>" class="notice-dismiss" style="text-decoration:none;"></a></p>
</div>
16 changes: 16 additions & 0 deletions includes/admin/views/html-notice-pagarme-documentation-link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Notice: Pagar.me documentation link.
*
* @package WooCommerce_Pagarme/Admin/Notices
*/

?>

<div class="updated notice is-dismissible">
<p><?php esc_html_e( 'We recommend checking out our documentation before starting using', 'woocommerce-pagarme' ); ?> <strong><?php esc_html_e( 'WooCommerce Pagar.me', 'woocommerce-pagarme' ); ?></strong>!</p>
<p>
<a href="https://docs.pagar.me/v2/docs/configurando-o-plugin-pagarme-woocommerce" class="button button-primary" target="_blank"><?php esc_html_e( 'Pagar.me documentation', 'woocommerce-pagarme' ); ?></a>
</p>
<p><a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'woocommerce-pagarme-hide-notice', 'documentation_link' ) ) ); ?>" class="notice-dismiss" style="text-decoration:none;"></a></p>
</div>
141 changes: 141 additions & 0 deletions tests/e2e/dismissable-notices.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
context('Wordpress admin notices', () => {
describe('when go to the wordpress plugins page', () => {
describe('and deactivate the woocommerce plugin', () => {
before(() => {
cy.goToPluginsPage()
cy.deactivateWoocommercePlugin()
})

it('should contain error message', () => {
cy.get('.error a.button')
.contains('WooCommerce')
.should('have.attr', 'href')
.and('match', /action\=activate\&plugin\=woocommerce/)
})

describe('and when reactivate the woocommerce plugin', () => {
before(() => {
cy.goToPluginsPage()
cy.activateWoocommercePlugin()
})

it('should not contain the message anymore', () => {
cy.get('.error a[href*="action=activate&plugin=woocommerce"]')
.should('not.exist')
})
})
})

describe('and deactivate the woocommerce-pagarme plugin', () => {
before(() => {
cy.goToPluginsPage()
cy.deactivateWoocommercePagarmePlugin()
})

describe('and reactivate the woocommerce-pagarme plugin', () => {
before(() => {
cy.goToPluginsPage()
cy.activateWoocommercePagarmePlugin()
})

it('should contain a message with the Pagar.me documentation link button', () => {
cy.get('.updated a.button-primary')
.should('have.attr', 'href')
.and('match', /docs.pagar.me/)
})
})

describe('and when click to close the message', () => {
before(() => {
cy.goToPluginsPage()
cy.get('.is-dismissible a[href*="woocommerce-pagarme-hide-notice=documentation_link"]')
.click()
})

it('should not contain the message anymore', () => {
cy.get('.updated a[href*="docs.pagar.me"]')
.should('not.exist')
})
})
})

describe('and deactivate the brazilian market plugin', () => {
before(() => {
cy.goToPluginsPage()
cy.deactivateBrazilianMarketPlugin()
})

describe('and deactivate the woocommerce-pagarme plugin', () => {
before(() => {
cy.goToPluginsPage()
cy.deactivateWoocommercePagarmePlugin()
})

describe('and reactivate the woocommerce-pagarme plugin', () => {
before(() => {
cy.goToPluginsPage()
cy.activateWoocommercePagarmePlugin()
})

it('should contain a message recommending the Brazilian Market plugin activation', () => {
cy.get('.updated a.button-primary')
.should('have.attr', 'href')
.and('match', /action=activate&plugin=woocommerce-extra-checkout-fields-for-brazil/)
})
})

describe('and when click to close the message', () => {
before(() => {
cy.goToPluginsPage()
cy.get('.is-dismissible a[href*="woocommerce-pagarme-hide-notice=missing_brazilian_market"]')
.click()
})

it('should not contain the message anymore', () => {
cy.get('.updated a[href*="action=activate&plugin=woocommerce-extra-checkout-fields-for-brazil"]')
.should('not.exist')
})
})
})

describe('and deactivate the woocommerce-pagarme plugin', () => {
before(() => {
cy.goToPluginsPage()
cy.deactivateWoocommercePagarmePlugin()
})

describe('and reactivate the woocommerce-pagarme plugin', () => {
before(() => {
cy.goToPluginsPage()
cy.activateWoocommercePagarmePlugin()
})

it('should contain again a message recommending the Brazilian Market plugin activation', () => {
cy.get('.updated a.button-primary')
.should('have.attr', 'href')
.and('match', /action=activate&plugin=woocommerce-extra-checkout-fields-for-brazil/)
})
})

describe('and when reactivate the brazilian market plugin', () => {
before(() => {
cy.goToPluginsPage()
cy.activateBrazilianMarketPlugin()
})

it('should not contain the message anymore', () => {
cy.get('.updated a[href*="action=activate&plugin=woocommerce-extra-checkout-fields-for-brazil"]')
.should('not.exist')
})
})

after(() => {
cy.goToPluginsPage()
cy.get('.is-dismissible a[href*="woocommerce-pagarme-hide-notice=documentation_link"]')
.click()
})
})
})
})
})

42 changes: 0 additions & 42 deletions tests/e2e/required-plugins.spec.js

This file was deleted.

22 changes: 18 additions & 4 deletions tests/e2e/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,26 +340,40 @@ Cypress.Commands.add('deactivateBrazilianMarketPlugin', () => {
cy.log('Deactivating the Brazilian Market plugin...')

cy.get('#deactivate-woocommerce-extra-checkout-fields-for-brazil')
.click()
.click()
})

Cypress.Commands.add('activateBrazilianMarketPlugin', () => {
cy.log('Activating the Brazilian Market plugin...')

cy.get('#activate-woocommerce-extra-checkout-fields-for-brazil')
.click()
.click()
})

Cypress.Commands.add('deactivateWoocommercePlugin', () => {
cy.log('Deactivating the WooCommerce plugin...')

cy.get('#deactivate-woocommerce')
.click()
.click()
})

Cypress.Commands.add('activateWoocommercePlugin', () => {
cy.log('Activating the WooCommerce plugin...')

cy.get('#activate-woocommerce')
.click()
.click()
})

Cypress.Commands.add('deactivateWoocommercePagarmePlugin', () => {
cy.log('Deactivating the WooCommerce Pagarme plugin...')

cy.get('#deactivate-woocommerce-pagarme')
.click()
})

Cypress.Commands.add('activateWoocommercePagarmePlugin', () => {
cy.log('Activating the WooCommerce Pagarme plugin...')

cy.get('#activate-woocommerce-pagarme')
.click()
})
68 changes: 68 additions & 0 deletions woocommerce-pagarme.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ private function __construct() {
if ( class_exists( 'Extra_Checkout_Fields_For_Brazil' ) ) {
add_action( 'wcbcf_billing_fields', array( $this, 'wcbcf_billing_fields_custom_settings' ) );
}

// Runs a specific method right after the plugin activation.
add_action( 'admin_init', array( $this, 'after_activation' ) );

// Dismissible notices.
add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
add_action( 'admin_notices', array( $this, 'brazilian_market_missing_notice' ) );
add_action( 'admin_notices', array( $this, 'pagarme_documentation_link_notice' ) );
}

/**
Expand Down Expand Up @@ -143,6 +151,30 @@ public function woocommerce_missing_notice() {
include dirname( __FILE__ ) . '/includes/admin/views/html-notice-missing-woocommerce.php';
}

/**
* Brazilian Market plugin missing notice.
*/
public function brazilian_market_missing_notice() {
if ( ( is_admin() && get_option( 'woocommerce_pagarme_admin_notice_missing_brazilian_market' ) === 'yes' ) ) {
// Do not show the notice if the Brazilian Market plugin is installed.
if ( class_exists( 'Extra_Checkout_Fields_For_Brazil' ) ) {
delete_option( 'woocommerce_pagarme_admin_notice_missing_brazilian_market' );
return;
}

include dirname( __FILE__ ) . '/includes/admin/views/html-notice-missing-brazilian-market.php';
}
}

/**
* Pagar.me documentation notice.
*/
public function pagarme_documentation_link_notice() {
if ( is_admin() && get_option( 'woocommerce_pagarme_admin_notice_documentation_link' ) === 'yes' ) {
include dirname( __FILE__ ) . '/includes/admin/views/html-notice-pagarme-documentation-link.php';
}
}

/**
* Upgrade.
*
Expand Down Expand Up @@ -196,8 +228,44 @@ public function wcbcf_billing_fields_custom_settings( $wcbcf_billing_fields ) {

return $wcbcf_billing_fields;
}

/**
* Hide a notice if the GET variable is set.
*/
public static function hide_notices() {
if ( isset( $_GET['woocommerce-pagarme-hide-notice'] ) ) {
$notice_to_hide = sanitize_text_field( wp_unslash( $_GET['woocommerce-pagarme-hide-notice'] ) );
delete_option( 'woocommerce_pagarme_admin_notice_' . $notice_to_hide );
}
}

/**
* Activate.
*
* Fired by `register_activation_hook` when the plugin is activated.
*/
public static function activation() {
if ( is_multisite() ) {
return;
}

add_option( 'woocommerce_pagarme_activated', 'yes' );
}

/**
* After activation.
*/
public function after_activation() {
if ( is_admin() && get_option( 'woocommerce_pagarme_activated' ) === 'yes' ) {
delete_option( 'woocommerce_pagarme_activated' );

add_option( 'woocommerce_pagarme_admin_notice_documentation_link', 'yes' );
add_option( 'woocommerce_pagarme_admin_notice_missing_brazilian_market', 'yes' );
}
}
}

add_action( 'plugins_loaded', array( 'WC_Pagarme', 'get_instance' ) );
register_activation_hook( plugin_basename( __FILE__ ), array( 'WC_Pagarme', 'activation' ) );

endif;

0 comments on commit 1461293

Please sign in to comment.