| 1 |
<?php |
| 2 |
|
| 3 |
namespace Payplug\PayplugWoocommerce\Admin; |
| 4 |
|
| 5 |
// Exit if accessed directly |
| 6 |
if (!defined('ABSPATH')) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper; |
| 11 |
use Payplug\PayplugWoocommerce\Traits\ServiceGetter; |
| 12 |
|
| 13 |
/** |
| 14 |
* Handle admin notices. |
| 15 |
*/ |
| 16 |
class Notices |
| 17 |
{ |
| 18 |
use ServiceGetter; |
| 19 |
|
| 20 |
private $options; |
| 21 |
|
| 22 |
public function __construct() |
| 23 |
{ |
| 24 |
$this->options = $this->get_service('configuration')->get_options(); |
| 25 |
// $this->options = PayplugWoocommerceHelper::get_payplug_options(); |
| 26 |
//add_action( 'admin_notices', [ $this, 'admin_notices' ] ); |
| 27 |
//add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Enqueue PayPlug notice style. |
| 32 |
* |
| 33 |
* @return void |
| 34 |
*/ |
| 35 |
public function admin_enqueue_scripts(): void |
| 36 |
{ |
| 37 |
$api_key = json_decode($this->options, true); |
| 38 |
$test_key = !empty($api_key['test']) ? $api_key['test'] : ''; |
| 39 |
$live_key = !empty($api_key['live']) ? $api_key['live'] : ''; |
| 40 |
if (empty($test_key) && empty($live_key)) { |
| 41 |
wp_enqueue_style( |
| 42 |
'payplug-notice', |
| 43 |
PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/css/notice.css', |
| 44 |
[], |
| 45 |
PAYPLUG_GATEWAY_VERSION |
| 46 |
); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Display admin notices. |
| 52 |
* |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
public function admin_notices(): void |
| 56 |
{ |
| 57 |
if (!current_user_can('manage_woocommerce')) { |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
/* |
| 62 |
* Before Woocommerce 3.2.x, settings were saved just before displaying the page |
| 63 |
* which cause the admin_notice to display old data. |
| 64 |
* |
| 65 |
* This condition check if we are on the PayPlug gateway settings page and if we |
| 66 |
* have new settings to save. If true we hook the notice to a hook which will run after the new |
| 67 |
* settings have been saved. |
| 68 |
*/ |
| 69 |
$screen = get_current_screen(); |
| 70 |
$wc = function_exists('WC') ? WC() : $GLOBALS['woocommerce']; |
| 71 |
|
| 72 |
if ( |
| 73 |
version_compare($wc->version, '3.2.0', '<') |
| 74 |
&& !empty($_POST) |
| 75 |
&& 'woocommerce_page_wc-settings' === $screen->id |
| 76 |
&& isset($_GET['section']) |
| 77 |
&& 'payplug' === $_GET['section'] |
| 78 |
) { |
| 79 |
add_action('woocommerce_settings_saved', [$this, 'display_notice']); |
| 80 |
|
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
$this->display_notice(); |
| 85 |
} |
| 86 |
|
| 87 |
public function display_notice(): void |
| 88 |
{ |
| 89 |
$testmode = isset($this->options['mode']) && !(bool) $this->options['mode']; |
| 90 |
$api_key = json_decode($this->options, true); |
| 91 |
$test_key = !empty($api_key['test']) ? $api_key['test'] : ''; |
| 92 |
$live_key = !empty($api_key['live']) ? $api_key['live'] : ''; |
| 93 |
|
| 94 |
if (empty($test_key) && empty($live_key)) { |
| 95 |
?> |
| 96 |
<div class="notice notice--start"> |
| 97 |
<div class="inside"> |
| 98 |
<div class="main"> |
| 99 |
<h2 class="notice__title"><?php _e('Thank you for installing PayPlug as your online payment solution.', 'payplug'); ?> |
| 100 |
<br> |
| 101 |
<strong><?php _e('Only one step left to activate the plugin on your site !', 'payplug'); ?></strong> |
| 102 |
</h2> |
| 103 |
<a href="<?php echo esc_url(PayplugWoocommerceHelper::get_setting_link()); ?>" |
| 104 |
class="button button-hero"><?php _e('Login', 'payplug'); ?></a> |
| 105 |
<img class="notice__img" |
| 106 |
src="<?php echo esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/PAYPLUG_LOGO_blanc.svg'); ?>" |
| 107 |
alt="PayPlug logo"> |
| 108 |
</div> |
| 109 |
</div> |
| 110 |
</div> |
| 111 |
<?php |
| 112 |
} elseif (!empty($test_key) && empty($live_key)) { |
| 113 |
?> |
| 114 |
<div class="notice notice-warning"> |
| 115 |
<p><strong><?php _e('PayPlug is in TEST mode', 'payplug'); ?></strong></p> |
| 116 |
<p><?php _e('Once your PayPlug account has been validated, please log out and log in again from the configuration page in order to activate LIVE mode.', 'payplug'); ?></p> |
| 117 |
</div> |
| 118 |
<?php |
| 119 |
} elseif (!empty($live_key) && $testmode) { |
| 120 |
?> |
| 121 |
<div class="notice notice-info"> |
| 122 |
<p><?php _e('Payments in TEST mode will be simulations and will not generate real transactions.', 'payplug'); ?></p> |
| 123 |
</div> |
| 124 |
<?php |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
|