🔥 HOT: Changeset/ - HD Photos!

Changeset 2472496


Ignore:
Timestamp:
02/10/2021 03:30:40 PM (5 years ago)
Author:
jluisfreitas
Message:

2.0.8.1

Location:
eupago-for-woocommerce
Files:
1 deleted
3 edited
22 copied

Legend:

Unmodified
Added
Removed
  • eupago-for-woocommerce/tags/2.0.8.1/eupago-for-woocommerce.php

    r2469709 r2472496  
    44* Plugin URI: http://www.webatual.pt
    55* 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
    77* Author: WebAtual
    88* Author URI: http://www.webatual.pt
  • eupago-for-woocommerce/tags/2.0.8.1/includes/class-wc-eupago-mbway.php

    r2469709 r2472496  
    11<?php
    2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
     2if (!defined('ABSPATH')) exit; // Exit if accessed directly
    33
    44/**
    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 */
     9if (!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    {
    1921
    2022      global $woocommerce;
     
    4648
    4749      // Set the API.
    48       $this->client = new WC_EuPago_API( $this );
     50      $this->client = new WC_EuPago_API($this);
    4951
    5052      // 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'));
    5254      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);
    5557
    5658      add_filter('woocommerce_available_payment_gateways', array($this, 'disable_unless_portugal'));
     
    6668      // Filter to decide if payment_complete reduces stock, or not
    6769      add_filter('woocommerce_payment_complete_reduce_order_stock', array($this, 'woocommerce_payment_complete_reduce_order_stock'), 10, 2);
    68 
    69     }
    70 
    71     /**
    72     * WPML compatibility
    73     */
    74     function register_wpml_strings() {
     70    }
     71
     72    /**
     73     * WPML compatibility
     74     */
     75    function register_wpml_strings()
     76    {
    7577      //These are already registered by WooCommerce Multilingual
    7678      /*$to_register=array('title','description',);*/
    7779      $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    {
    8487      $this->form_fields = array(
    8588        'enabled' => array(
    8689          'title' => __('Enable/Disable', 'woocommerce'),
    8790          'type' => 'checkbox',
    88           'label' => __( 'Enable MBWAY (using euPago)', 'eupago-for-woocommerce'),
     91          'label' => __('Enable MBWAY (using euPago)', 'eupago-for-woocommerce'),
    8992          'default' => 'no'
    9093        ),
    9194        'title' => array(
    92           'title' => __('Title', 'woocommerce' ),
     95          'title' => __('Title', 'woocommerce'),
    9396          'type' => 'text',
    9497          'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'),
     
    9699        ),
    97100        'description' => array(
    98           'title' => __('Description', 'woocommerce' ),
     101          'title' => __('Description', 'woocommerce'),
    99102          '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'),
    101104          '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')
    102105        ),
    103106        'instructions' => array(
    104           'title'       => __( 'Instructions', 'eupago-for-woocommerce' ),
     107          'title'       => __('Instructions', 'eupago-for-woocommerce'),
    105108          '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'),
    107110        ),
    108111        'only_portugal' => array(
    109112          'title' => __('Only for Portuguese customers?', 'eupago-for-woocommerce'),
    110113          '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'),
    112115          'default' => 'no'
    113116        ),
     
    115118          'title' => __('Only for orders above', 'eupago-for-woocommerce'),
    116119          'type' => 'number',
    117           'description' => __( 'Enable only for orders above x &euro; (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 &euro; (inclusive). You can use this option to further limit this range.', 'eupago-for-woocommerce'),
     120          'description' => __('Enable only for orders above x &euro; (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 &euro; (inclusive). You can use this option to further limit this range.', 'eupago-for-woocommerce'),
    118121          'default' => ''
    119122        ),
     
    121124          'title' => __('Only for orders below', 'eupago-for-woocommerce'),
    122125          'type' => 'number',
    123           'description' => __( 'Enable only for orders below x &euro; (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 &euro; (inclusive). You can use this option to further limit this range.', 'eupago-for-woocommerce'),
     126          'description' => __('Enable only for orders below x &euro; (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 &euro; (inclusive). You can use this option to further limit this range.', 'eupago-for-woocommerce'),
    124127          'default' => ''
    125128        ),
     
    127130          'title' => __('Reduce stock', 'eupago-for-woocommerce'),
    128131          'type' => 'select',
    129           'description' => __( 'Choose when to reduce stock.', 'eupago-for-woocommerce'),
     132          'description' => __('Choose when to reduce stock.', 'eupago-for-woocommerce'),
    130133          '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'),
    134137          ),
    135138        ),
     
    137140    }
    138141
    139     public function admin_options() {
     142    public function admin_options()
     143    {
    140144      include 'views/html-admin-page.php';
    141145    }
    142146
    143147    /**
    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>';
    149154      return apply_filters('woocommerce_gateway_icon', $icon_html, $this->id);
    150155    }
    151156
    152     function check_order_errors($order_id) {
     157    function check_order_errors($order_id)
     158    {
    153159      $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;
    155161
    156162      // A loja não está em Euros
    157       if ( trim(get_woocommerce_currency()) != 'EUR' ) {
     163      if (trim(get_woocommerce_currency()) != 'EUR') {
    158164        return __('Configuration error. This store currency is not Euros (&euro;).', 'eupago-for-woocommerce');
    159165      }
    160166
    161167      //O valor da encomenda não é aceita
    162       if ( ($order_total < 1) || ($order_total >= 1000000) ) {
     168      if (($order_total < 1) || ($order_total >= 1000000)) {
    163169        return __('It\'s not possible to use Multibanco to pay values under 1&euro; or above 999999&euro;.', 'eupago-for-woocommerce');
    164170      }
     
    167173
    168174    /**
    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    {
    176183      $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(
    183190          '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 : '',
    186193          'referencia' => get_post_meta($order_id, '_eupago_mbway_referencia', true),
    187194          '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) {
    212220        return;
    213221      }
    214222
    215223      if ($plain_text) {
    216         wc_get_template( 'emails/plain-instructions.php', array(
     224        wc_get_template('emails/plain-instructions.php', array(
    217225          '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 : '',
    220228          'referencia' => get_post_meta($order_id, '_eupago_mbway_referencia', true),
    221229          'order_total' => $order_total,
    222         ), 'woocommerce/eupago/', WC_EuPago::get_templates_path() );
     230        ), 'woocommerce/eupago/', WC_EuPago::get_templates_path());
    223231      } else {
    224         wc_get_template( 'emails/html-instructions.php', array(
     232        wc_get_template('emails/html-instructions.php', array(
    225233          '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 : '',
    228236          'referencia' => get_post_meta($order_id, '_eupago_mbway_referencia', true),
    229237          '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));
    237246      }
    238247
     
    244253    }
    245254
    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    {
    252257      ?>
    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;">
    254259        <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>
    258263        </p>
    259264        <div class="clear"></div>
     
    263268
    264269    /**
    265     * Process it
    266     */
    267     function process_payment($order_id) {
     270     * Process it
     271     */
     272    function process_payment($order_id)
     273    {
    268274      global $woocommerce;
    269275      $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(