From 5489c7fce289dce3538d6c3ec4bdc13280680cf2 Mon Sep 17 00:00:00 2001 From: jineshpv Date: Tue, 26 Nov 2024 16:23:04 +0530 Subject: [PATCH 1/2] Features:- Introduced a new Merchant Information section in the plugin settings for admins to easily update merchant information, Eliminated the intermediate page in the 'Redirect to Payment Page' process for Hosted Checkout, Compatibility with WooCommerce 9.3, Updated the API version to 84 & Resolved an issue where line items were not correctly transmitted to the payment gateway --- CHANGELOG.md | 19 +- README.md | 36 +- changelog.txt | 10 +- composer.json | 2 +- includes/assets/js/mastercard-admin.js | 86 ++++- includes/class-checkout-builder.php | 241 ++++++++++--- includes/class-gateway-blocks-support.php | 4 +- includes/class-gateway-notification.php | 14 +- includes/class-gateway-service.php | 42 ++- includes/class-gateway.php | 333 ++++++------------ includes/class-payment-gateway-cc.php | 14 +- includes/logger/class-api-error-plugin.php | 2 +- includes/logger/class-api-logger-plugin.php | 10 +- .../class-gateway-response-exception.php | 2 +- includes/settings-mastercard.php | 284 +++++++++++++++ mpgs_payments.log | 4 + templates/3dsecure/form.php | 4 +- templates/checkout/hosted-checkout.php | 18 +- templates/checkout/hosted-session.php | 19 +- vendor/composer/installed.php | 12 +- woocommerce-mastercard.php | 127 ++++++- 21 files changed, 894 insertions(+), 389 deletions(-) create mode 100755 includes/settings-mastercard.php create mode 100755 mpgs_payments.log diff --git a/CHANGELOG.md b/CHANGELOG.md index 56a0c77..7ebdf87 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,20 @@ # Changelog All notable changes to this project will be documented in this file. +## [1.4.7] - 2024-10-08 +### Added +- Introduced a new 'Merchant Information' section in the plugin settings for admins to easily update merchant information. +- Eliminated the intermediate page in the 'Redirect to Payment Page' process for Hosted Checkout. + +### Enhancement +- Compatibility with WooCommerce 9.3. + +### Changed +- Updated the API version to 84. + +### Fixed +- Resolved an issue where line items were not correctly transmitted to the payment gateway. + ## [1.4.6] - 2024-08-30 ### Added - Implemented the ability to process void transactions. @@ -10,6 +24,9 @@ All notable changes to this project will be documented in this file. ### Enhancement - Compatibility with WordPress 6.6 and WooCommerce 9.1. +### Changed +- Updated the API version to 81. + ## [1.4.4] - 2024-04-12 ### Feature - Implemented a notification feature to alert the WordPress administrator whenever a new version is launched on GitHub. @@ -82,4 +99,4 @@ All notable changes to this project will be documented in this file. - Partial refunds - AVS - 3DS1 -- Tokenisation +- Tokenisation \ No newline at end of file diff --git a/README.md b/README.md index af0e2c3..14e2889 100644 --- a/README.md +++ b/README.md @@ -9,35 +9,23 @@ 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. +## Installation + +**Minimum Requirements** + +* WooCommerce 8.5 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.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 - ## Customer Information Shared with Gateway ### This module shares the following customer information with the gateway: @@ -74,13 +62,13 @@ Ability to refund the partial transaction amount into the cardholder’s account 11. **Tokenization** Tokenization makes the card payment experience secure by converting your 16-digit card numbers to encrypted tokens. ## Documentation -The official documentation for this module is available on: [https://mpgs.fingent.wiki/target/woocommerce-mastercard-payment-gateway-services/installation](https://mpgs.fingent.wiki/target/woocommerce-mastercard-payment-gateway-services/installation/) +The official documentation for this module is available on: [https://mpgs.fingent.wiki/target/woocommerce-mastercard-payment-gateway-services/installation](https://mpgs.fingent.wiki/enterprise/woocommerce-mastercard-payment-gateway-services/overview-and-feature-support) ## Support For customer support: [https://mpgsfgs.atlassian.net/servicedesk/customer/portals](https://mpgsfgs.atlassian.net/servicedesk/customer/portals/) ## Obtain the module -You can obtain the module by downloading a release from: /~https://github.com/Mastercard-Gateway/gateway-woocommerce-module/releases +You can obtain the module by downloading a release from: /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/releases ## Installation of Module To use WooCommerce MPGS for WordPress, you need to install both the MasterCard Payment Gateway Services module and the WooCommerce module. ### Steps to install WooCommerce for WordPress: @@ -95,7 +83,7 @@ Follow the below steps: ### Steps to install MasterCard Payment Gateway Services for WordPress Follow the below steps: 1. There are two ways to install the plugin into WordPress, either: -1.1 Download the gateway-woocommerce-module plugin zip file from /~https://github.com/Mastercard-Gateway/gateway-woocommerce-module/releases and extract to the /wp-content/plugins/ directory, +1.1 Download the gateway-woocommerce-module plugin zip file from /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/releases and extract to the /wp-content/plugins/ directory, **or** 1.2. Connect to Backoffice of your shop with the available admin credentials and install the plugin through the WordPress plugins screen directly. Goto: Admin => Plugins => Installed Plugins => Click on 'Add New' => Then in the Top click on "Upload Plugin" button. diff --git a/changelog.txt b/changelog.txt index cc9cbf6..9bc2aa4 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,13 @@ == Mastercard Payment Gateway Services Changelog == +2024-10-08 - version 1.4.7 + +* Add - Introduced a new 'Merchant Information' section in the plugin settings for admins to easily update merchant information. +* Add - Eliminated the intermediate page in the 'Redirect to Payment Page' process for Hosted Checkout. +* Enhancement - Compatibility with WooCommerce 9.3. +* Update - Updated the API version to 84. +* Fix - Resolved an issue where line items were not correctly transmitted to the payment gateway. + 2024-08-30 - version 1.4.6 * Add - Implemented the ability to process void transactions. @@ -68,4 +76,4 @@ * Feature - Partial refunds * Feature - AVS * Feature - 3DS1 -* Feature - Tokenisation +* Feature - Tokenisation \ No newline at end of file diff --git a/composer.json b/composer.json index 5e7e089..22fa241 100755 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "version": "1.4.6", + "version": "1.4.7", "type": "woocommerce-plugin", "require": { "php-http/curl-client": "^2.3", diff --git a/includes/assets/js/mastercard-admin.js b/includes/assets/js/mastercard-admin.js index 8dfe64d..3bb5863 100755 --- a/includes/assets/js/mastercard-admin.js +++ b/includes/assets/js/mastercard-admin.js @@ -20,13 +20,14 @@ jQuery(function ($) { init: function () { var sandbox_username = $('#woocommerce_mpgs_gateway_sandbox_username').parents('tr').eq(0), sandbox_password = $('#woocommerce_mpgs_gateway_sandbox_password').parents('tr').eq(0), - username = $('#woocommerce_mpgs_gateway_username').parents('tr').eq(0), - password = $('#woocommerce_mpgs_gateway_password').parents('tr').eq(0), - threedsecure = $('#woocommerce_mpgs_gateway_threedsecure').parents('tr').eq(0), - gateway_url = $('#woocommerce_mpgs_gateway_custom_gateway_url').parents('tr').eq(0), - hc_interaction = $('#woocommerce_mpgs_gateway_hc_interaction').parents('tr').eq(0), - hc_type = $('#woocommerce_mpgs_gateway_hc_type').parents('tr').eq(0), - saved_cards = $('#woocommerce_mpgs_gateway_saved_cards').parents('tr').eq(0); + username = $('#woocommerce_mpgs_gateway_username').parents('tr').eq(0), + password = $('#woocommerce_mpgs_gateway_password').parents('tr').eq(0), + threedsecure = $('#woocommerce_mpgs_gateway_threedsecure').parents('tr').eq(0), + gateway_url = $('#woocommerce_mpgs_gateway_custom_gateway_url').parents('tr').eq(0), + hc_interaction = $('#woocommerce_mpgs_gateway_hc_interaction').parents('tr').eq(0), + hc_type = $('#woocommerce_mpgs_gateway_hc_type').parents('tr').eq(0), + saved_cards = $('#woocommerce_mpgs_gateway_saved_cards').parents('tr').eq(0), + merchant_info = $('#woocommerce_mpgs_gateway_merchant_info'); $('#woocommerce_mpgs_gateway_sandbox').on('change', function () { if ($(this).is(':checked')) { @@ -66,17 +67,41 @@ jQuery(function ($) { } }).change(); + $('#woocommerce_mpgs_gateway_method').on('change', function () { + if ($(this).val() === 'hosted-checkout' && $('#woocommerce_mpgs_gateway_hc_interaction').val() === 'redirect') { + merchant_info.show(); + merchant_info.next().show(); + merchant_info.next().next().show(); + } else { + merchant_info.hide(); + merchant_info.next().hide(); + merchant_info.next().next().hide(); + } + }).change(); + + $('#woocommerce_mpgs_gateway_hc_interaction').on('change', function () { + if ($(this).val() === 'redirect') { + merchant_info.show(); + merchant_info.next().show(); + merchant_info.next().next().show(); + } else { + merchant_info.hide(); + merchant_info.next().hide(); + merchant_info.next().next().hide(); + } + }).change(); + $( '#woocommerce_mpgs_gateway_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_mpgs_gateway_handling_fee_amount' ).css( "padding-left", "45px" ); - if( $( '#woocommerce_mpgs_gateway_hf_amount_type' ).val() == 'fixed' ) { + if( $( '#woocommerce_mpgs_gateway_hf_amount_type' ).val() === 'fixed' ) { $( '#handling_fee_amount_label' ).html( wcSettings.currency.symbol ); } else { $( '#handling_fee_amount_label' ).html( '%' ); } $('#woocommerce_mpgs_gateway_hf_amount_type').on('change', function () { - if( $( this ).val() == 'fixed' ) { + if( $( this ).val() === 'fixed' ) { $( '#handling_fee_amount_label' ).html( wcSettings.currency.symbol ); } else { $( '#handling_fee_amount_label' ).html( '%' ); @@ -84,11 +109,11 @@ jQuery(function ($) { }).change(); $( '#woocommerce_mpgs_gateway_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 ) ) || + 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; @@ -108,6 +133,39 @@ jQuery(function ($) { this.value = value.substring( 0, value.length - 1 ); } }); + + $( '#woocommerce_mpgs_gateway_merchant_logo' ).after( '   ' ); + + var customUploader = ''; + $( '#mpgs_gateway_merchant_logo' ).on( 'click', function(e) { + e.preventDefault(); + if ( customUploader) { + customUploader.open(); + return; + } + customUploader = wp.media.frames.file_frame = wp.media({ + title: 'Upload logo', + button: { + text: 'Choose logo' + }, + multiple: false, + library: { + type: [ 'image/jpeg', 'image/png', 'image/svg+xml' ] + }, + }); + customUploader.on('select', function() { + var attachment = customUploader.state().get('selection').first().toJSON(); + var previousElement = e.target.previousElementSibling; + + if( previousElement ) { + $( previousElement ).val( attachment.url ); + if( $( previousElement ).parents( '#mainform' ).find( '.woocommerce-save-button' ).attr( 'disabled' ) === 'disabled' ) { + $( previousElement ).parents( '#mainform' ).find( '.woocommerce-save-button' ).removeAttr( 'disabled' ); + } + } + }); + customUploader.open(); + }); } }; wc_mastercard_admin.init(); diff --git a/includes/class-checkout-builder.php b/includes/class-checkout-builder.php index 6886094..0afa3cc 100755 --- a/includes/class-checkout-builder.php +++ b/includes/class-checkout-builder.php @@ -15,7 +15,7 @@ * limitations under the License. * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ @@ -36,13 +36,21 @@ class Mastercard_CheckoutBuilder { */ protected $order = null; + /** + * Mastercard Gateway object + * + * @var WC_Order + */ + protected $gateway = null; + /** * Mastercard_Model_AbstractBuilder constructor. * * @param array $order WC_Order. */ public function __construct( $order ) { - $this->order = $order; + $this->order = $order; + $this->gateway = new Mastercard_Gateway(); } /** @@ -64,7 +72,7 @@ public function iso2ToIso3( $iso2_country ) { // phpcs:ignore * * @return boolean Returns true if the value is safe and within the limit, otherwise returns false. */ - public static function safe( $value, $limited = 0 ) { + public static function is_safe( $value, $limited = 0 ) { if ( '' === $value ) { return null; } @@ -84,12 +92,12 @@ public static function safe( $value, $limited = 0 ) { public function getBilling() { // phpcs:ignore return array( 'address' => array( - 'street' => self::safe( $this->order->get_billing_address_1(), 100 ), - 'street2' => self::safe( $this->order->get_billing_address_2(), 100 ), - 'city' => self::safe( $this->order->get_billing_city(), 100 ), - 'postcodeZip' => self::safe( $this->order->get_billing_postcode(), 10 ), + 'street' => self::is_safe( $this->order->get_billing_address_1(), 100 ), + 'street2' => self::is_safe( $this->order->get_billing_address_2(), 100 ), + 'city' => self::is_safe( $this->order->get_billing_city(), 100 ), + 'postcodeZip' => self::is_safe( $this->order->get_billing_postcode(), 10 ), 'country' => $this->iso2ToIso3( $this->order->get_billing_country() ), - 'stateProvince' => self::safe( $this->order->get_billing_state(), 20 ), + 'stateProvince' => self::is_safe( $this->order->get_billing_state(), 20 ), ), ); } @@ -102,11 +110,11 @@ public function getBilling() { // phpcs:ignore * @return bool */ public function orderIsVirtual( $order ) { // phpcs:ignore - if ( empty( $this->order->get_shipping_address_1() ) ) { + if ( empty( $order->get_shipping_address_1() ) ) { return true; } - if ( empty( $this->order->get_shipping_first_name() ) ) { + if ( empty( $order->get_shipping_first_name() ) ) { return true; } @@ -125,16 +133,16 @@ public function getShipping() { // phpcs:ignore return array( 'address' => array( - 'street' => self::safe( $this->order->get_shipping_address_1(), 100 ), - 'street2' => self::safe( $this->order->get_shipping_address_2(), 100 ), - 'city' => self::safe( $this->order->get_shipping_city(), 100 ), - 'postcodeZip' => self::safe( $this->order->get_shipping_postcode(), 10 ), + 'street' => self::is_safe( $this->order->get_shipping_address_1(), 100 ), + 'street2' => self::is_safe( $this->order->get_shipping_address_2(), 100 ), + 'city' => self::is_safe( $this->order->get_shipping_city(), 100 ), + 'postcodeZip' => self::is_safe( $this->order->get_shipping_postcode(), 10 ), 'country' => $this->iso2ToIso3( $this->order->get_shipping_country() ), - 'stateProvince' => self::safe( $this->order->get_shipping_state(), 20 ), + 'stateProvince' => self::is_safe( $this->order->get_shipping_state(), 20 ), ), 'contact' => array( - 'firstName' => self::safe( $this->order->get_shipping_first_name(), 50 ), - 'lastName' => self::safe( $this->order->get_shipping_last_name(), 50 ), + 'firstName' => self::is_safe( $this->order->get_shipping_first_name(), 50 ), + 'lastName' => self::is_safe( $this->order->get_shipping_last_name(), 50 ), ), ); @@ -148,8 +156,8 @@ public function getShipping() { // phpcs:ignore public function getCustomer() { // phpcs:ignore return array( 'email' => $this->order->get_billing_email(), - 'firstName' => self::safe( $this->order->get_billing_first_name(), 50 ), - 'lastName' => self::safe( $this->order->get_billing_last_name(), 50 ), + 'firstName' => self::is_safe( $this->order->get_billing_first_name(), 50 ), + 'lastName' => self::is_safe( $this->order->get_billing_last_name(), 50 ), ); } @@ -159,14 +167,77 @@ public function getCustomer() { // phpcs:ignore * @return array */ public function getHostedCheckoutOrder() { // phpcs:ignore - $gateway = new Mastercard_Gateway(); - return array_merge( - array( - 'id' => (string) $gateway->add_order_prefix( $this->order->get_id() ), - 'description' => 'Ordered goods', - ), - $this->getOrder() - ); + $order_summary = array(); + if ( isset( $this->gateway->hf_enabled ) && 'yes' === $this->gateway->hf_enabled ) { + $handling_fee = $this->order->get_meta( '_mpgs_handling_fee' ); + } else { + $handling_fee = 0; + } + $shipping_fee = (float)( $handling_fee ) + (float) $this->order->get_shipping_total(); + + if( 'yes' === $this->gateway->send_line_items ) { + $line_items = array(); + $items = $this->order->get_items(); + + if ( $items ) { + foreach ( $items as $item ) { + $product = $item->get_product(); + $line_items[] = array( + 'name' => $item->get_name(), + 'quantity' => $item->get_quantity(), + 'sku' => $product->get_sku(), + 'unitPrice' => $this->formattedPrice( $product->get_price() ), + ); + } + } + + $order_summary = array( + 'id' => (string) $this->gateway->add_order_prefix( $this->order->get_id() ), + 'description' => 'Customer Order Summary', + 'item' => $line_items, + 'itemAmount' => $this->formattedPrice( $this->order->get_subtotal() ), + ); + + if( $shipping_fee ) { + $order_summary['shippingAndHandlingAmount'] = $this->formattedPrice( $shipping_fee ); + } + + if( $this->order->get_total_tax() ) { + $order_summary['taxAmount'] = $this->formattedPrice( $this->order->get_total_tax() ); + } + + if( $this->order->get_total_discount() ) { + $order_summary['discount']['amount'] = $this->formattedPrice( $this->order->get_total_discount() ); + } + + return array_merge( + $order_summary, + $this->getOrder() + ); + } else { + $order_summary = array( + 'id' => (string) $this->gateway->add_order_prefix( $this->order->get_id() ), + 'description' => 'Customer Order Summary', + 'itemAmount' => $this->formattedPrice( $this->order->get_subtotal() ), + ); + + if( $shipping_fee ) { + $order_summary['shippingAndHandlingAmount'] = $this->formattedPrice( $shipping_fee ); + } + + if( $this->order->get_total_tax() ) { + $order_summary['taxAmount'] = $this->formattedPrice( $this->order->get_total_tax() ); + } + + if( $this->order->get_total_discount() ) { + $order_summary['discount']['amount'] = $this->formattedPrice( $this->order->get_total_discount() ); + } + + return array_merge( + $order_summary, + $this->getOrder() + ); + } } /** @@ -175,8 +246,9 @@ public function getHostedCheckoutOrder() { // phpcs:ignore * @return array */ public function getOrder() { // phpcs:ignore + $order_total = $this->order->get_total(); return array( - 'amount' => $this->formattedPrice( $this->order->get_total() ), + 'amount' => $this->formattedPrice( $order_total ), 'currency' => get_woocommerce_currency(), ); } @@ -209,19 +281,57 @@ public function formattedPrice( $price ) { // phpcs:ignore * @return array */ public function getInteraction( $capture = true, $return_url = null ) { // phpcs:ignore - return array( - 'merchant' => array( - 'name' => esc_html( get_bloginfo( 'name', 'display' ) ), - ), - 'returnUrl' => $return_url, - 'displayControl' => array( - 'customerEmail' => 'HIDE', - 'billingAddress' => 'HIDE', - 'paymentTerms' => 'HIDE', - 'shipping' => 'HIDE', - ), - 'operation' => $capture ? 'PURCHASE' : 'AUTHORIZE', + $merchant_interaction = array(); + + if( 'yes' === $this->gateway->mif_enabled ) { + $merchant_name = $this->gateway->get_option( 'merchant_name' ); + $sitename = get_bloginfo( 'name', 'display' ); + $merchant_name = $merchant_name ? preg_replace( "/['\"]/", '', $merchant_name ) : $sitename; + $merchant_name = $this->getExcerpt( $merchant_name, 39 ); + + $merchant = array( + 'name' => esc_html( $merchant_name ), + 'address' => array( + 'line1' => $this->getExcerpt( $this->gateway->get_option( 'merchant_address_line1' ), 100 ), + 'line2' => $this->getExcerpt( $this->gateway->get_option( 'merchant_address_line2' ), 100 ), + 'line3' => $this->getExcerpt( $this->gateway->get_option( 'merchant_address_line3' ), 100 ), + 'line4' => $this->getExcerpt( $this->gateway->get_option( 'merchant_address_line4' ), 100 ) + ) + ); + + if( $this->gateway->get_option( 'merchant_email' ) ) { + $merchant['email'] = $this->gateway->get_option( 'merchant_email' ); + } + + if( $this->gateway->get_option( 'merchant_logo' ) ) { + $merchant['logo'] = self::force_https_url( $this->gateway->get_option( 'merchant_logo' ) ); + } + + if( $this->gateway->get_option( 'merchant_phone' ) ) { + $merchant['phone'] = $this->getExcerpt( $this->gateway->get_option( 'merchant_phone' ), 20 ); + } + + $merchant_interaction['merchant'] = $merchant; + } else { + $sitename = $this->getExcerpt( get_bloginfo( 'name', 'display' ), 39 ); + $merchant_interaction['merchant']['name'] = $sitename; + } + + $interaction = array_merge( + $merchant_interaction, + array( + 'returnUrl' => $return_url, + 'displayControl' => array( + 'customerEmail' => 'HIDE', + 'billingAddress' => 'HIDE', + 'paymentTerms' => 'HIDE', + 'shipping' => 'HIDE', + ), + 'operation' => $capture ? 'PURCHASE' : 'AUTHORIZE', + ) ); + + return $interaction; } /** @@ -234,10 +344,15 @@ public function getInteraction( $capture = true, $return_url = null ) { // phpcs * @deprecated */ public function getLegacyInteraction( $capture = true, $return_url = null ) { // phpcs:ignore + $merchant_name = $this->gateway->get_option( 'merchant_name' ); + $sitename = get_bloginfo( 'name', 'display' ); + $merchant_name = $merchant_name ? $merchant_name : $sitename; + $merchant_name = $this->getExcerpt( $merchant_name, 39 ); + return array( 'operation' => $capture ? 'PURCHASE' : 'AUTHORIZE', 'merchant' => array( - 'name' => esc_html( get_bloginfo( 'name', 'display' ) ), + 'name' => esc_html( $merchant_name ), ), 'returnUrl' => $return_url, 'displayControl' => array( @@ -249,4 +364,48 @@ public function getLegacyInteraction( $capture = true, $return_url = null ) { // ), ); } + + /** + * Create an excerpt from a given text. + * + * @param string $text The text to create an excerpt from. + * @param int $length The length of the excerpt (number of words). + * @return string The excerpt. + */ + public function getExcerpt( $text, $length = 50 ) { + if ( strlen( $text ) > $length ) { + $excerpt = substr( $text, 0, $length ); + } else { + $excerpt = $text; + } + + return $this->attempt_transliteration( $excerpt ); + } + + /** + * Force https for urls. + * + * @param mixed $content + * @return string + */ + public static function force_https_url( $url ) { + return str_replace( 'http:', 'https:', (string) $url ); + } + + public function attempt_transliteration( $field ) { + $encode = mb_detect_encoding( $field ); + if ( $encode !== 'ASCII' ) { + if ( function_exists( 'transliterator_transliterate' ) ) { + $field = transliterator_transliterate( 'Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove', $field ); + } else { + // fall back to iconv if intl module not available + $field = remove_accents( $field ); + $field = iconv( $encode, 'ASCII//TRANSLIT//IGNORE', $field ); + $field = str_ireplace( '?', '', $field ); + $field = trim( $field ); + } + } + + return $field; + } } diff --git a/includes/class-gateway-blocks-support.php b/includes/class-gateway-blocks-support.php index 5e97bfb..156be67 100755 --- a/includes/class-gateway-blocks-support.php +++ b/includes/class-gateway-blocks-support.php @@ -15,7 +15,7 @@ * limitations under the License. * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ @@ -28,7 +28,7 @@ /** * Class Mastercard_Gateway_Blocks. * - * @since 1.4.4 + * @since 1.4.5 */ final class Mastercard_Gateway_Blocks_Support extends AbstractPaymentMethodType { /** diff --git a/includes/class-gateway-notification.php b/includes/class-gateway-notification.php index e7dadaa..4384ba8 100755 --- a/includes/class-gateway-notification.php +++ b/includes/class-gateway-notification.php @@ -15,7 +15,7 @@ * limitations under the License. * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ @@ -171,7 +171,6 @@ public function mgps_new_version_check() { $mgps_plugin_info->plugin = $plugin_file; $mgps_plugin_info->new_version = $latest_version; $mgps_plugin_info->url = 'https://api.' . $this->base_url . '/repos/' . $this->owner . '/' . $this->repo; - // $mgps_plugin_info->package = $response_body['assets'][0]['browser_download_url']; $mgps_plugin_info->package = ""; $mgps_plugin_info->icons = array(); $mgps_plugin_info->banners = array(); @@ -236,17 +235,6 @@ public function clear_mgps_target_module_new_version_check() { */ public function update_database() { update_option( '_mgps_target_module_version', MPGS_TARGET_MODULE_VERSION ); - $settings_options = get_option( 'woocommerce_' . $this->id . '_settings' ); - - if ( ! empty( $settings_options ) || isset( $settings_options ) ) { - if ( 'newhostedcheckout' === $settings_options['method'] ) { - $settings_options['method'] = 'hosted_checkout'; - } elseif ( 'hostedsession' === $settings_options['method'] ) { - $settings_options['method'] = 'hosted_session'; - } - - update_option( 'woocommerce_' . $this->id . '_settings', $settings_options ); - } } /** diff --git a/includes/class-gateway-service.php b/includes/class-gateway-service.php index d96f741..e8ddfdf 100755 --- a/includes/class-gateway-service.php +++ b/includes/class-gateway-service.php @@ -15,7 +15,7 @@ * limitations under the License. * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ @@ -91,6 +91,20 @@ class Mastercard_GatewayService { */ protected $webhook_url = null; + /** + * Webhook endpoint variable + * + * @var string|null + */ + protected $username; + + /** + * Webhook endpoint variable + * + * @var string|null + */ + protected $password; + /** * GatewayService constructor. * @@ -123,14 +137,15 @@ public function __construct( $this->message_factory = new Psr17Factory(); $this->api_url = 'https://' . $base_url . '/api/rest/' . $api_version . '/merchant/' . $merchant_id . '/'; - $username = 'merchant.' . $merchant_id; + $this->username = 'merchant.' . $merchant_id; + $this->password = $password; $client = new PluginClient( HttpClientDiscovery::find(), array( new ContentLengthPlugin(), new HeaderSetPlugin( array( 'Content-Type' => 'application/json;charset=UTF-8' ) ), - new AuthenticationPlugin( new BasicAuth( $username, $password ) ), + new AuthenticationPlugin( new BasicAuth( $this->username, $this->password ) ), new Mastercard_ApiErrorPlugin( $logger ), new Mastercard_ApiLoggerPlugin( $logger ), ) @@ -165,7 +180,7 @@ protected function getSolutionId() { // phpcs:ignore * * @return mixed The safely handled value. */ - public static function safe( $value, $limited = 0 ) { + public static function is_safe( $value, $limited = 0 ) { if ( '' === $value ) { return null; } @@ -251,7 +266,7 @@ public function validateSessionResponse( $data ) { // phpcs:ignore * @return void */ public function validateTxnResponse( $data ) { // phpcs:ignore - // @todo + return $data; } /** @@ -262,7 +277,7 @@ public function validateTxnResponse( $data ) { // phpcs:ignore * @return void */ public function validateOrderResponse( $data ) { // phpcs:ignore - // @todo + return $data; } /** @@ -273,7 +288,7 @@ public function validateOrderResponse( $data ) { // phpcs:ignore * @return void */ public function validateVoidResponse( $data ) { // phpcs:ignore - // @todo + return $data; } /** @@ -412,8 +427,8 @@ public function initiateCheckout( // phpcs:ignore $order, array( 'notificationUrl' => $this->webhook_url, - 'reference' => $order['id'], - ), + 'reference' => $order['id'], + ), ), 'billing' => $billing, 'shipping' => $shipping, @@ -424,6 +439,7 @@ public function initiateCheckout( // phpcs:ignore 'source' => 'INTERNET', ), ); + $request = $this->message_factory->createRequest( 'POST', $uri, @@ -434,12 +450,14 @@ public function initiateCheckout( // phpcs:ignore $request_data ) ); + $request_body = $request->withBody( $stream ); $response = $this->client->sendRequest( $request_body ); $response = json_decode( $response->getBody(), true ); + $this->validateCheckoutSessionResponse( $response ); return $response; @@ -480,7 +498,7 @@ public function createCheckoutSession( // phpcs:ignore $order, array( 'notificationUrl' => $this->webhook_url, - 'reference' => $order['id'], + 'reference' => $order['id'], ) ), 'billing' => $billing, @@ -501,6 +519,7 @@ public function createCheckoutSession( // phpcs:ignore $request_data ) ); + $request_body = $request->withBody( $stream ); $response = $this->client->sendRequest( $request_body ); $response = json_decode( @@ -543,7 +562,6 @@ public function update_session( 'order_id' => $gateway->remove_order_prefix( $order['id'] ), 'session_id' => $session_id, ); - if ( ! empty( $authentication ) && ! isset( $authentication['acceptVersions'] ) ) { $authentication['redirectResponseUrl'] = add_query_arg( 'wc-api', @@ -758,11 +776,11 @@ public function pay( if ( ! empty( $authentication ) ) { $request_data['authentication'] = $authentication; } - $request = $this->message_factory->createRequest( 'PUT', $uri ); + $stream = $this->message_factory->createStream( wp_json_encode( $request_data diff --git a/includes/class-gateway.php b/includes/class-gateway.php index ab82090..faea60f 100755 --- a/includes/class-gateway.php +++ b/includes/class-gateway.php @@ -15,7 +15,7 @@ * limitations under the License. * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ @@ -23,7 +23,7 @@ exit; // Exit if accessed directly. } -define( 'MPGS_TARGET_MODULE_VERSION', '1.4.6' ); +define( 'MPGS_TARGET_MODULE_VERSION', '1.4.7' ); require_once dirname( __DIR__ ) . '/includes/class-checkout-builder.php'; require_once dirname( __DIR__ ) . '/includes/class-gateway-service.php'; @@ -36,10 +36,11 @@ */ class Mastercard_Gateway extends WC_Payment_Gateway { - const ID = 'mpgs_gateway'; + const ID = 'mpgs_gateway'; + const GATEWAY_TITLE = 'Mastercard Payment Gateway Services'; - const MPGS_API_VERSION = 'version/81'; - const MPGS_API_VERSION_NUM = '81'; + const MPGS_API_VERSION = 'version/84'; + const MPGS_API_VERSION_NUM = '84'; const HOSTED_SESSION = 'hosted-session'; const HOSTED_CHECKOUT = 'hosted-checkout'; @@ -149,6 +150,27 @@ class Mastercard_Gateway extends WC_Payment_Gateway { */ protected $threedsecure_v2 = null; + /** + * Handling fees + * + * @var bool + */ + public $hf_enabled = null; + + /** + * Send Line Items + * + * @var bool + */ + public $send_line_items = null; + + /** + * Merchant Information + * + * @var bool + */ + public $mif_enabled = null; + /** * Saved Cards * @@ -161,10 +183,10 @@ class Mastercard_Gateway extends WC_Payment_Gateway { * * @throws Exception If there's a problem connecting to the gateway. */ - public function __construct() { + public function __construct() { $this->id = self::ID; - $this->title = __( 'Mastercard Payment Gateway Services', 'mastercard' ); - $this->method_title = __( 'Mastercard Payment Gateway Services', 'mastercard' ); + $this->title = __( self::GATEWAY_TITLE, 'mastercard' ); + $this->method_title = __( self::GATEWAY_TITLE, 'mastercard' ); $this->has_fields = true; $this->method_description = __( 'Accept payments on your WooCommerce store using Mastercard Payment Gateway Services.', @@ -191,6 +213,8 @@ public function __construct() { 'tokenization', ); $this->hf_enabled = $this->get_option( 'hf_enabled', false ); + $this->send_line_items = $this->get_option( 'send_line_items', false ); + $this->mif_enabled = $this->get_option( 'mif_enabled', false ); $this->service = $this->init_service(); add_action( @@ -210,6 +234,8 @@ public function __construct() { add_action( 'admin_notices', array( $this, 'admin_notices' ) ); add_filter( 'script_loader_tag', array( $this, 'add_js_extra_attribute' ), 10 ); add_action( 'woocommerce_cart_calculate_fees', array( $this, 'add_handling_fee' ) ); + add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'save_mpgs_handling_fee_on_place_order' ), 10, 2 ); + add_action( 'woocommerce_store_api_checkout_update_order_meta', array( $this, 'save_mpgs_handling_fee_api_on_place_order' ), 10, 1 ); } /** @@ -224,7 +250,7 @@ protected function init_service() { $this->username = 'no' === $this->sandbox ? $this->get_option( 'username' ) : $this->get_option( 'sandbox_username' ); $this->password = 'no' === $this->sandbox ? $this->get_option( 'password' ) : $this->get_option( 'sandbox_password' ); - $logging_level = $this->get_debug_logging_enabled() + $logging_level = $this->is_debug_logging_enabled() ? \Monolog\Logger::DEBUG : \Monolog\Logger::ERROR; @@ -243,7 +269,7 @@ protected function init_service() { * * @return bool True if debug logging is enabled, false otherwise. */ - protected function get_debug_logging_enabled() { + protected function is_debug_logging_enabled() { if ( 'yes' === $this->sandbox ) { return 'yes' === $this->get_option( 'debug', false ); } @@ -256,7 +282,7 @@ protected function get_debug_logging_enabled() { * * @return string The URL of the payment gateway. */ - protected function get_gateway_url() { + public function get_gateway_url() { $gateway_url = $this->get_option( 'gateway_url', self::API_EU ); if ( self::API_CUSTOM === $gateway_url ) { $gateway_url = $this->get_option( 'custom_gateway_url' ); @@ -283,7 +309,7 @@ public function process_admin_options() { } $this->update_option( 'handling_fee_amount', 100 ); } - } + } } $service = $this->init_service(); $service->paymentOptionsInquiry(); @@ -306,6 +332,7 @@ public function admin_scripts() { if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { return; } + wp_enqueue_media(); wp_enqueue_script( 'woocommerce_mastercard_admin', plugins_url( 'assets/js/mastercard-admin.js', __FILE__ ), @@ -321,7 +348,6 @@ public function admin_scripts() { * @return void */ public function payment_gateway_scripts() { - global $wp; $order_id = get_query_var( 'order-pay' ); $order = new WC_Order( $order_id ); if ( $order->get_payment_method() !== $this->id ) { @@ -421,8 +447,8 @@ public function process_capture() { ); $order->update_meta_data( '_mpgs_order_captured', true ); + $order->update_meta_data( '_mpgs_transaction_mode', 'captured' ); $order->save_meta_data(); - $hpos_enabled = get_option( 'woocommerce_custom_orders_table_enabled' ); if ( wp_get_referer() || 'yes' !== WC_Mastercard::is_hpos() ) { wp_safe_redirect( wp_get_referer() ); @@ -461,7 +487,7 @@ public function void_authorized_order() { throw new Exception( 'Order already reversed' ); } - $transaction_id = $order->get_meta( '_mpgs_transaction_id' ); + $transaction_id = $order->get_meta( '_mpgs_transaction_id' ); if( $transaction_id === $auth_txn['transaction']['id'] || $transaction_id === $auth_txn['authentication']['transactionId'] ) { $result = $this->service->voidTxn( @@ -470,6 +496,7 @@ public function void_authorized_order() { ); if( 'SUCCESS' === $result['result'] ) { + $order->update_meta_data( '_mpgs_transaction_mode', 'void' ); $txn = $result['transaction']; $order->update_status( 'cancelled', sprintf( __( 'Gateway reverse authorization (ID: %s)', 'mastercard' ), @@ -495,7 +522,7 @@ public function void_authorized_order() { wp_die( $e->getMessage(), __( 'Gateway reverse authorization failure.' ) ); } } - + /** * This function displays admin notices. * @@ -677,7 +704,8 @@ protected function get_token_key() { * * @return void */ - protected function process_hosted_session_payment( $three_ds_txn_id = null ) { + protected function process_hosted_session_payment( $three_ds_txn_id = null ) { + $order_id = isset( $_REQUEST['order_id'] ) ? $this->remove_order_prefix( sanitize_text_field( wp_unslash( $_REQUEST['order_id'] ) ) ) : null; // phpcs:ignore $session_id = isset( $_REQUEST['session_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['session_id'] ) ) : null; // phpcs:ignore $session_version = isset( $_REQUEST['session_version'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['session_version'] ) ) : null; // phpcs:ignore @@ -752,7 +780,7 @@ protected function process_hosted_session_payment( $three_ds_txn_id = null ) { exit(); } - $this->pay( $session, $order ); + $this->pay( $session, $order, null ); } if ( $process_acl_result && wp_verify_nonce( $mgps_3ds_nonce, 'mastercard_3ds_nonce' ) ) { @@ -775,7 +803,7 @@ protected function process_hosted_session_payment( $three_ds_txn_id = null ) { } if ( ! $check_3ds && ! $process_acl_result && ! $this->threedsecure_v1 ) { - $this->pay( $session, $order ); + $this->pay( $session, $order, null ); } $order->update_status( 'failed', __( 'Unexpected payment condition error.', 'mastercard' ) ); @@ -838,7 +866,7 @@ protected function pay( $session, $order, $tds_id = null ) { } if ( 'SUCCESS' !== $mpgs_txn['result'] ) { - $gateway_code = $mpgs_txn['response']['gatewayCode']; + $gateway_code = $mpgs_txn['response']['gatewayCode']; if ( 'DECLINED' === $gateway_code ) { throw new Exception( __( 'Payment unsuccessful; your card has been declined.', 'mastercard' ) ); @@ -850,7 +878,7 @@ protected function pay( $session, $order, $tds_id = null ) { throw new Exception( __( 'The transaction was disrupted due to an issue in the acquirer\'s system.', 'mastercard' ) ); } elseif ( 'UNSPECIFIED_FAILURE' === $gateway_code ) { throw new Exception( __( 'An unspecified issue has occurred with your card. Please check the details and try again.', 'mastercard' ) ); - } elseif ( 'EXPIRED_CARD' === $gateway_code ) { + } elseif ( 'AUTHORIZATION_FAILED' === $gateway_code ) { throw new Exception( __( 'The card not authorized. Please enter a new card for payment.', 'mastercard' ) ); } else { throw new Exception( __( 'Payment was declined.', 'mastercard' ) ); @@ -860,7 +888,7 @@ protected function pay( $session, $order, $tds_id = null ) { $this->process_wc_order( $order, $mpgs_txn['order'], $mpgs_txn ); if ( $this->saved_cards && $order->get_meta( '_save_card' ) ) { - $this->process_saved_cards( $session, $order->get_user_id( 'system' ) ); + $this->process_saved_cards( $session, $order->get_user_id( 'system' ) ); } wp_safe_redirect( $this->get_return_url( $order ) ); @@ -923,7 +951,9 @@ protected function process_saved_cards( $session, $user_id ) { protected function process_wc_order( $order, $order_data, $txn_data ) { $this->validate_order( $order, $order_data ); $captured = 'CAPTURED' === $order_data['status']; + $transaction_mode = ( $this->capture ) ? self::TXN_MODE_PURCHASE : self::TXN_MODE_AUTH_CAPTURE; $order->add_meta_data( '_mpgs_order_captured', $captured ); + $order->add_meta_data( '_mpgs_transaction_mode', $transaction_mode ); $order->add_meta_data( '_mpgs_order_paid', 1 ); $order->add_meta_data( '_mpgs_transaction_id', $txn_data['transaction']['id'] ); $order->add_meta_data( '_mpgs_transaction_reference', $txn_data['transaction']['reference'] ); @@ -1149,7 +1179,7 @@ public function rest_route_processor( $route, $request ) { $order_builder->getCustomer(), $order_builder->getBilling(), $order_builder->getShipping() - ); + ); if ( $result && $result['successIndicator'] ) { $order->update_meta_data( '_mpgs_success_indicator', $result['successIndicator'] ); @@ -1227,9 +1257,11 @@ public function rest_route_processor( $route, $request ) { } $order->save_meta_data(); break; - case '/mastercard/v1/webhook': break; + + default: + break; } return $result; @@ -1302,7 +1334,7 @@ public function receipt_page( $order_id ) { $order = new WC_Order( $order_id ); set_query_var( 'order', $order ); - set_query_var( 'gateway', $this ); + set_query_var( 'gateway', $this ); if ( self::HOSTED_SESSION === $this->method ) { $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; @@ -1332,205 +1364,7 @@ public function receipt_page( $order_id ) { * @return void */ public function init_form_fields() { - $this->form_fields = array( - 'heading' => array( - 'title' => null, - 'type' => 'title', - 'description' => sprintf( - /* translators: 1. MPGS module vesion, 2. MPGS API version. */ - __( 'Plugin version: %1$s
API version: %2$s', 'mastercard' ), - MPGS_TARGET_MODULE_VERSION, - self::MPGS_API_VERSION_NUM - ), - ), - 'enabled' => array( - 'title' => __( 'Enable/Disable', 'mastercard' ), - 'label' => __( 'Enable', 'mastercard' ), - 'type' => 'checkbox', - 'description' => '', - 'default' => 'no', - ), - 'title' => array( - 'title' => __( 'Title', 'mastercard' ), - 'type' => 'text', - 'description' => __( 'This controls the title which the user sees during checkout.', 'mastercard' ), - 'default' => __( 'Mastercard Payment Gateway Services', 'mastercard' ), - 'css' => 'min-height: 33px;' - ), - 'description' => array( - 'title' => __( 'Description', 'mastercard' ), - 'type' => 'text', - 'description' => __( 'The description displayed when this payment method is selected.', 'mastercard' ), - 'default' => 'Pay with your card via Mastercard.', - 'css' => 'min-height: 33px;' - ), - 'gateway_url' => array( - 'title' => __( 'Gateway', 'mastercard' ), - 'type' => 'select', - 'options' => array( - self::API_AS => __( 'Asia Pacific', 'mastercard' ), - self::API_EU => __( 'Europe', 'mastercard' ), - self::API_NA => __( 'North America', 'mastercard' ), - self::API_CUSTOM => __( 'Custom URL', 'mastercard' ), - ), - 'default' => self::API_EU, - ), - 'custom_gateway_url' => array( - 'title' => __( 'Custom Gateway Host', 'mastercard' ), - 'type' => 'text', - 'description' => __( 'Enter only the hostname without https prefix. For example na.gateway.mastercard.com.', 'mastercard' ), - 'css' => 'min-height: 33px;' - ), - 'txn_mode' => array( - 'title' => __( 'Transaction Mode', 'mastercard' ), - 'type' => 'select', - 'options' => array( - self::TXN_MODE_PURCHASE => __( 'Purchase', 'mastercard' ), - self::TXN_MODE_AUTH_CAPTURE => __( 'Authorize', 'mastercard' ), - ), - 'default' => self::TXN_MODE_PURCHASE, - 'description' => __( 'In “Purchase” mode, the customer is charged immediately. In Authorize mode, the transaction is only authorized and the capturing of funds is a manual process that you do using the Woocommerce admin panel.', 'mastercard' ), - ), - 'method' => array( - 'title' => __( 'Integration Model', 'mastercard' ), - 'type' => 'select', - 'options' => array( - self::HOSTED_CHECKOUT => __( 'Hosted Checkout', 'mastercard' ), - self::HOSTED_SESSION => __( 'Hosted Session', 'mastercard' ), - ), - 'default' => self::HOSTED_CHECKOUT, - ), - 'threedsecure' => array( - 'title' => __( '3D-Secure', 'mastercard' ), - 'label' => __( 'Use 3D-Secure', 'mastercard' ), - 'type' => 'select', - 'options' => array( - self::THREED_DISABLED => __( 'Disabled' ), - self::THREED_V1 => __( '3DS1' ), - self::THREED_V2 => __( '3DS2 (with fallback to 3DS1)' ), - ), - 'default' => self::THREED_DISABLED, - 'description' => __( 'For more information please contact your payment service provider.', 'mastercard' ), - ), - 'hc_interaction' => array( - 'title' => __( 'Checkout Interaction', 'mastercard' ), - 'type' => 'select', - 'options' => array( - self::HC_TYPE_REDIRECT => __( 'Redirect to Payment Page', 'mastercard' ), - self::HC_TYPE_EMBEDDED => __( 'Embedded', 'mastercard' ), - ), - 'default' => self::HC_TYPE_EMBEDDED, - ), - 'hc_type' => array( - 'title' => __( 'Checkout Interaction', 'mastercard' ), - 'type' => 'select', - 'options' => array( - self::HC_TYPE_REDIRECT => __( 'Redirect to Payment Page', 'mastercard' ), - self::HC_TYPE_MODAL => __( 'Lightbox', 'mastercard' ), - ), - 'default' => self::HC_TYPE_MODAL, - ), - 'saved_cards' => array( - 'title' => __( 'Saved Cards', 'mastercard' ), - 'label' => __( 'Enable payment via saved tokenized cards', 'mastercard' ), - 'type' => 'checkbox', - 'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved in the payment gateway, not on your store.', 'mastercard' ), - 'default' => 'yes', - ), - 'debug' => array( - 'title' => __( 'Debug Logging', 'mastercard' ), - 'label' => __( 'Enable Debug Logging', 'mastercard' ), - 'type' => 'checkbox', - 'description' => __( 'Logs all communication with Mastercard gateway to file ./wp-content/mastercard.log. Debug logging only works in Sandbox mode.', 'mastercard' ), - 'default' => 'no', - ), - 'api_details' => array( - 'title' => __( 'API credentials', 'mastercard' ), - 'type' => 'title', - 'description' => sprintf( - /* translators: Gateway API Credentials */ - __( 'Enter your API credentials to process payments via this payment gateway. Learn how to access your Gateway API Credentials.', 'mastercard' ), - 'https://test-gateway.mastercard.com/api/documentation/integrationGuidelines/supportedFeatures/pickSecurityModel/secureYourIntegration.html?locale=en_US' - ), - ), - 'sandbox' => array( - 'title' => __( 'Test Sandbox', 'mastercard' ), - 'label' => __( 'Enable test sandbox mode', 'mastercard' ), - 'type' => 'checkbox', - 'description' => __( 'Place the payment gateway in test mode using test API credentials (real payments will not be taken).', 'mastercard' ), - 'default' => 'yes', - ), - 'sandbox_username' => array( - 'title' => __( 'Test Merchant ID', 'mastercard' ), - 'type' => 'text', - 'description' => __( 'This is your test merchant profile ID prefixed with TEST.', 'mastercard' ), - 'default' => '', - 'css' => 'min-height: 33px;' - ), - 'sandbox_password' => array( - 'title' => __( 'Test API Password', 'mastercard' ), - 'type' => 'password', - 'description' => __( 'This is your test API password.', 'mastercard' ), - 'default' => '', - 'css' => 'min-height: 33px;' - ), - 'username' => array( - 'title' => __( 'Merchant ID', 'mastercard' ), - 'type' => 'text', - 'description' => __( 'This is your merchant profile ID.', 'mastercard' ), - 'default' => '', - 'css' => 'min-height: 33px;' - ), - 'password' => array( - 'title' => __( 'API Password', 'mastercard' ), - 'type' => 'password', - 'description' => __( 'This is your API password.', 'mastercard' ), - 'default' => '', - 'css' => 'min-height: 33px;' - ), - 'order_prefix' => array( - 'title' => __( 'Order ID prefix', 'mastercard' ), - 'type' => 'text', - 'description' => __( 'Should be specified in case multiple integrations use the same Merchant ID.', 'mastercard' ), - 'default' => '', - 'css' => 'min-height: 33px;' - ), - 'handling_fee' => array( - 'title' => __( 'Handling Fee', 'mastercard' ), - 'type' => 'title', - 'description' => __( 'The handling amount for the order, including taxes on the handling.', 'mastercard' ), - ), - 'hf_enabled' => array( - 'title' => __( 'Enable/Disable', 'mastercard' ), - 'label' => __( 'Enable', 'mastercard' ), - 'type' => 'checkbox', - 'description' => '', - 'default' => 'no', - ), - 'handling_text' => array( - 'title' => __( 'Handling Fee Text', 'mastercard' ), - 'type' => 'text', - 'description' => __( 'Display text for handling fee.', 'mastercard' ), - 'default' => '', - 'css' => 'min-height: 33px;' - ), - 'hf_amount_type' => array( - 'title' => __( 'Applicable Amount Type', 'mastercard' ), - 'type' => 'select', - 'options' => array( - self::HF_FIXED => __( 'Fixed', 'mastercard' ), - self::HF_PERCENTAGE => __( 'Percentage', 'mastercard' ), - ), - 'default' => self::HF_FIXED, - ), - 'handling_fee_amount' => array( - 'title' => __( 'Amount', 'mastercard' ), - 'type' => 'text', - 'description' => __( 'The total amount for handling fee; Eg: 10.00 or 10%.', 'mastercard' ), - 'default' => '', - 'css' => 'min-height: 33px;' - ) - ); + $this->form_fields = include dirname( __DIR__ ) . '/includes/settings-mastercard.php'; } /** @@ -1668,7 +1502,58 @@ public function add_handling_fee() { $surcharge = $handling_fee; } + if ( WC()->session ) { + WC()->session->set( 'mpgs_handling_fee', $surcharge ); + } + WC()->cart->add_fee( $handling_text, $surcharge, true, '' ); } } + + /** + * Save MasterCard Payment Gateway Services (MPGS) handling fee to the order. + * + * This function is triggered during the WooCommerce checkout process, right after the + * "Place Order" button is clicked and the order is being created. It adds the handling + * fee related to MPGS to the order metadata, which can later be used for calculations, + * displaying fees in the backend, or other custom logic. + * + * @param WC_Order $order_id The order id. + * @param array $data The posted data during checkout process (billing, shipping, etc.). + */ + public function save_mpgs_handling_fee_on_place_order( $order_id, $data ) { + if ( isset( $this->hf_enabled ) && 'yes' === $this->hf_enabled ) { + if ( $order_id ) { + $order = wc_get_order( $order_id ); + $handling_fee = WC()->session->get( 'mpgs_handling_fee' ); + $order->update_meta_data( '_mpgs_handling_fee', $handling_fee ); + $order->save(); + WC()->session->__unset( '_mpgs_handling_fee' ); + } + } else { + WC()->session->__unset( '_mpgs_handling_fee' ); + } + } + + /** + * Save MasterCard Payment Gateway Services (MPGS) handling fee to the order through WooCommerce checkout block. + * + * This function is triggered during the WooCommerce checkout process, right after the + * "Place Order" button is clicked and the order is being created. It adds the handling + * fee related to MPGS to the order metadata, which can later be used for calculations, + * displaying fees in the backend, or other custom logic. + * + * @param WC_Order $order_id The order id. + */ + public function save_mpgs_handling_fee_api_on_place_order( $order ) { + if ( isset( $this->hf_enabled ) && 'yes' === $this->hf_enabled ) { + if ( $order ) { + $handling_fee = WC()->session->get( 'mpgs_handling_fee' ); + $order->update_meta_data( '_mpgs_handling_fee', $handling_fee ); + WC()->session->__unset( '_mpgs_handling_fee' ); + } + } else { + WC()->session->__unset( '_mpgs_handling_fee' ); + } + } } diff --git a/includes/class-payment-gateway-cc.php b/includes/class-payment-gateway-cc.php index 04fb023..6672ffe 100755 --- a/includes/class-payment-gateway-cc.php +++ b/includes/class-payment-gateway-cc.php @@ -15,7 +15,7 @@ * limitations under the License. * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ @@ -56,22 +56,18 @@ public function form() { $cvc_field = '

- field_name( 'card-cvc' ) . ' style="width:100px" /> -

'; + field_name( 'card-cvc' ) . ' style="width:100px" />

'; $default_fields = array( 'card-number-field' => '

- field_name( 'card-number' ) . ' /> -

', + field_name( 'card-number' ) . ' />

', 'card-expiry-month-field' => '

- field_name( 'card-expiry-month' ) . ' /> -

', + field_name( 'card-expiry-month' ) . ' />

', 'card-expiry-year-field' => '

- field_name( 'card-expiry-year' ) . ' /> -

', + field_name( 'card-expiry-year' ) . ' />

', ); $default_fields['card-cvc-field'] = $cvc_field; diff --git a/includes/logger/class-api-error-plugin.php b/includes/logger/class-api-error-plugin.php index f6b2efc..6547305 100755 --- a/includes/logger/class-api-error-plugin.php +++ b/includes/logger/class-api-error-plugin.php @@ -15,7 +15,7 @@ * limitations under the License. * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ diff --git a/includes/logger/class-api-logger-plugin.php b/includes/logger/class-api-logger-plugin.php index 69b2993..828e1ab 100755 --- a/includes/logger/class-api-logger-plugin.php +++ b/includes/logger/class-api-logger-plugin.php @@ -15,7 +15,7 @@ * limitations under the License. * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ @@ -103,12 +103,8 @@ public function handleRequest( RequestInterface $request, callable $next, callab ); return $next( $request )->then( - function ( - ResponseInterface $response - ) use ( - $request - ) { - $body = json_decode( $response->getBody(), true ); + function ( ResponseInterface $response ) use ( $request ) { + $body = json_decode( $response->getBody(), true ); if ( json_last_error() !== JSON_ERROR_NONE ) { $body = $response->getBody(); } diff --git a/includes/logger/class-gateway-response-exception.php b/includes/logger/class-gateway-response-exception.php index cd9f4c9..a2d0432 100755 --- a/includes/logger/class-gateway-response-exception.php +++ b/includes/logger/class-gateway-response-exception.php @@ -15,7 +15,7 @@ * limitations under the License. * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ diff --git a/includes/settings-mastercard.php b/includes/settings-mastercard.php new file mode 100755 index 0000000..0085a57 --- /dev/null +++ b/includes/settings-mastercard.php @@ -0,0 +1,284 @@ + array( + 'title' => null, + 'type' => 'title', + 'description' => sprintf( + /* translators: 1. MPGS module vesion, 2. MPGS API version. */ + __( 'Plugin version: %1$s
API version: %2$s', 'mastercard' ), + MPGS_TARGET_MODULE_VERSION, + self::MPGS_API_VERSION_NUM + ), + ), + 'enabled' => array( + 'title' => __( 'Enable/Disable', 'mastercard' ), + 'label' => __( 'Enable', 'mastercard' ), + 'type' => 'checkbox', + 'description' => '', + 'default' => 'no', + ), + 'title' => array( + 'title' => __( 'Title', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'This controls the title which the user sees during checkout.', 'mastercard' ), + 'default' => __( 'Mastercard Payment Gateway Services', 'mastercard' ), + 'css' => 'min-height: 33px;' + ), + 'description' => array( + 'title' => __( 'Description', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'The description displayed when this payment method is selected.', 'mastercard' ), + 'default' => 'Pay with your card via Mastercard.', + 'css' => 'min-height: 33px;' + ), + 'gateway_url' => array( + 'title' => __( 'Gateway', 'mastercard' ), + 'type' => 'select', + 'options' => array( + self::API_AS => __( 'Asia Pacific', 'mastercard' ), + self::API_EU => __( 'Europe', 'mastercard' ), + self::API_NA => __( 'North America', 'mastercard' ), + self::API_CUSTOM => __( 'Custom URL', 'mastercard' ), + ), + 'default' => self::API_EU, + ), + 'custom_gateway_url' => array( + 'title' => __( 'Custom Gateway Host', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'Enter only the hostname without https prefix. For example na.gateway.mastercard.com.', 'mastercard' ), + 'css' => 'min-height: 33px;' + ), + 'txn_mode' => array( + 'title' => __( 'Transaction Mode', 'mastercard' ), + 'type' => 'select', + 'options' => array( + self::TXN_MODE_PURCHASE => __( 'Purchase', 'mastercard' ), + self::TXN_MODE_AUTH_CAPTURE => __( 'Authorize', 'mastercard' ), + ), + 'default' => self::TXN_MODE_PURCHASE, + 'description' => __( 'In “Purchase” mode, the customer is charged immediately. In Authorize mode, the transaction is only authorized and the capturing of funds is a manual process that you do using the Woocommerce admin panel.', 'mastercard' ), + ), + 'method' => array( + 'title' => __( 'Integration Model', 'mastercard' ), + 'type' => 'select', + 'options' => array( + self::HOSTED_CHECKOUT => __( 'Hosted Checkout', 'mastercard' ), + self::HOSTED_SESSION => __( 'Hosted Session', 'mastercard' ), + ), + 'default' => self::HOSTED_CHECKOUT, + ), + 'threedsecure' => array( + 'title' => __( '3D-Secure', 'mastercard' ), + 'label' => __( 'Use 3D-Secure', 'mastercard' ), + 'type' => 'select', + 'options' => array( + self::THREED_DISABLED => __( 'Disabled' ), + self::THREED_V1 => __( '3DS1' ), + self::THREED_V2 => __( '3DS2 (with fallback to 3DS1)' ), + ), + 'default' => self::THREED_DISABLED, + 'description' => __( 'For more information please contact your payment service provider.', 'mastercard' ), + ), + 'hc_interaction' => array( + 'title' => __( 'Checkout Interaction', 'mastercard' ), + 'type' => 'select', + 'options' => array( + self::HC_TYPE_REDIRECT => __( 'Redirect to Payment Page', 'mastercard' ), + self::HC_TYPE_EMBEDDED => __( 'Embedded', 'mastercard' ), + ), + 'default' => self::HC_TYPE_EMBEDDED, + 'description' => __( 'Selecting "Redirect to Payment Page" will also allow you to configure your business logo and related information in the Merchant Information section below.', 'mastercard' ), + ), + 'hc_type' => array( + 'title' => __( 'Checkout Interaction', 'mastercard' ), + 'type' => 'select', + 'options' => array( + self::HC_TYPE_REDIRECT => __( 'Redirect to Payment Page', 'mastercard' ), + self::HC_TYPE_MODAL => __( 'Lightbox', 'mastercard' ), + ), + 'default' => self::HC_TYPE_MODAL, + ), + 'saved_cards' => array( + 'title' => __( 'Saved Cards', 'mastercard' ), + 'label' => __( 'Enable payment via saved tokenized cards', 'mastercard' ), + 'type' => 'checkbox', + 'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved in the payment gateway, not on your store.', 'mastercard' ), + 'default' => 'yes', + ), + 'debug' => array( + 'title' => __( 'Debug Logging', 'mastercard' ), + 'label' => __( 'Enable Debug Logging', 'mastercard' ), + 'type' => 'checkbox', + 'description' => __( 'Logs all communication with Mastercard gateway to file ./wp-content/mastercard.log. Debug logging only works in Sandbox mode.', 'mastercard' ), + 'default' => 'no', + ), + 'send_line_items' => array( + 'title' => __( 'Send Line Items', 'mastercard' ), + 'label' => __( 'Enable Send Line Items', 'mastercard' ), + 'type' => 'checkbox', + 'description' => __( 'Enable the transmission of additional data to the Mastercard Gateway.', 'mastercard' ), + 'default' => 'no', + ), + 'api_details' => array( + 'title' => __( 'API Credentials', 'mastercard' ), + 'type' => 'title', + 'description' => sprintf( + /* translators: Gateway API Credentials */ + __( 'Enter your API credentials to process payments via this payment gateway. Learn how to access your Gateway API Credentials.', 'mastercard' ), + 'https://mpgs.fingent.wiki/enterprise/woocommerce-mastercard-payment-gateway-services/configuration/generate-api-password' + ), + ), + 'sandbox' => array( + 'title' => __( 'Test Sandbox', 'mastercard' ), + 'label' => __( 'Enable test sandbox mode', 'mastercard' ), + 'type' => 'checkbox', + 'description' => __( 'Place the payment gateway in test mode using test API credentials (real payments will not be taken).', 'mastercard' ), + 'default' => 'yes', + ), + 'sandbox_username' => array( + 'title' => __( 'Test Merchant ID', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'This is your test merchant profile ID prefixed with TEST.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;' + ), + 'sandbox_password' => array( + 'title' => __( 'Test API Password', 'mastercard' ), + 'type' => 'password', + 'description' => __( 'This is your test API password.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;' + ), + 'username' => array( + 'title' => __( 'Merchant ID', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'This is your merchant profile ID.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;' + ), + 'password' => array( + 'title' => __( 'API Password', 'mastercard' ), + 'type' => 'password', + 'description' => __( 'This is your API password.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;' + ), + 'order_prefix' => array( + 'title' => __( 'Order ID Prefix', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'Should be specified in case multiple integrations use the same Merchant ID.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;' + ), + 'handling_fee' => array( + 'title' => __( 'Handling Fee', 'mastercard' ), + 'type' => 'title', + 'description' => __( 'The handling amount for the order, including taxes on the handling.', 'mastercard' ), + ), + 'hf_enabled' => array( + 'title' => __( 'Enable/Disable', 'mastercard' ), + 'label' => __( 'Enable', 'mastercard' ), + 'type' => 'checkbox', + 'description' => '', + 'default' => 'no', + ), + 'handling_text' => array( + 'title' => __( 'Handling Fee Text', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'Display text for handling fee.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;' + ), + 'hf_amount_type' => array( + 'title' => __( 'Applicable Amount Type', 'mastercard' ), + 'type' => 'select', + 'options' => array( + self::HF_FIXED => __( 'Fixed', 'mastercard' ), + self::HF_PERCENTAGE => __( 'Percentage', 'mastercard' ), + ), + 'default' => self::HF_FIXED, + ), + 'handling_fee_amount' => array( + 'title' => __( 'Amount', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'The total amount for handling fee; Eg: 10.00 or 10%.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;', + ), + 'merchant_info' => array( + 'title' => __( 'Merchant Information', 'mastercard' ), + 'type' => 'title', + 'description' => __( 'This section appears only when "Redirect to Payment Page" is selected for Checkout Interaction. Configuring the details below allows them to be displayed on Mastercard’s redirected payment page.', 'mastercard' ), + ), + 'mif_enabled' => array( + 'title' => __( 'Enable/Disable', 'mastercard' ), + 'label' => __( 'Enable', 'mastercard' ), + 'type' => 'checkbox', + 'description' => '', + 'default' => 'no', + ), + 'merchant_name' => array( + 'title' => __( 'Merchant Name', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'Name of your business (up to 40 characters) to be shown to the payer during the payment interaction.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;' + ), + 'merchant_address_line1' => array( + 'title' => __( 'Address line 1', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'The first line of your business address (up to 100 characters) to be shown to the payer during the payment interaction.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;' + ), + 'merchant_address_line2' => array( + 'title' => __( 'Address line 2', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'The second line of your business address (up to 100 characters) to be shown to the payer during the payment interaction.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;' + ), + 'merchant_address_line3' => array( + 'title' => __( 'Postcode / ZIP', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'The postal or ZIP code of your business address (up to 100 characters) to be shown to the payer during the payment interaction.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;' + ), + 'merchant_address_line4' => array( + 'title' => __( 'Country / State', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'The country or state of your business address (up to 100 characters) to be shown to the payer during the payment interaction.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;' + ), + 'merchant_email' => array( + 'title' => __( 'Email', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'The email address of your business to be shown to the payer during the payment interaction. (e.g. an email address for customer service).', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px;' + ), + 'merchant_phone' => array( + 'title' => __( 'Phone', 'mastercard' ), + 'type' => 'tel', + 'description' => __( 'The phone number of your business (up to 20 characters) to be shown to the payer during the payment interaction.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px; width: 400px;' + ), + 'merchant_logo' => array( + 'title' => __( 'Logo', 'mastercard' ), + 'type' => 'text', + 'description' => __( 'The URL of your business logo (JPEG, PNG, or SVG) to be shown to the payer during the payment interaction.
The logo should be 140x140 pixels, and the URL must be secure (e.g., https://). Size exceeding 140 pixels will be auto resized.', 'mastercard' ), + 'default' => '', + 'css' => 'min-height: 33px; width: 400px;' + ), +); diff --git a/mpgs_payments.log b/mpgs_payments.log new file mode 100755 index 0000000..066f596 --- /dev/null +++ b/mpgs_payments.log @@ -0,0 +1,4 @@ +2024-11-20 05:16:54 :: Callback response:- +2024-11-20 05:17:06 :: Callback response:- + +2024-11-20 05:20:58 :: Callback response:- diff --git a/templates/3dsecure/form.php b/templates/3dsecure/form.php index 0620c8d..f89839d 100755 --- a/templates/3dsecure/form.php +++ b/templates/3dsecure/form.php @@ -15,7 +15,7 @@ * limitations under the License. * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ @@ -29,7 +29,7 @@ */ ?> - +> <?php esc_html_e( 'Processing Secure Payment', 'mastercard' ); ?> diff --git a/templates/checkout/hosted-checkout.php b/templates/checkout/hosted-checkout.php index 86fe110..395a1e8 100755 --- a/templates/checkout/hosted-checkout.php +++ b/templates/checkout/hosted-checkout.php @@ -15,7 +15,7 @@ * limitations under the License. * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ @@ -29,9 +29,9 @@ if ( $gateway->use_embedded() ) { ?>
- + \ No newline at end of file diff --git a/templates/checkout/hosted-session.php b/templates/checkout/hosted-session.php index ee26361..eab885e 100755 --- a/templates/checkout/hosted-session.php +++ b/templates/checkout/hosted-session.php @@ -15,7 +15,7 @@ * limitations under the License. * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ @@ -219,14 +219,14 @@ function placeOrder( response ) { $.when( savePayment( getPaymentData() )).done(function ( response ) { - if ( is3DsV2Enabled() ) { - initiateAuthentication(); - } else { - document.querySelector( 'form.mpgs_hostedsession > input[name=session_id]' ).value = response.session.id; - document.querySelector( 'form.mpgs_hostedsession > input[name=session_version]' ).value = response.session.version; - document.querySelector( 'form.mpgs_hostedsession' ).submit(); - } - }).fail( console.error ); + if ( is3DsV2Enabled() ) { + initiateAuthentication(); + } else { + document.querySelector( 'form.mpgs_hostedsession > input[name=session_id]' ).value = response.session.id; + document.querySelector( 'form.mpgs_hostedsession > input[name=session_version]' ).value = response.session.version; + document.querySelector( 'form.mpgs_hostedsession' ).submit(); + } + }).fail( console.error ); } function initializeTokenPaymentSession( session_id, id ) { @@ -257,6 +257,7 @@ function initializeTokenPaymentSession( session_id, id ) { if ( is3DsV1Enabled() ) { document.querySelector( 'form.mpgs_hostedsession > input[name=check_3ds_enrollment]' ).value = '1'; } + console.log(response); placeOrder( response ); } else { errorsContainer.innerText = hsLoadingFailedMsg + ' (unexpected status: ' + response.status + ')'; diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 4299153..b83cbe1 100755 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -58,8 +58,8 @@ 'php-http/async-client-implementation' => array( 'dev_requirement' => false, 'provided' => array( - 0 => '1.0', - 1 => '*', + 0 => '*', + 1 => '1.0', ), ), 'php-http/client-common' => array( @@ -74,8 +74,8 @@ 'php-http/client-implementation' => array( 'dev_requirement' => false, 'provided' => array( - 0 => '1.0', - 1 => '*', + 0 => '*', + 1 => '1.0', ), ), 'php-http/curl-client' => array( @@ -150,8 +150,8 @@ 'psr/http-client-implementation' => array( 'dev_requirement' => false, 'provided' => array( - 0 => '1.0', - 1 => '*', + 0 => '*', + 1 => '1.0', ), ), 'psr/http-factory' => array( diff --git a/woocommerce-mastercard.php b/woocommerce-mastercard.php index 52fe0d7..5d07835 100755 --- a/woocommerce-mastercard.php +++ b/woocommerce-mastercard.php @@ -5,18 +5,19 @@ * Plugin URI: /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ * Author: Fingent Global Solutions Pvt. Ltd. * Author URI: https://www.fingent.com/ - * Tags: payment, payment-gateway, mastercard, mastercard-payements, mastercard-gateway, woocommerce-plugin, woocommerce-payment, woocommerce-extension, woocommerce-shop, mastercard, woocommerce-api - * Version: 1.4.6 - * Requires at least: 5.6.0 + * Tags: payment, payment-gateway, mastercard, mastercard-payements, mastercard-gateway, woocommerce-plugin, woocommerce-payment, woocommerce-extension, woocommerce-shop, mastercard, woocommerce-api, woocommerce-blocks + * Version: 1.4.7 + * Requires Plugins: woocommerce + * Requires at least: 6.0 * Tested up to: 6.6.1 - * Requires PHP: 7.4 + * Requires PHP: 8.1 * php version 8.1 * - * WC requires at least: 7.6 - * WC tested up to: 9.1.4 + * WC requires at least: 8.5 + * WC tested up to: 9.3.3 * * @package Mastercard - * @version GIT: @1.4.6@ + * @version GIT: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ @@ -47,7 +48,7 @@ * Main class of the Mastercard Payment Gateway Services Module * * @package Mastercard - * @version Release: @1.4.6@ + * @version Release: @1.4.7@ * @link /~https://github.com/fingent-corp/gateway-woocommerce-mastercard-module/ */ class WC_Mastercard { @@ -62,7 +63,7 @@ class WC_Mastercard { /** * WC_Mastercard constructor. */ - public function __construct() { + public function __construct() { add_action( 'plugins_loaded', array( $this, 'init' ) ); add_action( 'init', array( $this, 'clean_output_buffer' ) ); add_action( 'before_woocommerce_init', array( $this, 'declare_cart_checkout_blocks_compatibility' ) ); @@ -105,7 +106,6 @@ public function init() { add_filter( 'woocommerce_order_actions', function ( $actions ) { - $hpos_enabled = get_option( 'woocommerce_custom_orders_table_enabled' ); $order_id = self::get_order_id(); if ( $order_id ) { $order = new WC_Order( $order_id ); @@ -118,7 +118,6 @@ function ( $actions ) { 'Capture Authorized Amount', 'mastercard' ); - $actions[ 'mpgs_void_payment' ] = __( 'Void', 'mastercard' @@ -182,7 +181,7 @@ function () { ), ), ) - ); + ); register_rest_route( 'mastercard/v1', '/webhook', @@ -194,7 +193,10 @@ function () { ); } ); + add_action( 'admin_head', array( $this, 'mpgs_admin_styles' ) ); add_filter( 'woocommerce_admin_order_should_render_refunds', array( $this, 'admin_order_should_render_refunds' ), 10, 3 ); + add_filter( 'manage_woocommerce_page_wc-orders_columns', array( $this, 'transaction_mode_columns' ) ); + add_action( 'manage_woocommerce_page_wc-orders_custom_column', array( $this, 'transaction_mode_column_data' ), 10, 2 ); } /** @@ -235,7 +237,7 @@ public function stop() { /** * Apply Custom CSS to Admin Area. * - * @since 1.4.4 + * @since 1.4.5 * * @return void */ @@ -415,6 +417,52 @@ public static function is_hpos() { return OrderUtil::custom_orders_table_usage_is_enabled() ? 'yes' : 'no'; } + /** + * Enqueue custom styles for the admin dashboard related to the Mastercard Payment Gateway Services (MPGS). + * + * This function is used to add custom CSS styles to the WordPress admin area, specifically for pages + * that handle Mastercard Payment Gateway Services (MPGS) settings or features. It ensures that the + * admin UI for these pages is styled according to the requirements of the plugin. + * + * @since 1.4.5 + */ + public function mpgs_admin_styles() { + echo ''; + } /** * Is_order_pay_page - Returns true when viewing the order received page. * @@ -427,7 +475,7 @@ public function is_order_pay_page() { /** * Function to declare compatibility with cart_checkout_blocks feature. * - * @since 1.4.4 + * @since 1.4.5 * @return void */ public function declare_cart_checkout_blocks_compatibility() { // phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed @@ -440,7 +488,7 @@ public function declare_cart_checkout_blocks_compatibility() { // phpcs:ignore U /** * Function to register the Mastercard payment method type. * - * @since 1.4.4 + * @since 1.4.5 * @return void */ public function woocommerce_gateway_mastercard_woocommerce_block_support() { @@ -456,6 +504,55 @@ function ( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment } ); } + + /** + * Adds transaction mode column to the existing columns in the list table. + * + * This function modifies the list of columns by adding or altering + * columns, typically for displaying additional information like + * transaction modes or other custom data. + * + * @param array $columns Existing columns in the list table. + * @return array Modified array of columns including the transaction mode column. + */ + public function transaction_mode_columns( $columns ) { + $columns['mgps_transaction'] = 'Transaction Mode'; + return $columns; + } + + /** + * Callback function to display data in the custom 'transaction_mode' column in the WooCommerce Orders List Table. + * + * @param string $column The name of the column currently being processed. + * @param WC_Order $order The order object for the current row being displayed. + */ + public function transaction_mode_column_data( $column, $order ) { + if ( 'mgps_transaction' === $column ) { + switch ( $order->get_meta( '_mpgs_transaction_mode' ) ) { + case 'capture': + $transaction_mode = 'Purchase'; + break; + + case 'authorize': + $transaction_mode = 'Authorize'; + break; + + case 'captured': + $transaction_mode = 'Captured'; + break; + + case 'void': + $transaction_mode = 'Void'; + break; + + default: + $transaction_mode = 'N/A'; + break; + } + + echo $transaction_mode; + } + } } WC_Mastercard::get_instance(); From 07f1d42d0eb8948ae571fe35055454e9a6c76612 Mon Sep 17 00:00:00 2001 From: jineshpv Date: Tue, 26 Nov 2024 16:23:34 +0530 Subject: [PATCH 2/2] Features:- Introduced a new Merchant Information section in the plugin settings for admins to easily update merchant information, Eliminated the intermediate page in the 'Redirect to Payment Page' process for Hosted Checkout, Compatibility with WooCommerce 9.3, Updated the API version to 84 & Resolved an issue where line items were not correctly transmitted to the payment gateway --- mpgs_payments.log | 4 ---- 1 file changed, 4 deletions(-) delete mode 100755 mpgs_payments.log diff --git a/mpgs_payments.log b/mpgs_payments.log deleted file mode 100755 index 066f596..0000000 --- a/mpgs_payments.log +++ /dev/null @@ -1,4 +0,0 @@ -2024-11-20 05:16:54 :: Callback response:- -2024-11-20 05:17:06 :: Callback response:- - -2024-11-20 05:20:58 :: Callback response:-