Changeset 2472496
- Timestamp:
- 02/10/2021 03:30:40 PM (5 years ago)
- Location:
- eupago-for-woocommerce
- Files:
-
- 1 deleted
- 3 edited
- 22 copied
-
tags/2.0.8.1 (copied) (copied from eupago-for-woocommerce/trunk)
-
tags/2.0.8.1/eupago-for-woocommerce.php (copied) (copied from eupago-for-woocommerce/trunk/eupago-for-woocommerce.php) (1 diff)
-
tags/2.0.8.1/images/cc_icon.jpg (copied) (copied from eupago-for-woocommerce/trunk/images/cc_icon.jpg)
-
tags/2.0.8.1/images/pagaqui_banner.png (copied) (copied from eupago-for-woocommerce/trunk/images/pagaqui_banner.png)
-
tags/2.0.8.1/images/pagaqui_icon.png (copied) (copied from eupago-for-woocommerce/trunk/images/pagaqui_icon.png)
-
tags/2.0.8.1/includes/callback.php (deleted)
-
tags/2.0.8.1/includes/class-wc-eupago-api.php (copied) (copied from eupago-for-woocommerce/trunk/includes/class-wc-eupago-api.php)
-
tags/2.0.8.1/includes/class-wc-eupago-callback.php (copied) (copied from eupago-for-woocommerce/trunk/includes/class-wc-eupago-callback.php)
-
tags/2.0.8.1/includes/class-wc-eupago-cc.php (copied) (copied from eupago-for-woocommerce/trunk/includes/class-wc-eupago-cc.php)
-
tags/2.0.8.1/includes/class-wc-eupago-mbway.php (copied) (copied from eupago-for-woocommerce/trunk/includes/class-wc-eupago-mbway.php) (15 diffs)
-
tags/2.0.8.1/includes/class-wc-eupago-multibanco.php (copied) (copied from eupago-for-woocommerce/trunk/includes/class-wc-eupago-multibanco.php)
-
tags/2.0.8.1/includes/class-wc-eupago-pagaqui.php (copied) (copied from eupago-for-woocommerce/trunk/includes/class-wc-eupago-pagaqui.php)
-
tags/2.0.8.1/includes/class-wc-eupago-paysafecard.php (copied) (copied from eupago-for-woocommerce/trunk/includes/class-wc-eupago-paysafecard.php)
-
tags/2.0.8.1/includes/class-wc-eupago-paysafecash.php (copied) (copied from eupago-for-woocommerce/trunk/includes/class-wc-eupago-paysafecash.php)
-
tags/2.0.8.1/includes/class-wc-eupago-payshop.php (copied) (copied from eupago-for-woocommerce/trunk/includes/class-wc-eupago-payshop.php)
-
tags/2.0.8.1/includes/views/html-admin-page.php (copied) (copied from eupago-for-woocommerce/trunk/includes/views/html-admin-page.php)
-
tags/2.0.8.1/includes/views/order-meta-box.php (copied) (copied from eupago-for-woocommerce/trunk/includes/views/order-meta-box.php)
-
tags/2.0.8.1/languages/eupago-for-woocommerce-pt_PT.mo (copied) (copied from eupago-for-woocommerce/trunk/languages/eupago-for-woocommerce-pt_PT.mo)
-
tags/2.0.8.1/languages/eupago-for-woocommerce-pt_PT.po (copied) (copied from eupago-for-woocommerce/trunk/languages/eupago-for-woocommerce-pt_PT.po)
-
tags/2.0.8.1/readme.txt (copied) (copied from eupago-for-woocommerce/trunk/readme.txt) (3 diffs)
-
tags/2.0.8.1/templates/emails/html-instructions.php (copied) (copied from eupago-for-woocommerce/trunk/templates/emails/html-instructions.php)
-
tags/2.0.8.1/templates/emails/plain-instructions.php (copied) (copied from eupago-for-woocommerce/trunk/templates/emails/plain-instructions.php)
-
tags/2.0.8.1/templates/payment-instructions.php (copied) (copied from eupago-for-woocommerce/trunk/templates/payment-instructions.php)
-
trunk/eupago-for-woocommerce.php (modified) (1 diff)
-
trunk/includes/class-wc-eupago-mbway.php (modified) (15 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
eupago-for-woocommerce/tags/2.0.8.1/eupago-for-woocommerce.php
r2469709 r2472496 4 4 * Plugin URI: http://www.webatual.pt 5 5 * Description: This plugin allows Portuguese costumers to pay WooCommerce orders with Multibanco, PayShop and MBWAY using the euPago gateway. 6 * Version: 2.0.8 6 * Version: 2.0.8.1 7 7 * Author: WebAtual 8 8 * Author URI: http://www.webatual.pt -
eupago-for-woocommerce/tags/2.0.8.1/includes/class-wc-eupago-mbway.php
r2469709 r2472496 1 1 <?php 2 if ( ! defined( 'ABSPATH' )) exit; // Exit if accessed directly2 if (!defined('ABSPATH')) exit; // Exit if accessed directly 3 3 4 4 /** 5 * euPago - MBWAY 6 * 7 * @since 0.1 8 */ 9 if ( !class_exists( 'WC_EuPago_MBWAY_WebAtual' ) ) { 10 class WC_EuPago_MBWAY_WebAtual extends WC_Payment_Gateway { 11 12 /** 13 * Constructor for your payment class 14 * 15 * @access public 16 * @return void 17 */ 18 public function __construct() { 5 * euPago - MBWAY 6 * 7 * @since 0.1 8 */ 9 if (!class_exists('WC_EuPago_MBWAY_WebAtual')) { 10 class WC_EuPago_MBWAY_WebAtual extends WC_Payment_Gateway 11 { 12 13 /** 14 * Constructor for your payment class 15 * 16 * @access public 17 * @return void 18 */ 19 public function __construct() 20 { 19 21 20 22 global $woocommerce; … … 46 48 47 49 // Set the API. 48 $this->client = new WC_EuPago_API( $this);50 $this->client = new WC_EuPago_API($this); 49 51 50 52 // Actions and filters 51 add_action('woocommerce_update_options_payment_gateways_' .$this->id, array($this, 'process_admin_options'));53 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); 52 54 if (function_exists('icl_object_id') && function_exists('icl_register_string')) add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'register_wpml_strings')); 53 add_action('woocommerce_thankyou_' .$this->id, array($this, 'thankyou_page'));54 add_action('woocommerce_order_details_after_order_table', array( $this, 'order_details_after_order_table' ), 20);55 add_action('woocommerce_thankyou_' . $this->id, array($this, 'thankyou_page')); 56 add_action('woocommerce_order_details_after_order_table', array($this, 'order_details_after_order_table'), 20); 55 57 56 58 add_filter('woocommerce_available_payment_gateways', array($this, 'disable_unless_portugal')); … … 66 68 // Filter to decide if payment_complete reduces stock, or not 67 69 add_filter('woocommerce_payment_complete_reduce_order_stock', array($this, 'woocommerce_payment_complete_reduce_order_stock'), 10, 2); 68 69 } 70 71 /**72 * WPML compatibility73 */74 function register_wpml_strings(){70 } 71 72 /** 73 * WPML compatibility 74 */ 75 function register_wpml_strings() 76 { 75 77 //These are already registered by WooCommerce Multilingual 76 78 /*$to_register=array('title','description',);*/ 77 79 $to_register = array(); 78 foreach($to_register as $string) { 79 icl_register_string($this->id, $this->id.'_'.$string, $this->settings[$string]); 80 } 81 } 82 83 function init_form_fields() { 80 foreach ($to_register as $string) { 81 icl_register_string($this->id, $this->id . '_' . $string, $this->settings[$string]); 82 } 83 } 84 85 function init_form_fields() 86 { 84 87 $this->form_fields = array( 85 88 'enabled' => array( 86 89 'title' => __('Enable/Disable', 'woocommerce'), 87 90 'type' => 'checkbox', 88 'label' => __( 'Enable MBWAY (using euPago)', 'eupago-for-woocommerce'),91 'label' => __('Enable MBWAY (using euPago)', 'eupago-for-woocommerce'), 89 92 'default' => 'no' 90 93 ), 91 94 'title' => array( 92 'title' => __('Title', 'woocommerce' ),95 'title' => __('Title', 'woocommerce'), 93 96 'type' => 'text', 94 97 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'), … … 96 99 ), 97 100 'description' => array( 98 'title' => __('Description', 'woocommerce' ),101 'title' => __('Description', 'woocommerce'), 99 102 'type' => 'textarea', 100 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce' ),103 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce'), 101 104 '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-for-woocommerce') 102 105 ), 103 106 'instructions' => array( 104 'title' => __( 'Instructions', 'eupago-for-woocommerce'),107 'title' => __('Instructions', 'eupago-for-woocommerce'), 105 108 'type' => 'textarea', 106 'description' => __( 'Instructions that will be added to the thank you page and email sent to customer.', 'eupago-for-woocommerce'),109 'description' => __('Instructions that will be added to the thank you page and email sent to customer.', 'eupago-for-woocommerce'), 107 110 ), 108 111 'only_portugal' => array( 109 112 'title' => __('Only for Portuguese customers?', 'eupago-for-woocommerce'), 110 113 'type' => 'checkbox', 111 'label' => __( 'Enable only for customers whose address is in Portugal', 'eupago-for-woocommerce'),114 'label' => __('Enable only for customers whose address is in Portugal', 'eupago-for-woocommerce'), 112 115 'default' => 'no' 113 116 ), … … 115 118 'title' => __('Only for orders above', 'eupago-for-woocommerce'), 116 119 'type' => 'number', 117 'description' => __( 'Enable only for orders above x € (exclusive). Leave blank (or zero) to allow for any order value.', 'eupago-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-for-woocommerce'),120 'description' => __('Enable only for orders above x € (exclusive). Leave blank (or zero) to allow for any order value.', 'eupago-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-for-woocommerce'), 118 121 'default' => '' 119 122 ), … … 121 124 'title' => __('Only for orders below', 'eupago-for-woocommerce'), 122 125 'type' => 'number', 123 'description' => __( 'Enable only for orders below x € (exclusive). Leave blank (or zero) to allow for any order value.', 'eupago-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-for-woocommerce'),126 'description' => __('Enable only for orders below x € (exclusive). Leave blank (or zero) to allow for any order value.', 'eupago-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-for-woocommerce'), 124 127 'default' => '' 125 128 ), … … 127 130 'title' => __('Reduce stock', 'eupago-for-woocommerce'), 128 131 'type' => 'select', 129 'description' => __( 'Choose when to reduce stock.', 'eupago-for-woocommerce'),132 'description' => __('Choose when to reduce stock.', 'eupago-for-woocommerce'), 130 133 'default' => '', 131 'options' => array(132 '' => __('when order is paid (requires active callback)', 'eupago-for-woocommerce'),133 'order' => __('when order is placed (before payment)', 'eupago-for-woocommerce'),134 'options' => array( 135 '' => __('when order is paid (requires active callback)', 'eupago-for-woocommerce'), 136 'order' => __('when order is placed (before payment)', 'eupago-for-woocommerce'), 134 137 ), 135 138 ), … … 137 140 } 138 141 139 public function admin_options() { 142 public function admin_options() 143 { 140 144 include 'views/html-admin-page.php'; 141 145 } 142 146 143 147 /** 144 * Icon HTML 145 */ 146 public function get_icon() { 147 $alt = (function_exists('icl_object_id') ? icl_t($this->id, $this->id.'_title', $this->title) : $this->title); 148 $icon_html = '<img src="'.esc_attr($this->icon).'" alt="'.esc_attr($alt).'" /> <a href="https://www.mbway.pt/#o-que-e" target="_blank">O que é o MBWAY?</a>'; 148 * Icon HTML 149 */ 150 public function get_icon() 151 { 152 $alt = (function_exists('icl_object_id') ? icl_t($this->id, $this->id . '_title', $this->title) : $this->title); 153 $icon_html = '<img src="' . esc_attr($this->icon) . '" alt="' . esc_attr($alt) . '" /> <a href="https://www.mbway.pt/#o-que-e" target="_blank">O que é o MBWAY?</a>'; 149 154 return apply_filters('woocommerce_gateway_icon', $icon_html, $this->id); 150 155 } 151 156 152 function check_order_errors($order_id) { 157 function check_order_errors($order_id) 158 { 153 159 $order = new WC_Order($order_id); 154 $order_total = version_compare( WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total;160 $order_total = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total; 155 161 156 162 // A loja não está em Euros 157 if ( trim(get_woocommerce_currency()) != 'EUR') {163 if (trim(get_woocommerce_currency()) != 'EUR') { 158 164 return __('Configuration error. This store currency is not Euros (€).', 'eupago-for-woocommerce'); 159 165 } 160 166 161 167 //O valor da encomenda não é aceita 162 if ( ($order_total < 1) || ($order_total >= 1000000)) {168 if (($order_total < 1) || ($order_total >= 1000000)) { 163 169 return __('It\'s not possible to use Multibanco to pay values under 1€ or above 999999€.', 'eupago-for-woocommerce'); 164 170 } … … 167 173 168 174 /** 169 * Thank You page message. 170 * 171 * @param int $order_id Order ID. 172 * 173 * @return string 174 */ 175 public function thankyou_page( $order_id ) { 175 * Thank You page message. 176 * 177 * @param int $order_id Order ID. 178 * 179 * @return string 180 */ 181 public function thankyou_page($order_id) 182 { 176 183 $order = new WC_Order($order_id); 177 $order_total = version_compare( WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total;178 $payment_method = version_compare( WC_VERSION, '3.0', '>=') ? $order->get_payment_method() : $order->payment_method;179 180 if ( $payment_method == $this->id) {181 182 wc_get_template( 'payment-instructions.php', array(184 $order_total = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total; 185 $payment_method = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_payment_method() : $order->payment_method; 186 187 if ($payment_method == $this->id) { 188 189 wc_get_template('payment-instructions.php', array( 183 190 'method' => $payment_method, 184 'payment_name' => (function_exists('icl_object_id') ? icl_t($this->id, $this->id .'_title', $this->title) : $this->title),185 'instructions' => isset( $this->instructions ) && !empty( $this->instructions) ? $this->instructions : '',191 'payment_name' => (function_exists('icl_object_id') ? icl_t($this->id, $this->id . '_title', $this->title) : $this->title), 192 'instructions' => isset($this->instructions) && !empty($this->instructions) ? $this->instructions : '', 186 193 'referencia' => get_post_meta($order_id, '_eupago_mbway_referencia', true), 187 194 'order_total' => $order_total, 188 ), 'woocommerce/eupago/', WC_EuPago::get_templates_path() ); 189 190 } 191 } 192 193 /** 194 * 195 * View Order detail payment reference. 196 */ 197 function order_details_after_order_table( $order ) { 198 if ( is_wc_endpoint_url( 'view-order' ) ) { 199 $this->thankyou_page( $order->get_id() ); 200 } 201 } 202 203 /** 204 * Email instructions 205 */ 206 function email_instructions($order, $sent_to_admin, $plain_text = false) { 207 $order_id = version_compare( WC_VERSION, '3.0', '>=' ) ? $order->get_id() : $order->id; 208 $order_total = version_compare( WC_VERSION, '3.0', '>=' ) ? $order->get_total() : $order->order_total; 209 $payment_method = version_compare( WC_VERSION, '3.0', '>=' ) ? $order->get_payment_method() : $order->payment_method; 210 211 if ($sent_to_admin || !$order->has_status( 'on-hold' ) || $this->id !== $payment_method ) { 195 ), 'woocommerce/eupago/', WC_EuPago::get_templates_path()); 196 } 197 } 198 199 /** 200 * 201 * View Order detail payment reference. 202 */ 203 function order_details_after_order_table($order) 204 { 205 if (is_wc_endpoint_url('view-order')) { 206 $this->thankyou_page($order->get_id()); 207 } 208 } 209 210 /** 211 * Email instructions 212 */ 213 function email_instructions($order, $sent_to_admin, $plain_text = false) 214 { 215 $order_id = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_id() : $order->id; 216 $order_total = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total; 217 $payment_method = version_compare(WC_VERSION, '3.0', '>=') ? $order->get_payment_method() : $order->payment_method; 218 219 if ($sent_to_admin || !$order->has_status('on-hold') || $this->id !== $payment_method) { 212 220 return; 213 221 } 214 222 215 223 if ($plain_text) { 216 wc_get_template( 'emails/plain-instructions.php', array(224 wc_get_template('emails/plain-instructions.php', array( 217 225 'method' => $payment_method, 218 'payment_name' => (function_exists('icl_object_id') ? icl_t($this->id, $this->id .'_title', $this->title) : $this->title),219 'instructions' => isset( $this->instructions ) && !empty( $this->instructions) ? $this->instructions : '',226 'payment_name' => (function_exists('icl_object_id') ? icl_t($this->id, $this->id . '_title', $this->title) : $this->title), 227 'instructions' => isset($this->instructions) && !empty($this->instructions) ? $this->instructions : '', 220 228 'referencia' => get_post_meta($order_id, '_eupago_mbway_referencia', true), 221 229 'order_total' => $order_total, 222 ), 'woocommerce/eupago/', WC_EuPago::get_templates_path() );230 ), 'woocommerce/eupago/', WC_EuPago::get_templates_path()); 223 231 } else { 224 wc_get_template( 'emails/html-instructions.php', array(232 wc_get_template('emails/html-instructions.php', array( 225 233 'method' => $payment_method, 226 'payment_name' => (function_exists('icl_object_id') ? icl_t($this->id, $this->id .'_title', $this->title) : $this->title),227 'instructions' => isset( $this->instructions ) && !empty( $this->instructions) ? $this->instructions : '',234 'payment_name' => (function_exists('icl_object_id') ? icl_t($this->id, $this->id . '_title', $this->title) : $this->title), 235 'instructions' => isset($this->instructions) && !empty($this->instructions) ? $this->instructions : '', 228 236 'referencia' => get_post_meta($order_id, '_eupago_mbway_referencia', true), 229 237 'order_total' => $order_total, 230 ), 'woocommerce/eupago/', WC_EuPago::get_templates_path() ); 231 } 232 } 233 234 function payment_fields() { 235 if ( $description = $this->get_description() ) { 236 echo wpautop( wptexturize( $description ) ); 238 ), 'woocommerce/eupago/', WC_EuPago::get_templates_path()); 239 } 240 } 241 242 function payment_fields() 243 { 244 if ($description = $this->get_description()) { 245 echo wpautop(wptexturize($description)); 237 246 } 238 247 … … 244 253 } 245 254 246 function mbway_form() { 247 $user = wp_get_current_user(); 248 if ( $user->ID ) { 249 $user_phone = get_user_meta( $user->ID, 'billing_phone', true ); 250 // $user_phone = $user_phone ? $user_phone : $user->user_phone; 251 } 255 function mbway_form() 256 { 252 257 ?> 253 <fieldset id="wc-<?php echo esc_attr( $this->id); ?>-mbway-form" class="wc-mbway-form wc-payment-form" style="background:transparent;">258 <fieldset id="wc-<?php echo esc_attr($this->id); ?>-mbway-form" class="wc-mbway-form wc-payment-form" style="background:transparent;"> 254 259 <p class="form-row form-row-wide"> 255 <label for="mbway_phone"><?php esc_html_e( 'Phone number registered on MB WAY', 'eupago-for-woocommerce'); ?></label>256 <input type="tel" id="mbway_phone" autocorrect="off" spellcheck="false" name="mbway_phone" class="input-text" aria-label="<?php _e('Phone number registered on MB WAY', 'eupago-for-woocommerce' ); ?>" placeholder="<?php _e( 'If different of billing phone', 'eupago-for-woocommerce' ); ?>" aria-placeholder="" aria-invalid="false" value="<?php echo $user_phone; ?>" />257 <span class="help-text"><small><?php _e( 'Fill in, if different from the billing phone.', 'eupago-for-woocommerce'); ?></small></span>260 <label for="mbway_phone"><?php esc_html_e('Phone number registered on MB WAY', 'eupago-for-woocommerce'); ?></label> 261 <input type="tel" id="mbway_phone" autocorrect="off" spellcheck="false" name="mbway_phone" class="input-text" aria-label="<?php _e('Phone number registered on MB WAY', 'eupago-for-woocommerce'); ?>" placeholder="<?php _e('If different of billing phone', 'eupago-for-woocommerce'); ?>" aria-placeholder="" aria-invalid="false" /> 262 <span class="help-text"><small><?php _e('Fill in, if different from the billing phone.', 'eupago-for-woocommerce'); ?></small></span> 258 263 </p> 259 264 <div class="clear"></div> … … 263 268 264 269 /** 265 * Process it 266 */ 267 function process_payment($order_id) { 270 * Process it 271 */ 272 function process_payment($order_id) 273 { 268 274 global $woocommerce; 269 275 $order = new WC_Order($order_id); 270 $order_total = version_compare( WC_VERSION, '3.0', '>=') ? $order->get_total() : $order->order_total;271 $billing_phone = version_compare( WC_VERSION, '3.0', '>=') ? $order->get_billing_phone() : $order->billing_phone;272 $mbway_phone = isset( $_POST['mbway_phone'] ) && !empty( $_POST['mbway_phone']) ? $_POST['mbway_phone'] : $billing_phone;276 $order_total = version_compare(