Plugin Directory

Changeset 3025695


Ignore:
Timestamp:
01/23/2024 12:11:06 PM (2 years ago)
Author:
eupagoip
Message:

v4.1.0

Location:
eupago-gateway-for-woocommerce/trunk
Files:
36 added
7 edited

Legend:

Unmodified
Added
Removed
  • eupago-gateway-for-woocommerce/trunk/eupago-gateway-for-woocommerce.php

    r3005079 r3025695  
    44* Plugin URI:
    55* Description: This plugin allows customers to pay their orders with Multibanco, MB WAY, Payshop, Credit Card and CofidisPay with Eupago’s gateway. Beta Version.
    6 * Version: 4.0
     6* Version: 4.1
    77* Author: euPago
    88* Author URI: https://www.eupago.pt/
     
    1212
    1313use Automattic\WooCommerce\Internal\Admin\Orders\CustomOrdersTableController;
     14use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
    1415
    1516if (!defined('ABSPATH')) {
     
    2526         * @var string
    2627         */
    27         public const VERSION = '4.0';
     28        public const VERSION = '4.1';
    2829
    2930        /**
     
    3940        public function __construct()
    4041        {
     42
    4143            // Load plugin text domain
    4244            add_action('init', [ $this, 'load_plugin_textdomain' ]);
     
    4850            if (class_exists('WC_Payment_Gateway')) {
    4951                $this->includes();
     52                $wc_blocks_active = false;
     53                $wc_blocks_active = class_exists('Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType');
    5054
    5155                add_filter('woocommerce_payment_gateways', [ $this, 'add_gateway' ]);
     56                add_action('woocommerce_blocks_loaded', [ $this, 'woocommerce_blocks_add_payment_methods' ]);
    5257
    5358                add_filter('plugin_action_links_' . plugin_basename(__FILE__), [ $this, 'plugin_action_links' ]);
     
    5661                // add_filter( 'woocommerce_integrations', array( $this, 'add_integration' ) );
    5762
    58                 // Check if it is HPOS compliant
     63                // Check if it is HPOS and Blocks compliant
    5964                add_action('before_woocommerce_init', function () {
    6065                    \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
     66                    \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true);
    6167                });
    6268
     
    120126            wp_enqueue_style('admin_style', plugin_dir_url(__FILE__) . 'assets/css/admin_style.css');
    121127            $hpos_enabled = $this->is_hpos_compliant();
     128
    122129            if ($hpos_enabled) {
    123130                wp_enqueue_script('admin_script', plugin_dir_url(__FILE__) . 'assets/js/admin_js_hpos.js', ['jquery'], true);
    124             }
    125             else{
     131            } else {
    126132                wp_enqueue_script('admin_script', plugin_dir_url(__FILE__) . 'assets/js/admin_js.js', ['jquery'], true);
    127133            }
    128134            wp_localize_script('admin_script', 'MYajax', [ 'ajax_url' => admin_url('admin-ajax.php') ]);
    129            
    130135        }
    131136
     
    253258        {
    254259            $hpos_enabled = $this->is_hpos_compliant();
    255        
     260
    256261            $metabox = 'mbeupago_order_meta_box_html';
    257262            $screen = $hpos_enabled ? wc_get_page_screen_id('shop-order') : 'shop_order';
     263
    258264            if ($hpos_enabled) {
    259265                $metabox = 'mbeupago_order_meta_box_html_hpos';
    260266            }
    261        
    262            
    263             add_meta_box('woocommerce_eupago', __('EuPago Payment Details', 'eupago-gateway-for-woocommerce'), array($this, $metabox), $screen, 'side', 'core');
    264         }
    265        
     267
     268            add_meta_box('woocommerce_eupago', __('EuPago Payment Details', 'eupago-gateway-for-woocommerce'), [$this, $metabox], $screen, 'side', 'core');
     269        }
     270
    266271        public function mbeupago_order_meta_box_html($post)
    267272        {
    268273            include 'includes/views/order-meta-box.php';
    269274        }
    270        
     275
    271276        public function mbeupago_order_meta_box_html_hpos($post)
    272277        {
    273278            include 'includes/views/order-meta-box-hpos.php';
    274279        }
    275        
     280
    276281        private function is_hpos_compliant()
    277282        {
     
    279284            if (version_compare(WC_VERSION, '7.1', '>=')) {
    280285                $customOrdersTableController = wc_get_container()->get(\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class);
    281        
     286
    282287                if ($customOrdersTableController->custom_orders_table_usage_is_enabled()) {
    283288                    return true;
    284289                }
    285290            }
    286        
     291
    287292            return false;
    288293        }
    289        
    290294
    291295        // function save_vat_number( $order_id ){
     
    361365            }
    362366        }
     367
     368        public function woocommerce_blocks_add_payment_methods()
     369        {
     370            $file_path_mb = __DIR__ . '/includes/woocommerce-blocks/multibanco/MultibancoBlock.php';
     371            $file_path_mbw = __DIR__ . '/includes/woocommerce-blocks/mbway/MbwBlock.php';
     372            $file_path_cc = __DIR__ . '/includes/woocommerce-blocks/cc/CcBlock.php';
     373            $file_path_payshop = __DIR__ . '/includes/woocommerce-blocks/payshop/PayshopBlock.php';
     374            $file_path_cofidispay = __DIR__ . '/includes/woocommerce-blocks/cofidispay/CofidisPayBlock.php';
     375
     376
     377            if (file_exists($file_path_mb)) {
     378                require_once $file_path_mb;
     379
     380                add_action(
     381                    'woocommerce_blocks_payment_method_type_registration',
     382                    function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) {
     383                        $payment_method_registry->register(new \Automattic\WooCommerce\Blocks\Payments\Integrations\MultibancoBlock());
     384                    }
     385                );
     386            }
     387
     388            if (file_exists($file_path_mbw)) {
     389                require_once $file_path_mbw;
     390
     391                add_action(
     392                    'woocommerce_blocks_payment_method_type_registration',
     393                    function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) {
     394                        $payment_method_registry->register(new \Automattic\WooCommerce\Blocks\Payments\Integrations\MbwBlock());
     395                    }
     396                );
     397            }
     398
     399            if (file_exists($file_path_cc)) {
     400                require_once $file_path_cc;
     401
     402                add_action(
     403                    'woocommerce_blocks_payment_method_type_registration',
     404                    function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) {
     405                        $payment_method_registry->register(new \Automattic\WooCommerce\Blocks\Payments\Integrations\CcBlock());
     406                    }
     407                );
     408            }
     409
     410            if (file_exists($file_path_payshop)) {
     411                require_once $file_path_payshop;
     412
     413                add_action(
     414                    'woocommerce_blocks_payment_method_type_registration',
     415                    function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) {
     416                        $payment_method_registry->register(new \Automattic\WooCommerce\Blocks\Payments\Integrations\PayshopBlock());
     417                    }
     418                );
     419            }
     420
     421            if (file_exists($file_path_cofidispay)) {
     422                require_once $file_path_cofidispay;
     423
     424                add_action(
     425                    'woocommerce_blocks_payment_method_type_registration',
     426                    function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) {
     427                        $payment_method_registry->register(new \Automattic\WooCommerce\Blocks\Payments\Integrations\CofidisPayBlock());
     428                    }
     429                );
     430            }
     431
     432            if (file_exists($file_path_paysafecard)) {
     433                require_once $file_path_paysafecard;
     434
     435                add_action(
     436                    'woocommerce_blocks_payment_method_type_registration',
     437                    function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) {
     438                        $payment_method_registry->register(new \Automattic\WooCommerce\Blocks\Payments\Integrations\PaysafeCardBlock());
     439                    }
     440                );
     441            }
     442        }
    363443    }
    364444
  • eupago-gateway-for-woocommerce/trunk/includes/class-wc-eupago-api.php

    r3005079 r3025695  
    99  * @param WC_Eupago_API
    1010  */
    11   /*public function __construct() {
    12     $this->integration = new WC_Eupago_Integration;
    13   }*/
     11  public $wc_blocks_active = false;
     12
     13  public function __construct() {
     14    // $this->integration = new WC_Eupago_Integration;
     15        $this->wc_blocks_active        = class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' );
     16
     17  }
    1418
    1519  public function get_url() {
     
    185189  }
    186190
     191 
     192
    187193  public function pedidoCC($order, $valor, $logo_url, $return_url, $lang, $comment) {
    188 
    189     $client = @new SoapClient($this->get_url(), array('cache_wsdl' => WSDL_CACHE_NONE));
    190     return $client->pedidoCC(array(
    191       'chave' => $this->get_api_key(),
    192       'valor' => $this->money_format( $valor ),
    193       'id' => $order->get_id(),
    194       'url_logotipo' => $logo_url,
    195       'url_retorno' => $return_url,
    196       'nome' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(),
    197       'email' => $order->get_billing_email(),
    198       'lang' => $lang,
    199       'comentario' => $comment,
    200       'tds' => 1
    201     ));
    202   }
     194    if (extension_loaded('soap')) {
     195      $client = @new SoapClient($this->get_url(), array('cache_wsdl' => WSDL_CACHE_NONE));
     196      return $client->pedidoCC(array(
     197        'chave' => $this->get_api_key(),
     198        'valor' => $this->money_format( $valor ),
     199        'id' => $order->get_id(),
     200        'url_logotipo' => $logo_url,
     201        'url_retorno' => $return_url,
     202        'nome' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(),
     203        'email' => $order->get_billing_email(),
     204        'lang' => $lang,
     205        'comentario' => $comment,
     206        'tds' => 1
     207      ));
     208  }else{
     209    $url = 'https://' . get_option('eupago_endpoint') . '.eupago.pt/api/v1.02/creditcard/create';
     210      $data = array(
     211          'payment' => array(
     212              'amount' => array(
     213                  'value' => $valor,
     214                  'currency' => 'EUR'
     215              ),
     216              'identifier' =>(string) $order->get_id(),
     217              'lang' => $lang,
     218              'successUrl' => $return_url,
     219              'failUrl' => $return_url,
     220              'backUrl' => $return_url
     221          ),
     222          'customer' => array(
     223              'notify' => true,
     224              'email' => $order->get_billing_email()
     225          )
     226      );
     227
     228      $headers = array(
     229          'Content-Type: application/json',
     230          'Accept: application/json',
     231          'Authorization: ApiKey ' . $this->get_api_key(),
     232      );
     233
     234      $curl = curl_init();
     235
     236      curl_setopt($curl, CURLOPT_URL, $url);
     237      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     238      curl_setopt($curl, CURLOPT_POST, true);
     239      curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($data));
     240      curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     241      curl_setopt($curl, CURLOPT_TIMEOUT, 60);
     242
     243      $response = curl_exec($curl);
     244
     245      if (curl_errno($curl)) {
     246          echo 'cURL Error: ' . curl_error($curl);
     247      }
     248
     249      curl_close($curl);
     250
     251      return $response;
     252  }
     253}
    203254
    204255  public function pedidoPF($order, $valor, $return_url, $comment) {
     
    252303  public function cofidispay_create($order_id)
    253304  {
     305
    254306    $order = wc_get_order( $order_id );
    255307
     
    282334      'taxCode' => $code,
    283335    ];
     336
    284337    $tax = new WC_Tax();
    285338    foreach ($order->get_items() as $item) {
     
    346399      ]
    347400    );
     401
    348402    $response_body = wp_remote_retrieve_body($response);
    349403
     
    351405  }
    352406
     407 
     408
    353409}
  • eupago-gateway-for-woocommerce/trunk/includes/class-wc-eupago-cc.php

    r3005079 r3025695  
    66
    77/*
    8 * Eupago - Credit Card
    9 *
    10 * @since 1.1
    11 */
     8 * Eupago - Credit Card
     9 *
     10 * @since 1.1
     11 */
    1212if (!class_exists('WC_Eupago_CC')) {
    1313    class WC_Eupago_CC extends WC_Payment_Gateway
     
    5252            }
    5353            add_action('woocommerce_thankyou_' . $this->id, [$this, 'thankyou_page']);
    54             add_action('woocommerce_order_details_after_order_table', [ $this, 'order_details_after_order_table' ], 20);
     54            add_action('woocommerce_order_details_after_order_table', [$this, 'order_details_after_order_table'], 20);
    5555
    5656            add_filter('woocommerce_available_payment_gateways', [$this, 'disable_unless_portugal']);
     
    7878        }
    7979
    80         /**
    81          * Initialise Gateway Settings Form Fields
     80
     81        /**
     82         * Initialize form fields for the Eupago Gateway - Credit Card settings in WooCommerce.
     83         *
     84         * This method sets up the form fields that will be displayed in the WooCommerce admin settings of Credit Card page
     85         * for the Eupago Gateway plugin.
     86         *
    8287         */
    8388        public function init_form_fields()
    8489        {
     90            // Get the current language of the WooCommerce admin page
     91            $admin_language = get_locale();
     92            // Default language options
     93            $language_options = [
     94                'default' => __('Default', 'eupago-gateway-for-woocommerce'),
     95                'pt' => __('Portuguese', 'eupago-gateway-for-woocommerce'),
     96                'en' => __('English', 'eupago-gateway-for-woocommerce'),
     97                'es' => __('Spanish', 'eupago-gateway-for-woocommerce'),
     98            ];
     99
     100            // Translate language options if the admin language is not English
     101            if ($admin_language === 'pt_PT' || $admin_language === 'pt_BR') {
     102                $language_options['default'] = __('Por padrão', 'eupago-gateway-for-woocommerce');
     103                $language_options['pt'] = __('Português', 'eupago-gateway-for-woocommerce');
     104                $language_options['en'] = __('Inglês', 'eupago-gateway-for-woocommerce');
     105                $language_options['es'] = __('Espanhol', 'eupago-gateway-for-woocommerce');
     106            } elseif ($admin_language === 'es_ES') {
     107                $language_options['default'] = __('Default', 'eupago-gateway-for-woocommerce');
     108                $language_options['pt'] = __('Portuguese', 'eupago-gateway-for-woocommerce');
     109                $language_options['en'] = __('English', 'eupago-gateway-for-woocommerce');
     110                $language_options['es'] = __('Spanish', 'eupago-gateway-for-woocommerce');
     111            }
     112
     113            // Translate title based on the selected language
     114            $language_title = esc_html(__('Language', 'eupago-gateway-for-woocommerce'));
     115            $language_description = esc_html(__('Select the language for the payment process.', 'eupago-gateway-for-woocommerce'));
     116
     117            if ($admin_language === 'pt_PT' || $admin_language === 'pt_BR') {
     118                $language_title = esc_html(__('Idioma', 'eupago-gateway-for-woocommerce'));
     119                $language_description = esc_html(__('Selecione o idioma para o processo de pagamento.', 'eupago-gateway-for-woocommerce'));
     120            } elseif ($admin_language === 'es_ES') {
     121                $language_title = esc_html(__('Idioma', 'eupago-gateway-for-woocommerce'));
     122                $language_description = esc_html(__('Seleccione el idioma para el proceso de pago.', 'eupago-gateway-for-woocommerce'));
     123            }
     124
    85125            $this->form_fields = [
    86               'enabled' => [
    87                 'title' => __('Enable/Disable', 'eupago-gateway-for-woocommerce'),
    88                 'type' => 'checkbox',
    89                 'label' => __('Enable Credit Card (using Eupago)', 'eupago-gateway-for-woocommerce'),
    90                 'default' => 'no',
    91               ],
    92               'title' => [
    93                 'title' => __('Title', 'eupago-gateway-for-woocommerce'),
    94                 'type' => 'text',
    95                 'description' => __('This controls the title which the user sees during checkout.', 'eupago-gateway-for-woocommerce'),
    96                 'default' => __('Credit Card', 'eupago-gateway-for-woocommerce'),
    97               ],
    98               'description' => [
    99                 'title' => __('Description', 'eupago-gateway-for-woocommerce'),
    100                 'type' => 'textarea',
    101                 'description' => __('This controls the description which the user sees during checkout.', 'eupago-gateway-for-woocommerce'),
    102                 'default' => __('Pay with credit card', 'eupago-gateway-for-woocommerce'),
    103               ],
    104               'logo_url' => [
    105                 'title' => __('Logo', 'eupago-gateway-for-woocommerce'),
    106                 'type' => 'text',
    107                 'description' => __('Shop Logo for payment page', 'eupago-gateway-for-woocommerce'),
    108                 'default' => '',
    109               ],
    110               'instructions' => [
    111                 'title' => __('Instructions', 'eupago-gateway-for-woocommerce'),
    112                 'type' => 'textarea',
    113                 'description' => __('Instructions that will be added to the thank you page and email sent to customer.', 'eupago-gateway-for-woocommerce'),
    114               ],
    115               'only_portugal' => [
    116                 'title' => __('Only for Portuguese customers?', 'eupago-gateway-for-woocommerce'),
    117                 'type' => 'checkbox',
    118                 'label' => __('Enable only for customers whose address is in Portugal', 'eupago-gateway-for-woocommerce'),
    119                 'default' => 'no',
    120               ],
    121               'only_above' => [
    122                 'title' => __('Only for orders above', 'eupago-gateway-for-woocommerce'),
    123                 'type' => 'number',
    124                 'description' => __('Enable only for orders above x &euro; (exclusive). Leave blank (or zero) to allow for any order value.', 'eupago-gateway-for-woocommerce') . ' <br/> ' . __('By design, Mulitibanco only allows payments from 1 to 999999 &euro; (inclusive). You can use this option to further limit this range.', 'eupago-gateway-for-woocommerce'),
    125                 'default' => '',
    126               ],
    127               'only_below' => [
    128                 'title' => __('Only for orders below', 'eupago-gateway-for-woocommerce'),
    129                 'type' => 'number',
    130                 'description' => __('Enable only for orders below x &euro; (exclusive). Leave blank (or zero) to allow for any order value.', 'eupago-gateway-for-woocommerce') . ' <br/> ' . __('By design, Mulitibanco only allows payments from 1 to 999999 &euro; (inclusive). You can use this option to further limit this range.', 'eupago-gateway-for-woocommerce'),
    131                 'default' => '',
    132               ],
    133               'stock_when' => [
    134                 'title' => __('Reduce stock', 'eupago-gateway-for-woocommerce'),
    135                 'type' => 'select',
    136                 'description' => __('Choose when to reduce stock.', 'eupago-gateway-for-woocommerce'),
    137                 'default' => '',
    138                 'options' => [
    139                   '' => __('when order is paid (requires active callback)', 'eupago-gateway-for-woocommerce'),
    140                   'order' => __('when order is placed (before payment)', 'eupago-gateway-for-woocommerce'),
    141                 ],
    142               ],
     126                'enabled' => [
     127                    'title' => esc_html(__('Enable/Disable', 'eupago-gateway-for-woocommerce')),
     128                    'type' => 'checkbox',
     129                    'label' => esc_html(__('Enable Credit Card (using Eupago)', 'eupago-gateway-for-woocommerce')),
     130                    'default' => 'no',
     131                ],
     132                'title' => [
     133                    'title' => esc_html(__('Title', 'eupago-gateway-for-woocommerce')),
     134                    'type' => 'text',
     135                    'description' => esc_html(__('This controls the title which the user sees during checkout.', 'eupago-gateway-for-woocommerce')),
     136                    'default' => esc_html__('Credit Card', 'eupago-gateway-for-woocommerce'),
     137                ],
     138                'description' => [
     139                    'title' => esc_html(__('Description', 'eupago-gateway-for-woocommerce')),
     140                    'type' => 'textarea',
     141                    'description' => esc_html(__('This controls the description which the user sees during checkout.', 'eupago-gateway-for-woocommerce')),
     142                    'default' => esc_html__('Pay with credit card', 'eupago-gateway-for-woocommerce'),
     143                ],
     144                'logo_url' => [
     145                    'title' => esc_html(__('Logo', 'eupago-gateway-for-woocommerce')),
     146                    'type' => 'text',
     147                    'description' => esc_html(__('Shop Logo for payment page', 'eupago-gateway-for-woocommerce')),
     148                    'default' => '',
     149                ],
     150                'instructions' => [
     151                    'title' => esc_html(__('Instructions', 'eupago-gateway-for-woocommerce')),
     152                    'type' => 'textarea',
     153                    'description' => esc_html(__('Instructions that will be added to the thank you page and email sent to customer.', 'eupago-gateway-for-woocommerce')),
     154                ],
     155                'only_portugal' => [
     156                    'title' => esc_html(__('Only for Portuguese customers?', 'eupago-gateway-for-woocommerce')),
     157                    'type' => 'checkbox',
     158                    'label' => esc_html(__('Enable only for customers whose address is in Portugal', 'eupago-gateway-for-woocommerce')),
     159                    'default' => 'no',
     160                ],
     161                'only_above' => [
     162                    'title' => esc_html(__('Only for orders above', 'eupago-gateway-for-woocommerce')),
     163                    'type' => 'number',
     164                    'description' => esc_html(__('Enable only for orders above x &euro; (exclusive). Leave blank (or zero) to allow for any order value.', 'eupago-gateway-for-woocommerce')) . ' <br/> ' . esc_html(__('By design, Mulitibanco only allows payments from 1 to 999999 &euro; (inclusive). You can use this option to further limit this range.', 'eupago-gateway-for-woocommerce')),
     165                    'default' => 0,
     166                ],
     167                'only_below' => [
     168                    'title' => esc_html(__('Only for orders below', 'eupago-gateway-for-woocommerce')),
     169                    'type' => 'number',
     170                    'description' => esc_html(__('Enable only for orders below x &euro; (exclusive). Leave blank (or zero) to allow for any order value.', 'eupago-gateway-for-woocommerce')) . ' <br/> ' . esc_html(__('By design, Mulitibanco only allows payments from 1 to 999999 &euro; (inclusive). You can use this option to further limit this range.', 'eupago-gateway-for-woocommerce')),
     171                    'default' => 0,
     172                ],
     173                'stock_when' => [
     174                    'title' => esc_html(__('Reduce stock', 'eupago-gateway-for-woocommerce')),
     175                    'type' => 'select',
     176                    'description' => esc_html(__('Choose when to reduce stock.', 'eupago-gateway-for-woocommerce')),
     177                    'default' => '',
     178                    'options' => [
     179                        '' => esc_html(__('when order is paid (requires active callback)', 'eupago-gateway-for-woocommerce')),
     180                        'order' => esc_html(__('when order is placed (before payment)', 'eupago-gateway-for-woocommerce')),
     181                    ],
     182                ],
     183                'language' => [
     184                    'title' => $language_title,
     185                    'type' => 'select',
     186                    'description' => $language_description,
     187                    'default' => 'default',
     188                    'options' => $language_options,
     189                ],
    143190            ];
    144191        }
     
    217264            if ($plain_text) {
    218265                wc_get_template('emails/plain-instructions.php', [
    219                   'method' => $payment_method,
    220                   'payment_name' => (function_exists('icl_object_id') ? icl_t($this->id, $this->id . '_title', $this->title) : $this->title),
    221                   'instructions' => isset($this->instructions) && !empty($this->instructions) ? $this->instructions : '',
    222                   'referencia' => $order->get_meta('_eupago_cc_referencia', true),
    223                   'order_total' => $order_total,
     266                    'method' => $payment_method,
     267                    'payment_name' => (function_exists('icl_object_id') ? icl_t($this->id, $this->id . '_title', $this->title) : $this->title),
     268                    'instructions' => isset($this->instructions) && !empty($this->instructions) ? $this->instructions : '',
     269                    'referencia' => $order->get_meta('_eupago_cc_referencia', true),
     270                    'order_total' => $order_total,
    224271                ], 'woocommerce/eupago/', (new WC_Eupago())->get_templates_path());
    225272            } else {
    226273                wc_get_template('emails/html-instructions.php', [
    227                   'method' => $payment_method,
    228                   'payment_name' => (function_exists('icl_object_id') ? icl_t($this->id, $this->id . '_title', $this->title) : $this->title),
    229                   'instructions' => isset($this->instructions) && !empty($this->instructions) ? $this->instructions : '',
    230                   'referencia' => $order->get_meta('_eupago_cc_referencia', true),
    231                   'order_total' => $order_total,
     274                    'method' => $payment_method,
     275                    'payment_name' => (function_exists('icl_object_id') ? icl_t($this->id, $this->id . '_title', $this->title) : $this->title),
     276                    'instructions' => isset($this->instructions) && !empty($this->instructions) ? $this->instructions : '',
     277                    'referencia' => $order->get_meta('_eupago_cc_referencia', true),
     278                    'order_total' => $order_total,
    232279                ], 'woocommerce/eupago/', (new WC_Eupago())->get_templates_path());
    233280            }
     
    236283        public function check_order_errors($order_id)
    237284        {
    238           $order = wc_get_order($order_id);
     285            $order = wc_get_order($order_id);
    239286            $order_total = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total;
    240287
     
    253300
    254301        /**
    255          * Process it
     302         * Process the Eupago payment for the given order.
     303         *
     304         * @param int $order_id The order ID.
    256305         */
    257306        public function process_payment($order_id)
    258307        {
    259308            global $woocommerce;
     309
    260310            $order = wc_get_order($order_id);
    261311            $order_total = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total;
     
    264314            if ($error_message = $this->check_order_errors($order_id)) {
    265315                wc_add_notice(__('Payment error:', 'eupago-gateway-for-woocommerce') . ' ' . $error_message, 'error');
    266 
    267316                return;
    268317            }
    269318
    270             $lang = $order->get_meta('wpml_language', true);
    271             if (empty($lang)) {
    272                 $lang = 'pt-pt';
    273             }
    274 
    275            
    276 
     319            // Determine language
     320            $lang = $this->determine_language($order);
     321
     322            // Make Eupago CC request
    277323            $eupagoCC = $this->client->pedidoCC($order, $order_total, $this->get_option('logo_url'), $this->get_return_url($order), $lang, $this->get_comment_table($order, $order_total));
     324            if (is_string($eupagoCC)) {
     325                $data = json_decode($eupagoCC, true);
     326                if ($data !== null) {
     327                    $redirect_url = $data['redirectUrl'];
     328                } else {
     329                    echo 'Erro ao decodificar JSON';
     330                }
     331            } else {
     332                $redirect_url = $eupagoCC->redirectUrl;
     333            }
    278334
    279335            if ($eupagoCC->estado != 0) {
    280336                $error_message = $eupagoCC->resposta;
    281337                wc_add_notice(__('Payment error:', 'eupago-gateway-for-woocommerce') . ' ' . $error_message, 'error');
    282 
    283338                return;
    284339            }
    285340
    286             // update_post_meta ($order_id, '_eupago_cc_referencia', $eupagoCC->referencia);
    287 
     341            // Update order meta data
    288342            $order->update_meta_data('_eupago_cc_referencia', $eupagoCC->referencia);
    289343            $order->save();
     
    293347
    294348            // Reduce stock levels
     349            $this->reduce_stock_levels($order);
     350
     351            // Empty cart and session
     352            $this->clear_cart_and_session();
     353
     354            // Return thankyou redirect
     355            return [
     356                'result' => 'success',
     357                'redirect' => $eupagoCC->url,
     358            ];
     359        }
     360
     361        /**
     362         * Determine the language for the Eupago request.
     363         *
     364         * @param WC_Order $order The WooCommerce order.
     365         * @return string The language code.
     366         */
     367        private function determine_language($order)
     368        {
     369            $lang = 'pt'; // Default to PT
     370
     371            // Check if WPML is installed
     372            if (function_exists('icl_object_id') && function_exists('icl_register_string')) {
     373                // Use WPML language if available
     374                $lang_from_wpml = $order->get_meta('wpml_language', true);
     375                if (!empty($lang_from_wpml)) {
     376                    $lang = $lang_from_wpml;
     377                }
     378            } else {
     379                // WPML not installed, use the language selected in the form or fallback to default
     380                $lang_from_form = $this->get_option('language');
     381
     382                if ($lang_from_form !== 'default') {
     383                    $lang = $lang_from_form;
     384                }
     385                // Else, default to 'pt-pt'
     386            }
     387
     388            return $lang;
     389        }
     390
     391        /**
     392         * Reduce stock levels based on configuration.
     393         *
     394         * @param WC_Order $order The WooCommerce order.
     395         */
     396        private function reduce_stock_levels($order)
     397        {
    295398            if ($this->stock_when == 'order') {
    296399                $order->reduce_order_stock();
    297400            }
     401        }
     402
     403        /**
     404         * Clear cart and session after successful payment.
     405         */
     406        private function clear_cart_and_session()
     407        {
     408            global $woocommerce;
    298409
    299410            // Remove cart
     
    305416            }
    306417
    307             // Return thankyou redirect
    308             return [
    309               'result' => 'success',
    310               'redirect' => $eupagoCC->url,
    311             ];
     418            if (isset($eupagoCC->url) && !empty($eupagoCC->url)) {
     419                return [
     420                    'result' => 'success',
     421                    'redirect' => $eupagoCC->url,
     422                ];
     423            }else{
     424                return [
     425                    'result' => 'success',
     426                    'redirect' => $redirect_url,
     427                ];
     428               
     429            }
    312430        }
    313431
     
    382500        public function woocommerce_payment_complete_reduce_order_stock($bool, $order_id)
    383501        {
    384           $order = wc_get_order($order_id);
     502            $order = wc_get_order($order_id);
    385503
    386504            if ($order->get_payment_method() == $this->id) {
    387                 return  (new WC_Eupago())->woocommerce_payment_complete_reduce_order_stock($bool, $order, $this->id, $this->stock_when) ;
     505                return (new WC_Eupago())->woocommerce_payment_complete_reduce_order_stock($bool, $order, $this->id, $this->stock_when);
    388506            } else {
    389507                return $bool;
  • eupago-gateway-for-woocommerce/trunk/includes/class-wc-eupago-cofidispay.php

    r3005079 r3025695  
    9595                'type' => 'text',
    9696                'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'),
    97                 'default' => __('Até 12 vezes sem juros', 'eupago-for-woocommerce'),
     97                'default' => __('Cofidis Pay', 'eupago-for-woocommerce'),
    9898              ],
    9999              'instructions' => [
     
    218218        public function check_order_errors($order_id)
    219219        {
    220           $order = wc_get_order($order_id);
    221           $order_total = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total;
     220            $order = wc_get_order($order_id);
     221            $order_total = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total;
    222222
    223223            // A loja não está em Euros
     
    231231            }
    232232
    233             if (!isset($_POST['cofidispay_vat_number']) || empty($_POST['cofidispay_vat_number'])) {
     233            if (!isset($_POST['nif']) || empty($_POST['nif'])) {
    234234                return __('Por favor, insira um NIF válido para prosseguir com o pagamento!', 'eupago-for-woocommerce');
    235235            }
     
    320320      <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cofidispay-form" class="wc-cofidispay-form wc-payment-form" style="background:transparent;">
    321321        <p class="form-row form-row-first">
    322           <label for="cofidispay_vat_number"><?php esc_html_e('Número de identificação fiscal', 'eupago-for-woocommerce'); ?></label>
    323           <input type="text" id="cofidispay_vat_number" autocorrect="off" spellcheck="false" name="cofidispay_vat_number" class="input-text" aria-label="<?php _e('Número de identificação fiscal', 'eupago-for-woocommerce'); ?>" aria-placeholder="" aria-invalid="false" required />
     322          <label for="nif"><?php esc_html_e('Número de identificação fiscal', 'eupago-for-woocommerce'); ?></label>
     323          <input type="text" id="nif" autocorrect="off" spellcheck="false" name="nif" class="input-text" aria-label="<?php _e('Número de identificação fiscal', 'eupago-for-woocommerce'); ?>" aria-placeholder="" aria-invalid="false" required />
    324324        </p>
    325325        <div class="clear"></div>
     
    333333        public function process_payment($order_id)
    334334        {
    335 
    336335            global $woocommerce;
    337336            // $order = new WC_Order($order_id);
     
    339338
    340339            $order_total = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total;
    341             $cofidispay_vat_number = isset($_POST['cofidispay_vat_number']) && !empty($_POST['cofidispay_vat_number']) ? $_POST['cofidispay_vat_number'] : '';
    342 
    343             // update_post_meta($order_id, '_eupago_cofidis_vat_number', $cofidispay_vat_number);
     340            $cofidispay_vat_number = isset($_POST['nif']) && !empty($_POST['nif']) ? $_POST['nif'] : '';
     341
    344342            $order->update_meta_data('_eupago_cofidis_vat_number', $cofidispay_vat_number);
    345343            $order->save();
     
    347345            if ($error_message = $this->check_order_errors($order_id)) {
    348346                wc_add_notice($error_message, 'error');
    349 
    350347                return;
    351348            }
     
    460457        public function woocommerce_payment_complete_reduce_order_stock($bool, $order_id)
    461458        {
    462           $order = wc_get_order($order_id);
     459            $order = wc_get_order($order_id);
    463460
    464461            if ($order->get_payment_method() == $this->id) {
  • eupago-gateway-for-woocommerce/trunk/includes/class-wc-eupago-mbway.php

    r3005079 r3025695  
    107107                'type' => 'textarea',
    108108                'description' => __('This controls the description which the user sees during checkout.', 'eupago-gateway-for-woocommerce'),
    109                 'default' => __('You will receive a notification in your MBWAY. When you open the notification you will be asked to confirm the purchase by simply entering your MB WAY PIN.', 'eupago-gateway-for-woocommerce'),
     109                'default' => __('', 'eupago-gateway-for-woocommerce'),
    110110              ],
    111111              'instructions' => [
  • eupago-gateway-for-woocommerce/trunk/includes/class-wc-eupago-multibanco.php

    r3005079 r3025695  
    2020         * @return void
    2121         */
     22
    2223        public function __construct()
    2324        {
     
    2728            $this->icon = plugins_url('assets/images/multibanco_icon.png', dirname(__FILE__));
    2829            $this->has_fields = false;
    29             $this->method_title = __('Pagamento de Serviços no Multibanco (Eupago)', 'eupago-gateway-for-woocommerce');
     30            $this->method_title = __('Multibanco', 'eupago-gateway-for-woocommerce');
    3031
    3132            // Plugin options and settings
     
    5051            add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']);
    5152
     53
    5254            if (function_exists('icl_object_id') && function_exists('icl_register_string')) {
    5355                add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'register_wpml_strings']);
     
    6264                add_action('admin_notices', [$this, 'admin_error_euros']);
    6365            }
     66
    6467            // Customer Emails
    6568            add_action('woocommerce_email_before_order_table', [$this, 'email_instructions'], 10, 2);
     
    184187        public function check_order_errors($order_id)
    185188        {
    186           $order = wc_get_order($order_id);
    187           $order_total = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total;
     189            $order = wc_get_order($order_id);
     190            $order_total = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total;
    188191
    189192            // A loja não está em Euros
     
    412415        public function woocommerce_payment_complete_reduce_order_stock($bool, $order_id)
    413416        {
    414           $order = wc_get_order($order_id);
     417            $order = wc_get_order($order_id);
    415418
    416419            if ($order->get_payment_method() == $this->id) {
    417                 return  (new WC_Eupago())->woocommerce_payment_complete_reduce_order_stock($bool, $order, $this->id, $this->stock_when) ;
     420                return (new WC_Eupago())->woocommerce_payment_complete_reduce_order_stock($bool, $order, $this->id, $this->stock_when) ;
    418421            } else {
    419422                return $bool;
    420423            }
    421424        }
     425
     426       
    422427    } // WC_Multibanco_Eupago
    423428} // class_exists()
  • eupago-gateway-for-woocommerce/trunk/readme.txt

    r3005079 r3025695  
    55Plugin URI:
    66Requires at least: 4.4
    7 Tested up to: 6.3.2
     7Tested up to: 6.4.2
    88Requires PHP: 7.0
    9 Stable tag: 4.0
     9Stable tag: 4.1
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4343
    4444== Changelog ==
     45
     46= 4.1 (22/01/2024) =
     47* Added compatibility with woocommerce checkout blocks.
     48* Added option to change language on credit card payment form.
     49* Added REST request for mbway payment method.
     50* Small bug fixes and translations.
    4551
    4652= 4.0 (30/11/2023) =
Note: See TracChangeset for help on using the changeset viewer.