From c641eaf854a87acaced669628b91ffe0689583bb Mon Sep 17 00:00:00 2001 From: malmo-monei Date: Tue, 26 Nov 2024 18:10:48 +0100 Subject: [PATCH] Release 6.1.0 * Add - Multibanco payment method * Add - MBWay payment method * Fix - Add default css class for checkout inputs * Fix - Add credit card icons with more cards --- assets/css/monei-icons-classic.css | 15 ++- assets/images/mbway-logo.svg | 1 + assets/images/monei-cards.svg | 16 +-- assets/images/multibanco-logo.svg | 45 +++++++ assets/js/monei-block-checkout-bizum.js | 1 - assets/js/monei-block-checkout-cc.js | 6 +- assets/js/monei-block-checkout-mbway.js | 33 +++++ assets/js/monei-block-checkout-multibanco.js | 33 +++++ build/package.json | 2 +- class-woocommerce-gateway-monei.php | 27 ++--- includes/MoneiMBWayBlocksSupport.php | 79 ++++++++++++ includes/MoneiMultibancoBlocksSupport.php | 79 ++++++++++++ .../abstract-wc-monei-payment-gateway.php | 2 +- includes/admin/monei-mbway-settings.php | 62 ++++++++++ includes/admin/monei-multibanco-settings.php | 62 ++++++++++ includes/payment-methods/MoneiMBWay.php | 113 ++++++++++++++++++ includes/payment-methods/MoneiMultibanco.php | 113 ++++++++++++++++++ .../class-wc-gateway-monei-cc.php | 8 +- readme.txt | 8 +- woocommerce-gateway-monei.php | 2 +- 20 files changed, 665 insertions(+), 42 deletions(-) create mode 100644 assets/images/mbway-logo.svg create mode 100644 assets/images/multibanco-logo.svg create mode 100644 assets/js/monei-block-checkout-mbway.js create mode 100644 assets/js/monei-block-checkout-multibanco.js create mode 100644 includes/MoneiMBWayBlocksSupport.php create mode 100644 includes/MoneiMultibancoBlocksSupport.php create mode 100644 includes/admin/monei-mbway-settings.php create mode 100644 includes/admin/monei-multibanco-settings.php create mode 100644 includes/payment-methods/MoneiMBWay.php create mode 100644 includes/payment-methods/MoneiMultibanco.php diff --git a/assets/css/monei-icons-classic.css b/assets/css/monei-icons-classic.css index 190fb35..0934c17 100644 --- a/assets/css/monei-icons-classic.css +++ b/assets/css/monei-icons-classic.css @@ -1,7 +1,20 @@ [class*="payment_method_monei"] label { } - +label .monei-icons-cc{ + margin-left: 15px; + margin-right:0; + padding-right:0; + max-height: 28px !important; + max-width: 258px !important; +} +label .monei-icons-multi{ + margin-left: 15px; + margin-right:0; + padding-right:0; + max-height: 28px !important; + max-width: 128px !important; +} label .monei-icons{ margin-left: 15px; margin-right:0; diff --git a/assets/images/mbway-logo.svg b/assets/images/mbway-logo.svg new file mode 100644 index 0000000..82b9b46 --- /dev/null +++ b/assets/images/mbway-logo.svg @@ -0,0 +1 @@ + diff --git a/assets/images/monei-cards.svg b/assets/images/monei-cards.svg index 71bf275..a0a01e7 100644 --- a/assets/images/monei-cards.svg +++ b/assets/images/monei-cards.svg @@ -1,15 +1 @@ - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/assets/images/multibanco-logo.svg b/assets/images/multibanco-logo.svg new file mode 100644 index 0000000..5c14cca --- /dev/null +++ b/assets/images/multibanco-logo.svg @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/js/monei-block-checkout-bizum.js b/assets/js/monei-block-checkout-bizum.js index 6de8555..4af73d3 100644 --- a/assets/js/monei-block-checkout-bizum.js +++ b/assets/js/monei-block-checkout-bizum.js @@ -194,6 +194,5 @@ }, supports: bizumData.supports, }; - console.log('hola bizum 6') registerPaymentMethod( MoneiBizumPaymentMethod ); } )(); diff --git a/assets/js/monei-block-checkout-cc.js b/assets/js/monei-block-checkout-cc.js index 03b2d7b..5dfa4d2 100644 --- a/assets/js/monei-block-checkout-cc.js +++ b/assets/js/monei-block-checkout-cc.js @@ -316,7 +316,7 @@ }, [ onCheckoutSuccess, shouldSavePayment ] ); return ( -
+
{ moneiData?.description &&

{ moneiData.description }

}
-
+
{ + return ( +
+ + { __( mbwayData.title, 'monei' ) } + + { mbwayData?.logo && ( +
+ +
+ ) } +
+ ); + }; + + const MoneiMbwayPaymentMethod = { + name: 'monei_mbway', + label:
{mbwayLabel()}
, + ariaLabel: __(mbwayData.title, 'monei'), + content:
{__(mbwayData.description, 'monei')}
, + edit:
{__(mbwayData.title, 'monei')}
, + canMakePayment: ({billingData}) => { + return billingData.country === 'PT'; + }, + supports: mbwayData.supports, + }; + registerPaymentMethod(MoneiMbwayPaymentMethod ); +} )(); diff --git a/assets/js/monei-block-checkout-multibanco.js b/assets/js/monei-block-checkout-multibanco.js new file mode 100644 index 0000000..a1e4816 --- /dev/null +++ b/assets/js/monei-block-checkout-multibanco.js @@ -0,0 +1,33 @@ +( function () { + const { registerPaymentMethod } = wc.wcBlocksRegistry; + const { __ } = wp.i18n; + const multibancoData = wc.wcSettings.getSetting( 'monei_multibanco_data' ); + + const multibancoLabel = () => { + return ( +
+ + { __( multibancoData.title, 'monei' ) } + + { multibancoData?.logo && ( +
+ +
+ ) } +
+ ); + }; + + const MoneiMultibancoPaymentMethod = { + name: 'monei_multibanco', + label:
{multibancoLabel()}
, + ariaLabel: __(multibancoData.title, 'monei'), + content:
{__(multibancoData.description, 'monei')}
, + edit:
{__(multibancoData.title, 'monei')}
, + canMakePayment: ({billingData}) => { + return billingData.country === 'PT'; + }, + supports: multibancoData.supports, + }; + registerPaymentMethod(MoneiMultibancoPaymentMethod ); +} )(); diff --git a/build/package.json b/build/package.json index 16540f0..e938d15 100644 --- a/build/package.json +++ b/build/package.json @@ -1,6 +1,6 @@ { "name": "monei-woocommerce", - "version": "6.0.0", + "version": "6.1.0", "main": "index.js", "repository": "git@github.com:MONEI/MONEI-WooCommerce.git", "author": "MONEI ", diff --git a/class-woocommerce-gateway-monei.php b/class-woocommerce-gateway-monei.php index 0e5492f..f48c130 100644 --- a/class-woocommerce-gateway-monei.php +++ b/class-woocommerce-gateway-monei.php @@ -5,7 +5,7 @@ * @author MONEI * @category Core * @package Woocommerce_Gateway_Monei - * @version 6.0.0 + * @version 6.1.0 */ if ( ! class_exists( 'Woocommerce_Gateway_Monei' ) ) : @@ -16,7 +16,7 @@ final class Woocommerce_Gateway_Monei { * * @var string */ - public $version = '6.0.0'; + public $version = '6.1.0'; /** * The single instance of the class. @@ -77,12 +77,16 @@ public function block_compatiblity() { require_once 'includes/class-monei-cc-blocks.php'; require_once 'includes/MoneiBizumBlocksSupport.php'; require_once 'includes/AppleGoogleBlocksSupport.php'; + require_once 'includes/MoneiMultibancoBlocksSupport.php'; + require_once 'includes/MoneiMBWayBlocksSupport.php'; add_action( 'woocommerce_blocks_payment_method_type_registration', function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { $payment_method_registry->register( new WC_Gateway_Monei_CC_Blocks ); $payment_method_registry->register( new MoneiBizumBlocksSupport ); $payment_method_registry->register( new AppleGoogleBlocksSupport ); + $payment_method_registry->register( new MoneiMultibancoBlocksSupport ); + $payment_method_registry->register( new MoneiMBWayBlocksSupport ); } ); } ); @@ -239,6 +243,8 @@ public function init() { add_filter( 'option_woocommerce_monei_bizum_settings', array( $this, 'monei_settings_by_default' ), 1 ); add_filter( 'option_woocommerce_monei_paypal_settings', array( $this, 'monei_settings_by_default' ), 1 ); + add_filter( 'option_woocommerce_monei_multibanco_settings', array( $this, 'monei_settings_by_default' ), 1 ); + add_filter( 'option_woocommerce_monei_mbway_settings', array( $this, 'monei_settings_by_default' ), 1 ); add_filter( 'option_woocommerce_monei_settings', array( $this, 'copyKeysToCentralSettings' ), 1 ); // Init action. @@ -322,7 +328,6 @@ private function get_setting_with_default( $key, $params ) { public function plugins_loaded() { $this->include_payment_methods(); add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); - add_action( 'woocommerce_after_checkout_validation', array( $this, 'validate_checkout' ), 2, 10 ); } /** @@ -340,7 +345,9 @@ private function include_payment_methods() { include_once 'includes/payment-methods/class-wc-gateway-monei-hosted-cofidis.php'; include_once 'includes/payment-methods/class-wc-gateway-monei-hosted-bizum.php'; include_once 'includes/payment-methods/class-wc-gateway-monei-hosted-paypal.php'; - } + include_once 'includes/payment-methods/MoneiMultibanco.php'; + include_once 'includes/payment-methods/MoneiMBWay.php'; + } /** * Add Monei Gateways. @@ -357,6 +364,8 @@ public function add_gateways( $methods ) { $methods[] = 'WC_Gateway_Monei_Cofidis'; $methods[] = 'WC_Gateway_Monei_Bizum'; $methods[] = 'WC_Gateway_Monei_Paypal'; + $methods[] = 'MoneiMultibanco'; + $methods[] = 'MoneiMBWay'; return $methods; } @@ -424,16 +433,6 @@ public function image_url( $image = '' ) { public function ajax_url() { return admin_url( 'admin-ajax.php', 'relative' ); } - - public function validate_checkout( $data, $errors ) { - //validate that the name and last name follow a pattern - if ( ! preg_match( '/^[A-Za-zÀ-ÖØ-öø-ÿ ]{2,50}$/', $data['billing_first_name'] ) ) { - $errors->add( 'validation', __( 'Please enter a valid name. Special characters are not allowed.', 'monei' ) ); - } - if ( ! preg_match( '/^[A-Za-zÀ-ÖØ-öø-ÿ ]{2,50}$/', $data['billing_last_name'] ) ) { - $errors->add( 'validation', __( 'Please enter a valid last name. Special characters are not allowed.', 'monei' ) ); - } - } } endif; diff --git a/includes/MoneiMBWayBlocksSupport.php b/includes/MoneiMBWayBlocksSupport.php new file mode 100644 index 0000000..49674da --- /dev/null +++ b/includes/MoneiMBWayBlocksSupport.php @@ -0,0 +1,79 @@ +settings = get_option( 'woocommerce_monei_mbway_settings', array() ); + $this->gateway = new MoneiMBWay(); + } + public function get_payment_method_script_handles() { + + $script_name = 'wc-monei-mbway-blocks-integration'; + + wp_register_script( + $script_name, + WC_Monei()->plugin_url(). '/public/js/monei-block-checkout-mbway.min.js', + array( + 'wc-blocks-checkout', + 'wc-blocks-registry', + 'wc-settings', + 'wp-element', + 'wp-html-entities', + 'wp-i18n' + ), + WC_Monei()->version, + true + ); + + if ( function_exists( 'wp_set_script_translations' ) ) { + wp_set_script_translations( $script_name ); + } + + return array( $script_name ); + } + + public function is_active() { + + $id = $this->gateway->getAccountId() ?? false;; + $key = $this->gateway->getApiKey() ?? false; + + if ( ! $id || ! $key ) { + return false; + } + + return 'yes' === ( $this->get_setting( 'enabled' ) ?? 'no' ); + } + + public function get_payment_method_data() { + $total = isset(WC()->cart) ? WC()->cart->get_total( false ) : 0; + $data = array( + + 'title' => $this->gateway->title, + 'description' => $this->gateway->description, + 'logo' => WC_Monei()->plugin_url() . '/assets/images/mbway-logo.svg', + 'supports' => $this->get_supported_features(), + 'currency' => get_woocommerce_currency(), + 'total' => $total, + 'language' => locale_iso_639_1_code(), + + // yes: test mode. + // no: live, + 'test_mode'=> $this->gateway->getTestmode() ?? false, + 'accountId' => $this->gateway->getAccountId() ?? false, + 'sessionId' => (wc()->session) ? wc()->session->get_customer_id() : '', + ); + + if ( 'yes' === $this->get_setting( 'hide_logo' ) ?? 'no' ) { + + unset( $data['logo'] ); + + } + + return $data; + } + } diff --git a/includes/MoneiMultibancoBlocksSupport.php b/includes/MoneiMultibancoBlocksSupport.php new file mode 100644 index 0000000..fc80ba6 --- /dev/null +++ b/includes/MoneiMultibancoBlocksSupport.php @@ -0,0 +1,79 @@ +settings = get_option( 'woocommerce_monei_multibanco_settings', array() ); + $this->gateway = new MoneiMultibanco(); + } + public function get_payment_method_script_handles() { + + $script_name = 'wc-monei-multibanco-blocks-integration'; + + wp_register_script( + $script_name, + WC_Monei()->plugin_url(). '/public/js/monei-block-checkout-multibanco.min.js', + array( + 'wc-blocks-checkout', + 'wc-blocks-registry', + 'wc-settings', + 'wp-element', + 'wp-html-entities', + 'wp-i18n' + ), + WC_Monei()->version, + true + ); + + if ( function_exists( 'wp_set_script_translations' ) ) { + wp_set_script_translations( $script_name ); + } + + return array( $script_name ); + } + + public function is_active() { + + $id = $this->gateway->getAccountId() ?? false;; + $key = $this->gateway->getApiKey() ?? false; + + if ( ! $id || ! $key ) { + return false; + } + + return 'yes' === ( $this->get_setting( 'enabled' ) ?? 'no' ); + } + + public function get_payment_method_data() { + $total = isset(WC()->cart) ? WC()->cart->get_total( false ) : 0; + $data = array( + + 'title' => $this->gateway->title, + 'description' => $this->gateway->description, + 'logo' => WC_Monei()->plugin_url() . '/assets/images/multibanco-logo.svg', + 'supports' => $this->get_supported_features(), + 'currency' => get_woocommerce_currency(), + 'total' => $total, + 'language' => locale_iso_639_1_code(), + + // yes: test mode. + // no: live, + 'test_mode'=> $this->gateway->getTestmode() ?? false, + 'accountId' => $this->gateway->getAccountId() ?? false, + 'sessionId' => (wc()->session) ? wc()->session->get_customer_id() : '', + ); + + if ( 'yes' === $this->get_setting( 'hide_logo' ) ?? 'no' ) { + + unset( $data['logo'] ); + + } + + return $data; + } + } diff --git a/includes/abstracts/abstract-wc-monei-payment-gateway.php b/includes/abstracts/abstract-wc-monei-payment-gateway.php index 9f01d3f..c71d69f 100644 --- a/includes/abstracts/abstract-wc-monei-payment-gateway.php +++ b/includes/abstracts/abstract-wc-monei-payment-gateway.php @@ -105,7 +105,7 @@ abstract class WC_Monei_Payment_Gateway extends WC_Payment_Gateway { /** * Check if this gateway is enabled and available in the user's country - * todo: define this better. + * todo: check if the gateway is enabled in the user account * * @access public * @return bool diff --git a/includes/admin/monei-mbway-settings.php b/includes/admin/monei-mbway-settings.php new file mode 100644 index 0000000..b01fb53 --- /dev/null +++ b/includes/admin/monei-mbway-settings.php @@ -0,0 +1,62 @@ + 'wc-settings', + 'tab' => 'monei_settings', +), 'admin.php' ) ) ); + +/** + * Monei mbway Gateway Settings. + */ +return apply_filters( + 'wc_monei_mbway_settings', + array( + 'top_link' => array( + 'title' => '', + 'type' => 'title', + 'description' => '' . __( 'Go to MONEI Api key Settings', 'monei' ) . '', + 'id' => 'mbway_monei_top_link', + ), + 'enabled' => array( + 'title' => __( 'Enable/Disable', 'monei' ), + 'type' => 'checkbox', + 'label' => __( 'Enable MBWay by MONEI', 'monei' ), + 'default' => 'no', + ), + 'title' => array( + 'title' => __( 'Title', 'monei' ), + 'type' => 'text', + 'description' => __( 'The payment method title a user sees during checkout.', 'monei' ), + 'default' => __( 'MBWay', 'monei' ), + 'desc_tip' => true, + ), + 'description' => array( + 'title' => __( 'Description', 'monei' ), + 'type' => 'textarea', + 'description' => __( 'The payment method description a user sees during checkout.', 'monei' ), + 'default' => __( 'Pay with MBWay, you will be redirected to MBWay. Powered by MONEI', 'monei' ), + ), + 'hide_logo' => array( + 'title' => __( 'Hide Logo', 'monei' ), + 'type' => 'checkbox', + 'label' => __( 'Hide payment method logo', 'monei' ), + 'default' => 'no', + 'description' => __( 'Hide payment method logo in the checkout.', 'monei' ), + 'desc_tip' => true, + ), + 'orderdo' => array( + 'title' => __( 'What to do after payment?', 'monei' ), + 'type' => 'select', + 'description' => __( 'Chose what to do after the customer pay the order.', 'monei' ), + 'default' => 'processing', + 'options' => array( + 'processing' => __( 'Mark as Processing (default & recommended)', 'monei' ), + 'completed' => __( 'Mark as Complete', 'monei' ), + ), + ), + ) +); + diff --git a/includes/admin/monei-multibanco-settings.php b/includes/admin/monei-multibanco-settings.php new file mode 100644 index 0000000..096faa2 --- /dev/null +++ b/includes/admin/monei-multibanco-settings.php @@ -0,0 +1,62 @@ + 'wc-settings', + 'tab' => 'monei_settings', +), 'admin.php' ) ) ); + +/** + * Monei Multibanco Gateway Settings. + */ +return apply_filters( + 'wc_monei_multibanco_settings', + array( + 'top_link' => array( + 'title' => '', + 'type' => 'title', + 'description' => '' . __( 'Go to MONEI Api key Settings', 'monei' ) . '', + 'id' => 'multibanco_monei_top_link', + ), + 'enabled' => array( + 'title' => __( 'Enable/Disable', 'monei' ), + 'type' => 'checkbox', + 'label' => __( 'Enable Multibanco by MONEI', 'monei' ), + 'default' => 'no', + ), + 'title' => array( + 'title' => __( 'Title', 'monei' ), + 'type' => 'text', + 'description' => __( 'The payment method title a user sees during checkout.', 'monei' ), + 'default' => __( 'Multibanco', 'monei' ), + 'desc_tip' => true, + ), + 'description' => array( + 'title' => __( 'Description', 'monei' ), + 'type' => 'textarea', + 'description' => __( 'The payment method description a user sees during checkout.', 'monei' ), + 'default' => __( 'Pay with Multibanco, you will be redirected to Multibanco. Powered by MONEI', 'monei' ), + ), + 'hide_logo' => array( + 'title' => __( 'Hide Logo', 'monei' ), + 'type' => 'checkbox', + 'label' => __( 'Hide payment method logo', 'monei' ), + 'default' => 'no', + 'description' => __( 'Hide payment method logo in the checkout.', 'monei' ), + 'desc_tip' => true, + ), + 'orderdo' => array( + 'title' => __( 'What to do after payment?', 'monei' ), + 'type' => 'select', + 'description' => __( 'Chose what to do after the customer pay the order.', 'monei' ), + 'default' => 'processing', + 'options' => array( + 'processing' => __( 'Mark as Processing (default & recommended)', 'monei' ), + 'completed' => __( 'Mark as Complete', 'monei' ), + ), + ), + ) +); + diff --git a/includes/payment-methods/MoneiMBWay.php b/includes/payment-methods/MoneiMBWay.php new file mode 100644 index 0000000..a85f9af --- /dev/null +++ b/includes/payment-methods/MoneiMBWay.php @@ -0,0 +1,113 @@ +id = MONEI_GATEWAY_ID . '_mbway'; + $this->method_title = __( 'MONEI - MBWay', 'monei' ); + $this->method_description = __( 'Accept MBWay payments.', 'monei' ); + $this->enabled = ( ! empty( $this->get_option( 'enabled' ) && 'yes' === $this->get_option( 'enabled' ) ) && $this->is_valid_for_use() ) ? 'yes' : false; + + // Load the form fields. + $this->init_form_fields(); + // Load the settings. + $this->init_settings(); + + // Bizum Hosted payment with redirect. + $this->has_fields = false; + $iconUrl = apply_filters( 'woocommerce_monei_mbway_icon', WC_Monei()->image_url( 'mbway-logo.svg' )); + $iconMarkup = 'MONEI'; + // Settings variable + $this->hide_logo = ( ! empty( $this->get_option( 'hide_logo' ) && 'yes' === $this->get_option( 'hide_logo' ) ) ) ? true : false; + $this->icon = ( $this->hide_logo ) ? '' : $iconMarkup; + $this->title = ( ! empty( $this->get_option( 'title' ) ) ) ? $this->get_option( 'title' ) : ''; + $this->description = ( ! empty( $this->get_option( 'description' ) ) ) ? $this->get_option( 'description' ) : ' '; + $this->status_after_payment = ( ! empty( $this->get_option( 'orderdo' ) ) ) ? $this->get_option( 'orderdo' ) : ''; + $this->api_key = $this->getApiKey(); + $this->account_id = $this->getAccountId(); + $this->shop_name = get_bloginfo( 'name' ); + $this->logging = ( ! empty( get_option( 'monei_debug' ) ) && 'yes' === get_option( 'monei_debug' ) ) ? true : false; + + // IPN callbacks + $this->notify_url = WC_Monei()->get_ipn_url(); + new WC_Monei_IPN($this->logging); + + $this->supports = array( + 'products', + 'refunds', + ); + + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); + add_filter( + 'woocommerce_save_settings_checkout_' . $this->id, + function ($is_post) { + return $this->checks_before_save($is_post, 'woocommerce_monei_mbway_enabled'); + } + ); + } + /** + * Return whether or not this gateway still requires setup to function. + * + * When this gateway is toggled on via AJAX, if this returns true a + * redirect will occur to the settings page instead. + * + * @since 3.4.0 + * @return bool + */ + public function needs_setup() { + + if ( ! $this->account_id || ! $this->api_key ) { + return true; + } + + return false; + } + /** + * Initialise Gateway Settings Form Fields + * + * @access public + * @since 5.0 + * @return void + */ + public function init_form_fields() { + $this->form_fields = require WC_Monei()->plugin_path() . '/includes/admin/monei-mbway-settings.php'; + } + + /** + * Process the payment and return the result + * + * @access public + * @param int $order_id + * @param null|string $allowed_payment_method + * @return array + */ + public function process_payment( $order_id, $allowed_payment_method = null ) { + return parent::process_payment( $order_id, self::PAYMENT_METHOD ); + } + + public function is_available(){ + $customerCountry = WC()->customer && !empty(WC()->customer->get_billing_country()); + $billingCountry = $customerCountry ? WC()->customer->get_billing_country() : wc_get_base_location()['country']; + if ($this->enabled === 'yes' && $billingCountry === 'PT') { + return true; + } + } +} + diff --git a/includes/payment-methods/MoneiMultibanco.php b/includes/payment-methods/MoneiMultibanco.php new file mode 100644 index 0000000..f1e4121 --- /dev/null +++ b/includes/payment-methods/MoneiMultibanco.php @@ -0,0 +1,113 @@ +id = MONEI_GATEWAY_ID . '_multibanco'; + $this->method_title = __( 'MONEI - Multibanco', 'monei' ); + $this->method_description = __( 'Accept Multibanco payments.', 'monei' ); + $this->enabled = ( ! empty( $this->get_option( 'enabled' ) && 'yes' === $this->get_option( 'enabled' ) ) && $this->is_valid_for_use() ) ? 'yes' : false; + + // Load the form fields. + $this->init_form_fields(); + // Load the settings. + $this->init_settings(); + + // Bizum Hosted payment with redirect. + $this->has_fields = false; + $iconUrl = apply_filters( 'woocommerce_monei_multibanco_icon', WC_Monei()->image_url( 'multibanco-logo.svg' )); + $iconMarkup = 'MONEI'; + // Settings variable + $this->hide_logo = ( ! empty( $this->get_option( 'hide_logo' ) && 'yes' === $this->get_option( 'hide_logo' ) ) ) ? true : false; + $this->icon = ( $this->hide_logo ) ? '' : $iconMarkup; + $this->title = ( ! empty( $this->get_option( 'title' ) ) ) ? $this->get_option( 'title' ) : ''; + $this->description = ( ! empty( $this->get_option( 'description' ) ) ) ? $this->get_option( 'description' ) : ' '; + $this->status_after_payment = ( ! empty( $this->get_option( 'orderdo' ) ) ) ? $this->get_option( 'orderdo' ) : ''; + $this->api_key = $this->getApiKey(); + $this->account_id = $this->getAccountId(); + $this->shop_name = get_bloginfo( 'name' ); + $this->logging = ( ! empty( get_option( 'monei_debug' ) ) && 'yes' === get_option( 'monei_debug' ) ) ? true : false; + + // IPN callbacks + $this->notify_url = WC_Monei()->get_ipn_url(); + new WC_Monei_IPN($this->logging); + + $this->supports = array( + 'products', + 'refunds', + ); + + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); + add_filter( + 'woocommerce_save_settings_checkout_' . $this->id, + function ($is_post) { + return $this->checks_before_save($is_post, 'woocommerce_monei_multibanco_enabled'); + } + ); + } + /** + * Return whether or not this gateway still requires setup to function. + * + * When this gateway is toggled on via AJAX, if this returns true a + * redirect will occur to the settings page instead. + * + * @since 3.4.0 + * @return bool + */ + public function needs_setup() { + + if ( ! $this->account_id || ! $this->api_key ) { + return true; + } + + return false; + } + /** + * Initialise Gateway Settings Form Fields + * + * @access public + * @since 5.0 + * @return void + */ + public function init_form_fields() { + $this->form_fields = require WC_Monei()->plugin_path() . '/includes/admin/monei-multibanco-settings.php'; + } + + /** + * Process the payment and return the result + * + * @access public + * @param int $order_id + * @param null|string $allowed_payment_method + * @return array + */ + public function process_payment( $order_id, $allowed_payment_method = null ) { + return parent::process_payment( $order_id, self::PAYMENT_METHOD ); + } + + public function is_available(){ + $customerCountry = WC()->customer && !empty(WC()->customer->get_billing_country()); + $billingCountry = $customerCountry ? WC()->customer->get_billing_country() : wc_get_base_location()['country']; + if ($this->enabled === 'yes' && $billingCountry === 'PT') { + return true; + } + } +} + diff --git a/includes/payment-methods/class-wc-gateway-monei-cc.php b/includes/payment-methods/class-wc-gateway-monei-cc.php index 4990fd3..1f3d289 100644 --- a/includes/payment-methods/class-wc-gateway-monei-cc.php +++ b/includes/payment-methods/class-wc-gateway-monei-cc.php @@ -62,7 +62,7 @@ public function __construct() { // Hosted payment with redirect. $this->has_fields = false; $iconUrl = apply_filters( 'woocommerce_monei_icon', WC_Monei()->image_url( 'monei-cards.svg' )); - $iconMarkup = 'MONEI'; + $iconMarkup = 'MONEI'; // Settings variable $this->hide_logo = ( ! empty( $this->get_option( 'hide_logo' ) && 'yes' === $this->get_option( 'hide_logo' ) ) ) ? true : false; $this->icon = ( $this->hide_logo ) ? '' : $iconMarkup; @@ -285,7 +285,7 @@ function payment_fields() { */ protected function render_monei_form() { ?> -
+
+ class="monei-input wc-block-components-text-input">
-
+