Skip to content

Commit

Permalink
File structure update (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlHandy authored Sep 30, 2024
1 parent 4c96a7c commit e8309e5
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 106 deletions.
4 changes: 2 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ This version includes important updates and improvements. Please upgrade to ensu
== Screenshots ==

1. MMG Checkout Payment gateway settings page
![MMG Checkout Payment gateway settings page](assets/settings-page.png)
![MMG Checkout Payment gateway settings page](public/images/settings-page.png)

2. MMG Checkout option on WooCommerce checkout page
![MMG Checkout option on WooCommerce checkout page](assets/checkout-options.png)
![MMG Checkout option on WooCommerce checkout page](public/images/checkout-options.png)

== Support ==

Expand Down
22 changes: 22 additions & 0 deletions admin/css/admin-style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.blinking-dot {
display: inline-block;
width: 10px;
height: 10px;
background-color: #00ff00;
border-radius: 50%;
animation: blink 1s infinite;
}

@keyframes blink {
0% {
opacity: 0;
}

50% {
opacity: 1;
}

100% {
opacity: 0;
}
}
69 changes: 69 additions & 0 deletions admin/js/admin-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
jQuery(document).ready(function($) {
var originalValues = {};

// Store original values
$('form#mmg-checkout-settings-form :input').each(function() {
originalValues[this.id] = $(this).val();
});

$('.toggle-secret-key').click(function() {
var targetId = $(this).data('target');
var secretKeyInput = $('#' + targetId);
if (secretKeyInput.attr('type') === 'password') {
secretKeyInput.attr('type', 'text');
$(this).text('Hide');
} else {
secretKeyInput.attr('type', 'password');
$(this).text('Show');
}
});

function toggleLiveModeIndicator() {
if ($('#mmg_mode').val() === 'live') {
$('#live-mode-indicator').show();
} else {
$('#live-mode-indicator').hide();
}
}

$('#mmg_mode').on('change', toggleLiveModeIndicator);
toggleLiveModeIndicator(); // Initial state

$('form#mmg-checkout-settings-form').submit(function(e) {
var changedFields = [];
$('form#mmg-checkout-settings-form :input').each(function() {
if ($(this).val() !== originalValues[this.id]) {
changedFields.push($(this).closest('tr').find('th').text());
}
});

if (changedFields.length > 0) {
var confirmMessage = '';
if (changedFields.includes('Mode')) {
var oldMode = originalValues['mmg_mode'];
var newMode = $('#mmg_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?';
}
if (!confirm(confirmMessage)) {
e.preventDefault();
}
}
});
});

function copyToClipboard(text) {
var tempInput = document.createElement('input');
tempInput.value = text;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);

var successMessage = document.getElementById('copy-success');
successMessage.style.display = 'inline';
setTimeout(function() {
successMessage.style.display = 'none';
}, 2000);
}
File renamed without changes.
19 changes: 6 additions & 13 deletions js/mmg-checkout.js → admin/js/mmg-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,18 @@ jQuery(document).ready(function($) {
type: 'POST',
data: postData,
success: function(response) {
if (response.success && response.data.checkout_url) {
if (isValidUrl(response.data.checkout_url)) {
window.location.href = response.data.checkout_url;
} else {
alert('Invalid checkout URL received.');
$button.prop('disabled', false).text('Pay with MMG');
}
if (response.success && isValidUrl(response.data.checkout_url)) {
window.location.href = response.data.checkout_url;
} else {
alert('Error generating checkout URL: ' + (response.data.error || 'Unknown error'));
$button.prop('disabled', false).text('Pay with MMG');
alert(response.data || 'Invalid checkout URL.');
}
},
error: function(error) {
alert('Error communicating with the server. Please try again.', error);
$button.prop('disabled', false).text('Pay with MMG');
error: function() {
alert('Error communicating with the server. Please try again.');
}
});
});
});
});

function isValidUrl(url) {
try {
Expand Down
2 changes: 1 addition & 1 deletion includes/class-mmg-checkout-payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function generate_unique_callback_url() {
*/
public function enqueue_scripts() {
if ( is_checkout_pay_page() ) {
wp_enqueue_script( 'mmg-checkout', plugin_dir_url( __DIR__ ) . 'js/mmg-checkout.js', array( 'jquery' ), '3.0', true );
wp_enqueue_script( 'mmg-checkout', plugin_dir_url( __DIR__ ) . 'admin/js/mmg-checkout.js', array( 'jquery' ), '3.0', true );
wp_localize_script(
'mmg-checkout',
'mmg_checkout_params',
Expand Down
89 changes: 3 additions & 86 deletions includes/class-mmg-checkout-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,7 @@ public function settings_page() {
</span>
</td>
</tr>
<style>
.blinking-dot {
display: inline-block;
width: 10px;
height: 10px;
background-color: #00ff00;
border-radius: 50%;
animation: blink 1s infinite;
}
@keyframes blink {
0% { opacity: 0; }
50% { opacity: 1; }
100% { opacity: 0; }
}
</style>

<tr valign="top">
<th scope="row">Callback URL</th>
<td>
Expand Down Expand Up @@ -187,77 +173,6 @@ public function settings_page() {
<?php submit_button(); ?>
</form>
</div>
<script>
jQuery(document).ready(function($) {
var originalValues = {};

// Store original values
$('form#mmg-checkout-settings-form :input').each(function() {
originalValues[this.id] = $(this).val();
});

$('.toggle-secret-key').click(function() {
var targetId = $(this).data('target');
var secretKeyInput = $('#' + targetId);
if (secretKeyInput.attr('type') === 'password') {
secretKeyInput.attr('type', 'text');
$(this).text('Hide');
} else {
secretKeyInput.attr('type', 'password');
$(this).text('Show');
}
});

function toggleLiveModeIndicator() {
if ($('#mmg_mode').val() === 'live') {
$('#live-mode-indicator').show();
} else {
$('#live-mode-indicator').hide();
}
}

$('#mmg_mode').on('change', toggleLiveModeIndicator);
toggleLiveModeIndicator(); // Initial state

$('form#mmg-checkout-settings-form').submit(function(e) {
var changedFields = [];
$('form#mmg-checkout-settings-form :input').each(function() {
if ($(this).val() !== originalValues[this.id]) {
changedFields.push($(this).closest('tr').find('th').text());
}
});

if (changedFields.length > 0) {
var confirmMessage = '';
if (changedFields.includes('Mode')) {
var oldMode = originalValues['mmg_mode'];
var newMode = $('#mmg_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?';
}
if (!confirm(confirmMessage)) {
e.preventDefault();
}
}
});
});

function copyToClipboard(text) {
var tempInput = document.createElement('input');
tempInput.value = text;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);

var successMessage = document.getElementById('copy-success');
successMessage.style.display = 'inline';
setTimeout(function() {
successMessage.style.display = 'none';
}, 2000);
}
</script>
<?php
}

Expand All @@ -271,6 +186,8 @@ public function enqueue_admin_scripts( $hook ) {
return;
}
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'mmg-admin-script', plugin_dir_url( __FILE__ ) . '../admin/js/admin-script.js', array( 'jquery' ), '1.0.0', true );
wp_enqueue_style( 'mmg-admin-style', plugin_dir_url( __FILE__ ) . '../admin/css/admin-style.css', array(), '1.0.0' );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-mmg-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class WC_MMG_Gateway extends WC_Payment_Gateway {
*/
public function __construct() {
$this->id = 'mmg_checkout';
$this->icon = 'assets/mmg-logo-white.png';
$this->icon = 'public/images/mmg-logo-white.png';
$this->has_fields = false;
$this->method_title = 'MMG Checkout';
$this->method_description = 'Enables MMG Checkout Payment flow for WooCommerce';
Expand Down Expand Up @@ -88,7 +88,7 @@ public function receipt_page( $order_id ) {
$order = wc_get_order( $order_id );
echo '<div id="mmg-checkout-container" style="width: 100%;">';
echo '<button id="mmg-checkout-button" class="button alt" data-order-id="' . esc_attr( $order_id ) . '" style="background-color: #147047; color: white; display: flex; align-items: center; justify-content: center; padding: 15px 20px; width: 100%; font-size: 18px; border-radius: 6px; border: none;">';
echo '<img src="' . esc_url( plugins_url( 'assets/mmg-logo-white.png', __DIR__ ) ) . '" alt="MMG Logo" style="height: 50px; margin-right: 10px;">';
echo '<img src="' . esc_url( plugins_url( 'public/images/mmg-logo-white.png', __DIR__ ) ) . '" alt="MMG Logo" style="height: 50px; margin-right: 10px;">';
echo 'Pay with MMG</button>';
echo '</div>';
}
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-mmg-payments-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public function is_active() {
public function get_payment_method_script_handles() {
wp_register_script(
'wc-mmg-payments-blocks',
plugins_url( 'js/mmg-checkout-blocks.js', __DIR__ ),
plugins_url( 'admin/js/mmg-checkout-blocks.js', __DIR__ ),
array( 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n' ),
filemtime( plugin_dir_path( __DIR__ ) . 'js/mmg-checkout-blocks.js' ),
filemtime( plugin_dir_path( __DIR__ ) . 'admin/js/mmg-checkout-blocks.js' ),
true
);
return array( 'wc-mmg-payments-blocks' );
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit e8309e5

Please sign in to comment.