From d794070e92223a1eeff63e3866e0ee51562bd8fe Mon Sep 17 00:00:00 2001 From: carlhandy Date: Mon, 19 Aug 2024 23:27:33 -0400 Subject: [PATCH] change settings prefix --- admin/js/admin-script.js | 21 +++++++------ includes/class-mmgcp-checkout-payment.php | 8 ++--- includes/class-mmgcp-checkout-settings.php | 36 +++++++++++----------- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/admin/js/admin-script.js b/admin/js/admin-script.js index 3b8cc3c..34e11ce 100644 --- a/admin/js/admin-script.js +++ b/admin/js/admin-script.js @@ -6,6 +6,9 @@ jQuery(document).ready(function($) { originalValues[this.id] = $(this).val(); }); + // Ensure mmgcp_mode is set correctly + originalValues['mmgcp_mode'] = $('#mmgcp_mode').val(); + $('.toggle-secret-key').click(function() { var targetId = $(this).data('target'); var secretKeyInput = $('#' + targetId); @@ -19,14 +22,14 @@ jQuery(document).ready(function($) { }); function toggleLiveModeIndicator() { - if ($('#mmg_mode').val() === 'live') { + if ($('#mmgcp_mode').val() === 'live') { $('#live-mode-indicator').show(); } else { $('#live-mode-indicator').hide(); } } - $('#mmg_mode').on('change', toggleLiveModeIndicator); + $('#mmgcp_mode').on('change', toggleLiveModeIndicator); toggleLiveModeIndicator(); // Initial state $('form#mmg-checkout-settings-form').submit(function(e) { @@ -40,8 +43,8 @@ jQuery(document).ready(function($) { if (changedFields.length > 0) { var confirmMessage = ''; if (changedFields.includes('Mode')) { - var oldMode = originalValues['mmg_mode']; - var newMode = $('#mmg_mode').val(); + var oldMode = originalValues['mmgcp_mode']; + var newMode = $('#mmgcp_mode').val(); confirmMessage = 'You have switched from ' + oldMode + ' to ' + newMode + '.\n\nAre you sure you want to save this change?'; } else { confirmMessage += 'You have changed the following fields:\n' + changedFields.join('\n') + '\nAre you sure you want to save these changes?'; @@ -62,8 +65,8 @@ function copyToClipboard(text) { document.body.removeChild(tempInput); var successMessage = document.getElementById('copy-success'); - successMessage.style.display = 'inline'; - setTimeout(function() { - successMessage.style.display = 'none'; - }, 2000); - } \ No newline at end of file + successMessage.style.display = 'inline'; + setTimeout(function() { + successMessage.style.display = 'none'; + }, 2000); +} \ No newline at end of file diff --git a/includes/class-mmgcp-checkout-payment.php b/includes/class-mmgcp-checkout-payment.php index 2718d6b..bfeb824 100644 --- a/includes/class-mmgcp-checkout-payment.php +++ b/includes/class-mmgcp-checkout-payment.php @@ -75,7 +75,7 @@ class MMGCP_Checkout_Payment { */ public function __construct() { // Initialize plugin. - $this->mode = get_option( 'mmg_mode', 'demo' ); // Default mode set to 'demo'. + $this->mode = get_option( 'mmgcp_mode', 'demo' ); // Default mode set to 'demo'. // Generate or retrieve unique callback URL. $this->callback_url = $this->mmgcp_generate_unique_callback_url(); @@ -172,13 +172,13 @@ public function mmgcp_generate_checkout_url() { $timestamp = round( microtime( true ) * 1000 ); // Use milliseconds. $token_data = array( - 'secretKey' => get_option( "mmg_{$this->mode}_secret_key" ), + 'secretKey' => get_option( "mmgcp_{$this->mode}_secret_key" ), 'amount' => $amount, - 'merchantId' => get_option( "mmg_{$this->mode}_merchant_id" ), + 'merchantId' => get_option( "mmgcp_{$this->mode}_merchant_id" ), 'merchantTransactionId' => $order->get_id() . '-' . $attempt_number, 'productDescription' => $description, 'requestInitiationTime' => (string) $timestamp, - 'merchantName' => get_option( 'mmg_merchant_name', get_bloginfo( 'name' ) ), + 'merchantName' => get_option( 'mmgcp_merchant_name', get_bloginfo( 'name' ) ), ); $encrypted = $this->mmgcp_encrypt( $token_data ); diff --git a/includes/class-mmgcp-checkout-settings.php b/includes/class-mmgcp-checkout-settings.php index 1a52c6a..7c46f19 100644 --- a/includes/class-mmgcp-checkout-settings.php +++ b/includes/class-mmgcp-checkout-settings.php @@ -36,26 +36,26 @@ public function mmgcp_add_admin_menu() { * Register settings. */ public function mmgcp_register_settings() { - register_setting( 'mmgcp_checkout_settings', 'mmg_mode', array( 'sanitize_callback' => array( $this, 'mmgcp_sanitize_mode' ) ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_mode', array( 'sanitize_callback' => array( $this, 'mmgcp_sanitize_mode' ) ) ); // Live credentials. - register_setting( 'mmgcp_checkout_settings', 'mmg_live_client_id', array( 'sanitize_callback' => 'sanitize_text_field' ) ); - register_setting( 'mmgcp_checkout_settings', 'mmg_live_merchant_id', array( 'sanitize_callback' => 'sanitize_text_field' ) ); - register_setting( 'mmgcp_checkout_settings', 'mmg_live_secret_key', array( 'sanitize_callback' => 'sanitize_text_field' ) ); - register_setting( 'mmgcp_checkout_settings', 'mmg_live_rsa_public_key', array( 'sanitize_callback' => array( $this, 'mmgcp_sanitize_multiline_field' ) ) ); - register_setting( 'mmgcp_checkout_settings', 'mmg_live_rsa_private_key', array( 'sanitize_callback' => array( $this, 'mmgcp_sanitize_multiline_field' ) ) ); - register_setting( 'mmgcp_checkout_settings', 'mmg_live_checkout_url', array( 'sanitize_callback' => 'esc_url' ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_live_client_id', array( 'sanitize_callback' => 'sanitize_text_field' ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_live_merchant_id', array( 'sanitize_callback' => 'sanitize_text_field' ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_live_secret_key', array( 'sanitize_callback' => 'sanitize_text_field' ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_live_rsa_public_key', array( 'sanitize_callback' => array( $this, 'mmgcp_sanitize_multiline_field' ) ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_live_rsa_private_key', array( 'sanitize_callback' => array( $this, 'mmgcp_sanitize_multiline_field' ) ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_live_checkout_url', array( 'sanitize_callback' => 'esc_url' ) ); // Demo credentials. - register_setting( 'mmgcp_checkout_settings', 'mmg_demo_client_id', array( 'sanitize_callback' => 'sanitize_text_field' ) ); - register_setting( 'mmgcp_checkout_settings', 'mmg_demo_merchant_id', array( 'sanitize_callback' => 'sanitize_text_field' ) ); - register_setting( 'mmgcp_checkout_settings', 'mmg_demo_secret_key', array( 'sanitize_callback' => 'sanitize_text_field' ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_demo_client_id', array( 'sanitize_callback' => 'sanitize_text_field' ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_demo_merchant_id', array( 'sanitize_callback' => 'sanitize_text_field' ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_demo_secret_key', array( 'sanitize_callback' => 'sanitize_text_field' ) ); register_setting( 'mmgcp_checkout_settings', 'mmg_demo_rsa_public_key', array( 'sanitize_callback' => array( $this, 'mmgcp_sanitize_multiline_field' ) ) ); - register_setting( 'mmgcp_checkout_settings', 'mmg_demo_rsa_private_key', array( 'sanitize_callback' => array( $this, 'mmgcp_sanitize_multiline_field' ) ) ); - register_setting( 'mmgcp_checkout_settings', 'mmg_demo_checkout_url', array( 'sanitize_callback' => 'esc_url' ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_demo_rsa_private_key', array( 'sanitize_callback' => array( $this, 'mmgcp_sanitize_multiline_field' ) ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_demo_checkout_url', array( 'sanitize_callback' => 'esc_url' ) ); // Common settings. - register_setting( 'mmgcp_checkout_settings', 'mmg_merchant_name', array( 'sanitize_callback' => 'sanitize_text_field' ) ); + register_setting( 'mmgcp_checkout_settings', 'mmgcp_merchant_name', array( 'sanitize_callback' => 'sanitize_text_field' ) ); } /** @@ -80,9 +80,9 @@ public function mmgcp_settings_page() { Mode - + +