diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cf1218..e41ea8b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Changelog All notable changes to this project will be documented in this file. +## [2.4.3] - 2024-10-01 +### Added +- Implemented a feature to enable or disable debug logging. All communication data is encrypted and stored in a log file. +- Implemented the ability to process void transactions. +- Implemented the ability to add mandatory or optional extra fees on the checkout page. +### Fixed +- Fixed the compatibility issue with the WooCommerce Subscription plugin. + ## [2.4.2] - 2024-05-06 ### Added - Implemented a notification feature to alert the WordPress administrator whenever a new version is launched on GitHub. @@ -26,12 +34,10 @@ All notable changes to this project will be documented in this file. ### Fixed - “Amount mismatch” error is triggered when a user purchases a product on recent versions of WooCommerce (WordPress 5.9.3 / Woocommerce 6.4.1) - ## [2.3.1] - 2021-12-01 ### Fixed - Fixed a "false" Transaction Description issue that happened for some types of transactions - ## [2.3.0] - 2021-10-19 ### Changed - Add Embedded Payment Option @@ -43,67 +49,55 @@ All notable changes to this project will be documented in this file. - It's impossible to Refund the Payment if the plugin works in the Authorization Mode - Fix the issue with text transformation while save the settings - ## [2.2.0] - 2021-01-29 ## [2.1.2] - 2021-01-14 ### Fixed - Fixing an issue where performing a partial refund through woocommerce will instead refund the full amount. - ## [2.1.1] ### Fixed - Patch to allow for non-latin (e.g. Greek or Arabic) characters in the checkout - ## [2.1.0] ### Changed - Added support for transaction modes, Payment and Authorization - Added capture and reverse capability - ## [2.0.0] ### Changed - Standard integration has been removed - Compatibility with Wordpress 5.2 and WooCommerce 3.6 - ## [1.4.3] ### Fixed - Fix issue with amounts off by 1c. - ## [1.4.2] ### Changed - Adding Qatar to the supported countries list - ## [1.4.1] ### Fixed - Using hash_equals in return_handler helps prevent timing attacks. - ## [1.4.0] ### Changed - Display supported card types set by merchant - ## [1.3.0] ### Changed - Save hosted payment for subscription - ## [1.2.0] ### Changed - Adding "Australia" to the supported countries list - Pass currency code in Hosted Payments args - ## [1.1.0] ### Fixed - Fix the card on file not working for subscription payment - ## [1.0.0] ### Changed -- First version +- First version \ No newline at end of file diff --git a/Makefile b/Makefile index a41be08..62d6c85 100755 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ all : - git archive HEAD --prefix=simplify-woocommerce-mastercard/ -o ./simplify-woocommerce-mastercard.zip &&\ - echo "\nCreated simplify-woocommerce-mastercard.zip\n" + git archive HEAD --prefix=simplifycommerce/ -o ./woocommerce-simplifycommerce.zip &&\ + echo "\nCreated woocommerce-simplifycommerce.zip\n" diff --git a/README.md b/README.md index 5d12693..e0505e0 100755 --- a/README.md +++ b/README.md @@ -1,14 +1,8 @@ # Simplify Commerce Payment Gateway for WooCommerce -The Simplify Commerce payment gateway plugin for WooCommerce 7.6+ lets you to take card payments directly on your WooCommerce store. -
+The Simplify Commerce payment gateway plugin for WooCommerce 7.3+ lets you to take card payments directly on your WooCommerce store. -## Overview Section -Mastercard Inc. is the second-largest payment-processing corporation worldwide. It offers a range of payment transaction processing and other related payment services. By connecting individuals, businesses, and organizations in more than 210 countries and territories today, we're unlocking opportunities for more people in more places for generations. This WooCommerce module adds different payment methods to the WooCommerce checkout, enabling credit and debit card payments to be accepted securely on your WooCommerce-powered website. - -Payments through this module are processed securely via the Mastercard Payment Gateway. This ensures that card data is managed in compliance with all legal requirements. The gateway monitors every transaction and handles sensitive payment data on PCI Level 1 certified servers, simplifying PCI compliance for your business. +The Standard payment form in some of the previous releases is now deprecated and out of support. ## Support @@ -24,42 +18,12 @@ For any issues or enhancement requests you have with this plugin, please raise t **Minimum Requirements** -* WooCommerce 7.6 or greater +* WooCommerce 7.3 or greater * PHP version 7.4 or greater * cURL -## Compatibility -The module has been tested with the WooCommerce versions: - -- 7.6.1 -- 7.7.2 -- 7.8.0 -- 7.9.0 -- 8.0.1 -- 8.1.1 -- 8.2.1 -- 8.3.0 -- 8.4.1 -- 8.5.2 -- 8.7.1 -- 8.0.0 -- 9.0.2 -- 9.1.4 - -The module has been tested with the WordPress versions: - -- 5.2.4 -- 5.3.2 -- 5.6.0 -- 5.7.2 -- 5.9.1 -- 6.0.3 -- 6.1.2 -- 6.2.2 -- 6.3.1 -- 6.4.2 -- 6.5.2 -- 6.6.1 +The module has been tested and is supported with the following versions of WooCommerce: +7.3 - 7.7.1 ## Documentation The official documentation for this module is available on: [https://mpgs.fingent.wiki/simplify-commerce/simplify-commerce-payment-gateway-for-woocommerce/getting-started/](https://mpgs.fingent.wiki/simplify-commerce/simplify-commerce-payment-gateway-for-woocommerce/getting-started/) diff --git a/assets/js/mastercard-admin.js b/assets/js/mastercard-admin.js index 1195aca..d0aaf5d 100755 --- a/assets/js/mastercard-admin.js +++ b/assets/js/mastercard-admin.js @@ -27,6 +27,49 @@ jQuery(function ($) { gateway_url.hide(); } }).change(); + + $( '#woocommerce_simplify_commerce_handling_fee_amount' ).before( '' ); + $( '#handling_fee_amount_label' ).css({ "width": "35px", "height": "31px", "line-height": "30px", "background-color": "#eaeaea", "text-align": "center", "position": "absolute", "left": "1px", "top": "1px", "border-radius": "3px 0 0 3px" }).parent().css( "position", "relative" ); + $( '#woocommerce_simplify_commerce_handling_fee_amount' ).css( "padding-left", "45px" ); + if( $( '#woocommerce_simplify_commerce_hf_amount_type' ).val() == 'fixed' ) { + $( '#handling_fee_amount_label' ).html( wcSettings.currency.symbol ); + } else { + $( '#handling_fee_amount_label' ).html( '%' ); + } + + $('#woocommerce_simplify_commerce_hf_amount_type').on('change', function () { + if( $( this ).val() == 'fixed' ) { + $( '#handling_fee_amount_label' ).html( wcSettings.currency.symbol ); + } else { + $( '#handling_fee_amount_label' ).html( '%' ); + } + }).change(); + $( '#woocommerce_simplify_commerce_handling_fee_amount' ).on( 'keypress', function(e) { + var charCode = ( e.which ) ? e.which : e.keyCode; + if ( charCode == 46 || charCode == 8 || charCode == 9 || charCode == 27 || charCode == 13 || + ( charCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) || + ( charCode == 67 && ( e.ctrlKey === true || e.metaKey === true ) ) || + ( charCode == 86 && ( e.ctrlKey === true || e.metaKey === true ) ) || + ( charCode == 88 && ( e.ctrlKey === true || e.metaKey === true ) ) || + // Allow: home, end, left, right + ( charCode >= 35 && charCode <= 39 ) ) { + return; + } + + if ( ( charCode < 48 || charCode > 57 ) && charCode !== 46 ) { + e.preventDefault(); + } + + if ( charCode === 46 && $( this ).val().indexOf( '.' ) !== -1 ) { + e.preventDefault(); + } + }); + $( '#woocommerce_simplify_commerce_handling_fee_amount' ).on( 'input', function() { + var value = this.value; + if ( !/^\d*\.?\d*$/.test( value ) ) { + this.value = value.substring( 0, value.length - 1 ); + } + }); } }; wc_mastercard_admin.init(); diff --git a/changelog.txt b/changelog.txt index f9a6ef8..cccbc8d 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,12 @@ == Simplify - Mastercard Payment Gateway Services Changelog == +2024-10-01 - version 2.4.3 + +* Add - Implemented a feature to enable or disable debug logging. All communication data is encrypted and stored in a log file. +* Add - Implemented the ability to process void transactions. +* Add - Implemented the ability to add mandatory or optional extra fees on the checkout page. +* Fix - Fixed the compatibility issue with the WooCommerce Subscription plugin. + 2024-05-06 - version 2.4.2 * Add - Implemented a notification feature to alert the WordPress administrator whenever a new version is launched on GitHub. diff --git a/composer.json b/composer.json index 6aee7c2..c42af7d 100755 --- a/composer.json +++ b/composer.json @@ -1,4 +1,4 @@ { - "version": "2.4.2", + "version": "2.4.1", "type": "woocommerce-plugin" } diff --git a/includes/class-payment-gateway.php b/includes/class-payment-gateway.php index e49eaf1..87384f0 100755 --- a/includes/class-payment-gateway.php +++ b/includes/class-payment-gateway.php @@ -19,20 +19,24 @@ exit; // Exit if accessed directly } -define( 'MPGS_SIMPLIFY_MODULE_VERSION', '2.4.2' ); +define( 'MPGS_SIMPLIFY_MODULE_VERSION', '2.4.3' ); +define( 'MPGS_SIMPLIFY_SDK_VERSION', '1.7.0' ); class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC { const ID = 'simplify_commerce'; - const TXN_MODE_PURCHASE = 'purchase'; + const TXN_MODE_PURCHASE = 'purchase'; const TXN_MODE_AUTHORIZE = 'authorize'; - const INTEGRATION_MODE_MODAL = 'modal'; + const INTEGRATION_MODE_MODAL = 'modal'; const INTEGRATION_MODE_EMBEDDED = 'embedded'; - const SIP_HOST = 'www.simplify.com'; + const SIP_HOST = 'www.simplify.com'; const SIP_CUSTOM = 'custom'; + const HF_FIXED = 'fixed'; + const HF_PERCENTAGE = 'percentage'; + /** * @var string */ @@ -63,6 +67,23 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC { */ protected $is_modal_integration_model; + /** + * @var string + */ + protected $logging_level; + + /** + * @var string + */ + protected $hash; + + /** + * Handling fees + * + * @var bool + */ + protected $hf_enabled = null; + /** * Constructor. */ @@ -114,6 +135,9 @@ public function __construct() { $this->public_key = $this->sandbox === 'no' ? $this->get_option( 'public_key' ) : $this->get_option( 'sandbox_public_key' ); $this->private_key = $this->sandbox === 'no' ? $this->get_option( 'private_key' ) : $this->get_option( 'sandbox_private_key' ); $this->is_modal_integration_model = $this->get_option( 'integration_mode' ) === self::INTEGRATION_MODE_MODAL; + $this->logging_level = $this->get_debug_logging_enabled() ? true : false; + $this->hash = hash( 'sha256', $this->public_key . $this->private_key ); + $this->hf_enabled = $this->get_option( 'hf_enabled', false ); $this->init_simplify_sdk(); @@ -143,6 +167,20 @@ public function __construct() { 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); + + add_action( + 'wp_ajax_download_log', + array( $this, 'download_decrypted_log' ) + ); + + add_filter( + 'woocommerce_admin_order_should_render_refunds', + array( $this, 'admin_order_should_render_refunds' ), 10, 3 + ); + add_action( + 'woocommerce_cart_calculate_fees', + array( $this, 'add_handling_fee' ) + ); } /** @@ -150,10 +188,6 @@ public function __construct() { */ public function admin_scripts() { - if( 'woocommerce_page_wc-orders' === get_current_screen()->id || 'shop_order' === get_current_screen()->id ) { - add_action( 'admin_head', array( $this, 'woocommerce_simplify_custom_styles' ) ); - } - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { return; } @@ -163,16 +197,52 @@ public function admin_scripts() { } /** - * @return void + * Check if debug logging is enabled. + * + * @return bool True if debug logging is enabled, false otherwise. */ + protected function get_debug_logging_enabled() { + if ( 'yes' === $this->get_option( 'debug', false ) ) { + + $filename = WP_CONTENT_DIR . '/mastercard_simplify.log'; + if ( !is_writable( $filename ) ) { + @chmod( $filename, 0644 ); + } - public function woocommerce_simplify_custom_styles() { - $order_id = WC_Gateway_Simplify_Commerce_Loader::get_order_id(); - $order = new WC_Order( $order_id ); + if ( ! file_exists( $filename ) ) { + file_put_contents( $filename, '' ); + chmod( $filename, 0644 ); + } + + return true; + } + + return false; + } - if ( 'refunded' === $order->get_status() ) { - echo ''; + /** + * Determines whether the admin order page should render refunds. + * + * This function is used to check if refunds should be displayed on the admin order page. + * It can be used to add custom logic or conditions for rendering refunds in the order details view. + * + * @param bool $render_refunds Indicates whether refunds should be rendered. + * @param int $order_id The ID of the order being viewed. + * @param WC_Order $order The order object for which the refunds are being checked. + * @return bool Updated value of $render_refunds indicating whether refunds should be rendered. + */ + public function admin_order_should_render_refunds( $render_refunds, $order_id, $order ) { + $auth_code = $order->get_meta( '_simplify_authorization' ); + if ( $auth_code ) { + if( + ( 'simplify_commerce' === $order->get_payment_method() && 'refunded' === $order->get_status() ) || + ( 'simplify_commerce' === $order->get_payment_method() && empty( get_post_meta( $order_id, '_simplify_order_captured', true ) ) ) + ) { + return false; + } } + + return $render_refunds; } /** @@ -196,7 +266,7 @@ public function capture_authorized_order() { throw new Exception( 'Invalid or missing authorization code' ); } - $payment = Simplify_Payment::createPayment( array( + $data = array( 'authorization' => $authCode, 'reference' => $order->get_id(), 'currency' => strtoupper( $order->get_currency() ), @@ -205,7 +275,10 @@ public function capture_authorized_order() { __( 'Order #%s', 'woocommerce-gateway-simplify-commerce' ), $order->get_order_number() ), - ) ); + ); + $this->log( 'Capture Request', json_encode( $data ) ); + $payment = Simplify_Payment::createPayment( $data ); + $this->log( 'Capture Response', $payment ); if ( $payment->paymentStatus === 'APPROVED' ) { $this->process_capture_order_status( $order, $payment->id ); @@ -330,18 +403,9 @@ public function void_authorized_order() { $authTxn = Simplify_Authorization::findAuthorization( $authCode ); $authTxn->deleteAuthorization(); - - $order->add_order_note( sprintf( __( 'Gateway reverse authorization (ID: %s)', - 'woocommerce-gateway-simplify-commerce' ), - $authCode ) ); - - wc_create_refund( array( - 'order_id' => $order->get_id(), - 'reason' => 'Reverse', - 'refund_payment' => false, - 'restock_items' => true, - 'amount' => $order->get_remaining_refund_amount(), - ) ); + $order->update_status( 'cancelled', sprintf( __( 'Gateway reverse authorization (ID: %s)', + 'woocommerce-gateway-simplify-commerce' ), + $authCode ) ); if ( wp_get_referer() || 'yes' !== WC_Gateway_Simplify_Commerce_Loader::is_hpos() ) { wp_safe_redirect( wp_get_referer() ); @@ -483,7 +547,23 @@ public function is_available() { * Initialise Gateway Settings Form Fields. */ public function init_form_fields() { + $download_url = add_query_arg( + array( + 'action' => 'download_log', + '_wpnonce' => wp_create_nonce( 'mpgs_download_log' ) + ), admin_url( 'admin-ajax.php' ) ); + $this->form_fields = array( + 'heading' => array( + 'title' => null, + 'type' => 'title', + 'description' => sprintf( + /* translators: 1. MPGS Simplify module vesion, 2. MPGS Simplify SDK version. */ + __( 'Plugin version: %1$s