Changeset 3025695
- Timestamp:
- 01/23/2024 12:11:06 PM (2 years ago)
- Location:
- eupago-gateway-for-woocommerce/trunk
- Files:
-
- 36 added
- 7 edited
-
eupago-gateway-for-woocommerce.php (modified) (10 diffs)
-
includes/class-wc-eupago-api.php (modified) (6 diffs)
-
includes/class-wc-eupago-cc.php (modified) (10 diffs)
-
includes/class-wc-eupago-cofidispay.php (modified) (8 diffs)
-
includes/class-wc-eupago-mbway.php (modified) (1 diff)
-
includes/class-wc-eupago-multibanco.php (modified) (6 diffs)
-
includes/woocommerce-blocks (added)
-
includes/woocommerce-blocks/cc (added)
-
includes/woocommerce-blocks/cc/CcBlock.php (added)
-
includes/woocommerce-blocks/cc/cc_icon.jpg (added)
-
includes/woocommerce-blocks/cc/index.php (added)
-
includes/woocommerce-blocks/cc/src (added)
-
includes/woocommerce-blocks/cc/src/index.js (added)
-
includes/woocommerce-blocks/cc/src/index.php (added)
-
includes/woocommerce-blocks/cofidispay (added)
-
includes/woocommerce-blocks/cofidispay/CofidisPayBlock.php (added)
-
includes/woocommerce-blocks/cofidispay/cofidispay.png (added)
-
includes/woocommerce-blocks/cofidispay/index.php (added)
-
includes/woocommerce-blocks/cofidispay/src (added)
-
includes/woocommerce-blocks/cofidispay/src/index.js (added)
-
includes/woocommerce-blocks/cofidispay/src/index.php (added)
-
includes/woocommerce-blocks/mbway (added)
-
includes/woocommerce-blocks/mbway/MbwBlock.php (added)
-
includes/woocommerce-blocks/mbway/index.php (added)
-
includes/woocommerce-blocks/mbway/mbway_banner.png (added)
-
includes/woocommerce-blocks/mbway/src (added)
-
includes/woocommerce-blocks/mbway/src/index.js (added)
-
includes/woocommerce-blocks/mbway/src/index.php (added)
-
includes/woocommerce-blocks/multibanco (added)
-
includes/woocommerce-blocks/multibanco/MultibancoBlock.php (added)
-
includes/woocommerce-blocks/multibanco/index.php (added)
-
includes/woocommerce-blocks/multibanco/multibanco_banner.png (added)
-
includes/woocommerce-blocks/multibanco/src (added)
-
includes/woocommerce-blocks/multibanco/src/index.js (added)
-
includes/woocommerce-blocks/multibanco/src/index.php (added)
-
includes/woocommerce-blocks/payshop (added)
-
includes/woocommerce-blocks/payshop/PayshopBlock.php (added)
-
includes/woocommerce-blocks/payshop/index.php (added)
-
includes/woocommerce-blocks/payshop/payshop_banner.png (added)
-
includes/woocommerce-blocks/payshop/src (added)
-
includes/woocommerce-blocks/payshop/src/index.js (added)
-
includes/woocommerce-blocks/payshop/src/index.php (added)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
eupago-gateway-for-woocommerce/trunk/eupago-gateway-for-woocommerce.php
r3005079 r3025695 4 4 * Plugin URI: 5 5 * 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. 06 * Version: 4.1 7 7 * Author: euPago 8 8 * Author URI: https://www.eupago.pt/ … … 12 12 13 13 use Automattic\WooCommerce\Internal\Admin\Orders\CustomOrdersTableController; 14 use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry; 14 15 15 16 if (!defined('ABSPATH')) { … … 25 26 * @var string 26 27 */ 27 public const VERSION = '4. 0';28 public const VERSION = '4.1'; 28 29 29 30 /** … … 39 40 public function __construct() 40 41 { 42 41 43 // Load plugin text domain 42 44 add_action('init', [ $this, 'load_plugin_textdomain' ]); … … 48 50 if (class_exists('WC_Payment_Gateway')) { 49 51 $this->includes(); 52 $wc_blocks_active = false; 53 $wc_blocks_active = class_exists('Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType'); 50 54 51 55 add_filter('woocommerce_payment_gateways', [ $this, 'add_gateway' ]); 56 add_action('woocommerce_blocks_loaded', [ $this, 'woocommerce_blocks_add_payment_methods' ]); 52 57 53 58 add_filter('plugin_action_links_' . plugin_basename(__FILE__), [ $this, 'plugin_action_links' ]); … … 56 61 // add_filter( 'woocommerce_integrations', array( $this, 'add_integration' ) ); 57 62 58 // Check if it is HPOS compliant63 // Check if it is HPOS and Blocks compliant 59 64 add_action('before_woocommerce_init', function () { 60 65 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true); 66 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true); 61 67 }); 62 68 … … 120 126 wp_enqueue_style('admin_style', plugin_dir_url(__FILE__) . 'assets/css/admin_style.css'); 121 127 $hpos_enabled = $this->is_hpos_compliant(); 128 122 129 if ($hpos_enabled) { 123 130 wp_enqueue_script('admin_script', plugin_dir_url(__FILE__) . 'assets/js/admin_js_hpos.js', ['jquery'], true); 124 } 125 else{ 131 } else { 126 132 wp_enqueue_script('admin_script', plugin_dir_url(__FILE__) . 'assets/js/admin_js.js', ['jquery'], true); 127 133 } 128 134 wp_localize_script('admin_script', 'MYajax', [ 'ajax_url' => admin_url('admin-ajax.php') ]); 129 130 135 } 131 136 … … 253 258 { 254 259 $hpos_enabled = $this->is_hpos_compliant(); 255 260 256 261 $metabox = 'mbeupago_order_meta_box_html'; 257 262 $screen = $hpos_enabled ? wc_get_page_screen_id('shop-order') : 'shop_order'; 263 258 264 if ($hpos_enabled) { 259 265 $metabox = 'mbeupago_order_meta_box_html_hpos'; 260 266 } 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 266 271 public function mbeupago_order_meta_box_html($post) 267 272 { 268 273 include 'includes/views/order-meta-box.php'; 269 274 } 270 275 271 276 public function mbeupago_order_meta_box_html_hpos($post) 272 277 { 273 278 include 'includes/views/order-meta-box-hpos.php'; 274 279 } 275 280 276 281 private function is_hpos_compliant() 277 282 { … … 279 284 if (version_compare(WC_VERSION, '7.1', '>=')) { 280 285 $customOrdersTableController = wc_get_container()->get(\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class); 281 286 282 287 if ($customOrdersTableController->custom_orders_table_usage_is_enabled()) { 283 288 return true; 284 289 } 285 290 } 286 291 287 292 return false; 288 293 } 289 290 294 291 295 // function save_vat_number( $order_id ){ … … 361 365 } 362 366 } 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 } 363 443 } 364 444 -
eupago-gateway-for-woocommerce/trunk/includes/class-wc-eupago-api.php
r3005079 r3025695 9 9 * @param WC_Eupago_API 10 10 */ 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 } 14 18 15 19 public function get_url() { … … 185 189 } 186 190 191 192 187 193 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 } 203 254 204 255 public function pedidoPF($order, $valor, $return_url, $comment) { … … 252 303 public function cofidispay_create($order_id) 253 304 { 305 254 306 $order = wc_get_order( $order_id ); 255 307 … … 282 334 'taxCode' => $code, 283 335 ]; 336 284 337 $tax = new WC_Tax(); 285 338 foreach ($order->get_items() as $item) { … … 346 399 ] 347 400 ); 401 348 402 $response_body = wp_remote_retrieve_body($response); 349 403 … … 351 405 } 352 406 407 408 353 409 } -
eupago-gateway-for-woocommerce/trunk/includes/class-wc-eupago-cc.php
r3005079 r3025695 6 6 7 7 /* 8 * Eupago - Credit Card9 *10 * @since 1.111 */8 * Eupago - Credit Card 9 * 10 * @since 1.1 11 */ 12 12 if (!class_exists('WC_Eupago_CC')) { 13 13 class WC_Eupago_CC extends WC_Payment_Gateway … … 52 52 } 53 53 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); 55 55 56 56 add_filter('woocommerce_available_payment_gateways', [$this, 'disable_unless_portugal']); … … 78 78 } 79 79 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 * 82 87 */ 83 88 public function init_form_fields() 84 89 { 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 85 125 $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 € (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 € (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 € (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 € (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 € (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 € (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 € (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 € (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 ], 143 190 ]; 144 191 } … … 217 264 if ($plain_text) { 218 265 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, 224 271 ], 'woocommerce/eupago/', (new WC_Eupago())->get_templates_path()); 225 272 } else { 226 273 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, 232 279 ], 'woocommerce/eupago/', (new WC_Eupago())->get_templates_path()); 233 280 } … … 236 283 public function check_order_errors($order_id) 237 284 { 238 $order = wc_get_order($order_id);285 $order = wc_get_order($order_id); 239 286 $order_total = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total; 240 287 … … 253 300 254 301 /** 255 * Process it 302 * Process the Eupago payment for the given order. 303 * 304 * @param int $order_id The order ID. 256 305 */ 257 306 public function process_payment($order_id) 258 307 { 259 308 global $woocommerce; 309 260 310 $order = wc_get_order($order_id); 261 311 $order_total = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total; … … 264 314 if ($error_message = $this->check_order_errors($order_id)) { 265 315 wc_add_notice(__('Payment error:', 'eupago-gateway-for-woocommerce') . ' ' . $error_message, 'error'); 266 267 316 return; 268 317 } 269 318 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 277 323 $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 } 278 334 279 335 if ($eupagoCC->estado != 0) { 280 336 $error_message = $eupagoCC->resposta; 281 337 wc_add_notice(__('Payment error:', 'eupago-gateway-for-woocommerce') . ' ' . $error_message, 'error'); 282 283 338 return; 284 339 } 285 340 286 // update_post_meta ($order_id, '_eupago_cc_referencia', $eupagoCC->referencia); 287 341 // Update order meta data 288 342 $order->update_meta_data('_eupago_cc_referencia', $eupagoCC->referencia); 289 343 $order->save(); … … 293 347 294 348 // 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 { 295 398 if ($this->stock_when == 'order') { 296 399 $order->reduce_order_stock(); 297 400 } 401 } 402 403 /** 404 * Clear cart and session after successful payment. 405 */ 406 private function clear_cart_and_session() 407 { 408 global $woocommerce; 298 409 299 410 // Remove cart … … 305 416 } 306 417 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 } 312 430 } 313 431 … … 382 500 public function woocommerce_payment_complete_reduce_order_stock($bool, $order_id) 383 501 { 384 $order = wc_get_order($order_id);502 $order = wc_get_order($order_id); 385 503 386 504 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); 388 506 } else { 389 507 return $bool; -
eupago-gateway-for-woocommerce/trunk/includes/class-wc-eupago-cofidispay.php
r3005079 r3025695 95 95 'type' => 'text', 96 96 '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'), 98 98 ], 99 99 'instructions' => [ … … 218 218 public function check_order_errors($order_id) 219 219 { 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; 222 222 223 223 // A loja não está em Euros … … 231 231 } 232 232 233 if (!isset($_POST[' cofidispay_vat_number']) || empty($_POST['cofidispay_vat_number'])) {233 if (!isset($_POST['nif']) || empty($_POST['nif'])) { 234 234 return __('Por favor, insira um NIF válido para prosseguir com o pagamento!', 'eupago-for-woocommerce'); 235 235 } … … 320 320 <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cofidispay-form" class="wc-cofidispay-form wc-payment-form" style="background:transparent;"> 321 321 <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 /> 324 324 </p> 325 325 <div class="clear"></div> … … 333 333 public function process_payment($order_id) 334 334 { 335 336 335 global $woocommerce; 337 336 // $order = new WC_Order($order_id); … … 339 338 340 339 $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 344 342 $order->update_meta_data('_eupago_cofidis_vat_number', $cofidispay_vat_number); 345 343 $order->save(); … … 347 345 if ($error_message = $this->check_order_errors($order_id)) { 348 346 wc_add_notice($error_message, 'error'); 349 350 347 return; 351 348 } … … 460 457 public function woocommerce_payment_complete_reduce_order_stock($bool, $order_id) 461 458 { 462 $order = wc_get_order($order_id);459 $order = wc_get_order($order_id); 463 460 464 461 if ($order->get_payment_method() == $this->id) { -
eupago-gateway-for-woocommerce/trunk/includes/class-wc-eupago-mbway.php
r3005079 r3025695 107 107 'type' => 'textarea', 108 108 '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'), 110 110 ], 111 111 'instructions' => [ -
eupago-gateway-for-woocommerce/trunk/includes/class-wc-eupago-multibanco.php
r3005079 r3025695 20 20 * @return void 21 21 */ 22 22 23 public function __construct() 23 24 { … … 27 28 $this->icon = plugins_url('assets/images/multibanco_icon.png', dirname(__FILE__)); 28 29 $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'); 30 31 31 32 // Plugin options and settings … … 50 51 add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']); 51 52 53 52 54 if (function_exists('icl_object_id') && function_exists('icl_register_string')) { 53 55 add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'register_wpml_strings']); … … 62 64 add_action('admin_notices', [$this, 'admin_error_euros']); 63 65 } 66 64 67 // Customer Emails 65 68 add_action('woocommerce_email_before_order_table', [$this, 'email_instructions'], 10, 2); … … 184 187 public function check_order_errors($order_id) 185 188 { 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; 188 191 189 192 // A loja não está em Euros … … 412 415 public function woocommerce_payment_complete_reduce_order_stock($bool, $order_id) 413 416 { 414 $order = wc_get_order($order_id);417 $order = wc_get_order($order_id); 415 418 416 419 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) ; 418 421 } else { 419 422 return $bool; 420 423 } 421 424 } 425 426 422 427 } // WC_Multibanco_Eupago 423 428 } // class_exists() -
eupago-gateway-for-woocommerce/trunk/readme.txt
r3005079 r3025695 5 5 Plugin URI: 6 6 Requires at least: 4.4 7 Tested up to: 6. 3.27 Tested up to: 6.4.2 8 8 Requires PHP: 7.0 9 Stable tag: 4. 09 Stable tag: 4.1 10 10 License: GPLv2 or later 11 11 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 43 43 44 44 == 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. 45 51 46 52 = 4.0 (30/11/2023) =
Note: See TracChangeset
for help on using the changeset viewer.