Plugin Directory

Changeset 2717683


Ignore:
Timestamp:
05/03/2022 05:25:08 PM (4 years ago)
Author:
akrostech
Message:

Actualizacion de version

Location:
pei-payments/trunk
Files:
24 added
7 edited

Legend:

Unmodified
Added
Removed
  • pei-payments/trunk/includes/admin/pei_payment-settings.php

    r2412696 r2717683  
    22if ( ! defined( 'ABSPATH' ) ) exit;
    33
    4 $wcppw = new pei_Payment_Webhook_Handler();
     4$wcppw = new PEI_Payment_Webhook_Handler();
    55$the_webhook = $wcppw->pei_payment_get_webhook_info();
    66$production = __('Producción', 'pei-payment-gateway');
  • pei-payments/trunk/includes/class-pei_payment-checkout-process.php

    r2412696 r2717683  
    22/**
    33 * Pei Payment Gateway process class
     4 *
     5 * @since 1.0.0
     6 * @version 2.0.0
    47 */
    58class PEI_Payment_Process {
    69    function __construct() {
    7         $this->responses = apply_filters('pei_payment_response_codes', array(
    8             '403'   => __('Error en la autenticación.', 'pei-payment-gateway'), // Missing Authentication Token
    9             '5002'  => __('El monto de la compra es inferior al monto mínimo permitido.', 'pei-payment-gateway'), // 5000.00 Colones
    10             '5007'  => __('Comercio no tiene una cuenta activa en la moneda elegida.', 'pei-payment-gateway'), // Comercio no tiene una cta activa en esta moneda
    11             'ND1'   => __('Error desconocido al intentar obtener la URL de pago de Pei.', 'pei-payment-gateway'),
    12             'ND2'   => __('Error desconocido al procesar el pago.', 'pei-payment-gateway'),
    13             'ND3'   => __('Error desconocido no identificado.', 'pei-payment-gateway')
    14         ));
    15     }   
     10        $this->responses = apply_filters( 'pei_payment_response_codes', array(
     11            '403'   => __( 'Error en la autenticación.', 'pei-payment-gateway' ), // Missing Authentication Token
     12            '404'   => __( 'No se encuentra el recurso solicitado.', 'pei-payment-gateway' ),
     13            '503'   => __( 'El servicio no está disponible.', 'pei-payment-gateway' ),
     14            '5002'  => __( 'El monto de la compra es inferior al monto mínimo permitido.', 'pei-payment-gateway' ), // 5000.00 Colones
     15            '5007'  => __( 'Comercio no tiene una cuenta activa en la moneda elegida.', 'pei-payment-gateway' ), // Comercio no tiene una cta activa en esta moneda
     16            'ND1'   => __( 'Error desconocido al intentar obtener la URL de pago de Pei.', 'pei-payment-gateway' ),
     17            'ND2'   => __( 'Error desconocido al procesar el pago.', 'pei-payment-gateway' ),
     18            'ND3'   => __( 'Error desconocido no identificado.', 'pei-payment-gateway' )
     19        ) );
     20
     21        $this->process_responses = apply_filters( 'pei_processing_response_codes', array(
     22            '000'   => __( 'Pago exitoso', 'pei-payment-gateway' ),
     23            '010'   => __( 'Autenticación exitosa', 'pei-payment-gateway' ),
     24            '011'   => __( 'Error en la autenticación', 'pei-payment-gateway' ),
     25            '012'   => __( 'Error al procesar el pago', 'pei-payment-gateway' ),
     26            '013'   => __( 'Error en la autenticación', 'pei-payment-gateway' ),
     27            '101'   => __( 'Error de tarjeta', 'pei-payment-gateway' ),
     28            '111'   => __( 'Error de tarjeta', 'pei-payment-gateway' ),
     29            '121'   => 'Card Error',
     30            '151'   => __( 'Error al procesar el pago', 'pei-payment-gateway' ),
     31            '201'   => 'Card Error',
     32            '251'   => 'Payment Error',
     33            '500'   => 'Not Finished',
     34            '501'   => 'Error',
     35            '502'   => 'Error',
     36            '503'   => 'Error',
     37            '505'   => 'Error checking',
     38            '550'   => 'Pending Execution',
     39            '551'   => 'Execution cancelled',
     40            '552'   => 'Execution expired',
     41            '553'   => 'Execution denied',
     42            '701'   => 'Card Error',
     43            '702'   => 'Card Error',
     44            '703'   => 'Card Error',
     45            '731'   => 'Blocked',
     46            '751'   => 'Blocked',
     47            '752'   => 'Blocked',
     48            '756'   => 'Blocked',
     49            '757'   => 'Blocked',
     50            '771'   => 'Blocked',
     51            '776'   => 'Blocked',
     52            '940'   => 'COF Error',
     53            '950'   => 'Error',
     54            '960'   => 'Error',
     55            '970'   => 'Error',
     56            '999'   => 'Error'
     57        ) );
     58
     59        $this->success_codes = apply_filters( 'pei_response_success_codes', array( '000', '010' ) );
     60
     61        $this->error_codes = apply_filters( 'pei_response_error_codes', array() );
     62    }
    1663}
    1764
  • pei-payments/trunk/includes/class-pei_payment-ws.php

    r2412696 r2717683  
    1212    }
    1313
    14     public function pc_get_url($order_id = 0, $params = array()) {
     14    /**
     15     * Get payment URL
     16     *
     17     * @since 1.0.0
     18     * @version 2.0.0
     19     */
     20    public function pc_get_url( $order_id = 0, $params = array() ) {
     21        $status = 'ND1';
    1522        $response = array(
    1623            'response' => false
     
    3340        ));
    3441
    35         if (!is_null($response_result = $response_checkout['result'])) {
     42        $response_result = isset( $response_checkout['result'] ) ? $response_checkout['result'] : null;
     43        $response_error = isset( $response_checkout['error'] ) ? $response_checkout['error'] : null;
     44
     45        if ( ! is_null( $response_result ) ) {
    3646            $response = array(
    3747                'response' => true,
     
    4050                'is_expired' => (strtotime($response_result['Expiration']) <= strtotime(date_i18n('Y-m-d h:i:s'))) ? true : false
    4151            );
    42         } elseif (isset($response_checkout['error']) && !is_null($response_checkout['error'])) {
     52        } elseif ( ! is_null( $response_error ) ) {
    4353            $response_error = $response_checkout['error'];
    4454            $status = isset( $response_error['status'] ) ? $response_error['status'] : $response_checkout['response_code'];
    4555            $message = ( isset( PEI_PROC()->responses[$status] ) ) ? PEI_PROC()->responses[$status] : PEI_PROC()->responses['ND1'] ;
    46             $response['message'] = sprintf('<strong>%s %d:</strong> %s', __('Error', 'pei-payment-gateway'), $status, esc_attr($message));
     56            $response['message'] = sprintf('<strong>%s %s:</strong> %s', __('Error', 'pei-payment-gateway'), $status, esc_attr($message));
    4757        } else {
    4858            $response['response_checkout'] = json_encode( $response_checkout );
    49             $response['message'] = sprintf('<strong>%s %d:</strong> %s', __('Error', 'pei-payment-gateway'), $status, esc_attr(PEI_PROC()->responses['ND3']));
     59            $response['message'] = sprintf('<strong>%s %s:</strong> %s', __('Error', 'pei-payment-gateway'), $status, esc_attr( PEI_PROC()->responses[ $status ] ) );
    5060        }
    5161
  • pei-payments/trunk/includes/class-pei_payment.php

    r2412696 r2717683  
    44/**
    55 * Class Payment init
     6 *
     7 * @since 1.0.0
     8 * @version 2.0.0
    69 */
    7 if (class_exists('WC_Payment_Gateway')) {
    8     include PEI_PAYMENT_PLUGIN_PATH . '/includes/class-pei_payment-checkout-process.php';
    9 
    10     class WC_PEI_Payment_Gateway extends WC_Payment_Gateway {
    11         public function __construct() {
    12             $this->logger = new WC_Logger();
    13             $this->id = PEI_PAYMENT_ID;
    14             $this->method_title = __('Pagos con Pei', 'pei-payment-gateway');
    15             $this->method_description = sprintf('%s Versión actual: %s', __('Configuraciones para Pagos con pei.', 'pei-payment-gateway'), PEI_PAYMENT_VERSION);
    16 
    17             // Bool. Can be set to true if you want payment fields to show on the checkout if doing a direct integration, which we are doing in this case
    18             $this->has_fields = true;
    19 
    20             // This defines your settings which are loaded with init_settings()
    21             $this->init_form_fields();
    22             $this->init_settings();
    23 
    24             // Turn these settings into variables
    25             foreach ( $this->settings as $setting_key => $value ) {
    26                 $this->$setting_key = $value;
    27             }
    28 
    29             $this->is_sandbox = ($this->environment == 'sand') ? true : false;
    30 
    31             // Save settings
    32             add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
     10class WC_PEI_Payment_Gateway extends WC_Payment_Gateway {
     11    public function __construct() {
     12        $this->logger = new WC_Logger();
     13        $this->id = PEI_PAYMENT_ID;
     14        $this->method_title = __('Pagos con Pei', 'pei-payment-gateway');
     15        $this->method_description = sprintf('%s Versión actual: %s', __('Configuraciones para Pagos con pei.', 'pei-payment-gateway'), PEI_PAYMENT_VERSION);
     16
     17        // Bool. Can be set to true if you want payment fields to show on the checkout if doing a direct integration, which we are doing in this case
     18        $this->has_fields = true;
     19
     20        // This defines your settings which are loaded with init_settings()
     21        $this->init_form_fields();
     22        $this->init_settings();
     23
     24        // Turn these settings into variables
     25        foreach ( $this->settings as $setting_key => $value ) {
     26            $this->$setting_key = $value;
     27        }
     28
     29        $this->is_sandbox = ($this->environment == 'sand') ? true : false;
     30
     31        // Save settings
     32        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
     33       
     34        // Actions
     35        add_action( 'wp_head', array($this, 'pei_payment_styles') );
     36        add_filter( 'woocommerce_get_order_item_totals', array( $this, 'pei_payment_wc_get_order_item_totals' ), 10, 3 );
     37        // add_filter( 'woocommerce_order_is_pending_statuses', array( $this, 'pei_payment_wc_order_is_pending_statuses' ) );
     38
     39        // Add message to Thankyou page
     40        add_filter( 'woocommerce_thankyou_order_received_text', array( $this, 'pei_payment_wc_thankyou_order_received_text' ), 10, 2 );
     41    }
     42
     43    public function init_form_fields() {
     44        $this->form_fields = require(PEI_PAYMENT_PLUGIN_PATH . '/includes/admin/pei_payment-settings.php');
     45    }
     46
     47    /**
     48     * Generate payment fields
     49     */
     50    public function payment_fields() {
     51        if ( $this->description ) {
     52            echo wpautop( wptexturize( $this->description ) );
     53        }
     54    }
     55
     56    /**
     57     * Process payment from the Checkout
     58     */
     59    public function process_payment( $order_id ) {
     60        $order = wc_get_order($order_id);
     61        $status = 'pending';
     62
     63
     64        /** Get Pei URL **/
     65        $formatted_name = ( !empty( trim( $order->get_formatted_shipping_full_name() ) ) ) ? $order->get_formatted_shipping_full_name() : $order->get_formatted_billing_full_name();
     66        $params = array(
     67            'description' => apply_filters('pei_payment_order_description', sprintf(__('Compra de %s en %s', 'pei-payment-gateway'), trim($formatted_name), get_bloginfo('name')), $order),
     68            'amount' => (int) $order->get_total(),
     69            'callback' => $order->get_checkout_order_received_url()
     70        );
     71        $response = PEI_CONN()->pc_get_url($order->get_id(), $params);
     72
     73        if ( $response['response'] ) {
     74            $order->add_order_note( sprintf(__('Checkout iniciado: %s', 'pei-payment-gateway'), $this->method_title) );
     75            wc_reduce_stock_levels($order->get_id());
     76            // Remove cart
     77            WC()->cart->empty_cart();
     78
     79            $response = array(
     80                'result'    => 'success',
     81                'redirect'  => esc_url($response['pei_url'])
     82            );
     83        } else {
     84            $this->pei_log('Response Error: ' . json_encode($response));
     85
     86            if ( isset($response['message']) ) {
     87                $order->add_order_note( $response['message'], 1 );
     88                wc_add_notice( $response['message'], 'error' );
     89            }
     90
     91            if ( isset($response['response_checkout']) ) {
     92                $this->pei_log('response_checkout: ' . $response['response_checkout']);
     93                $order->add_order_note( $response['response_checkout'] );
     94            }
    3395           
    34             // Actions
    35             add_action( 'wp_head', array($this, 'pei_payment_styles') );
    36             add_filter( 'woocommerce_get_order_item_totals', array( $this, 'pei_payment_wc_get_order_item_totals' ), 10, 3 );
    37             add_filter( 'woocommerce_order_is_pending_statuses', array( $this, 'pei_payment_wc_order_is_pending_statuses' ) );
    38 
    39             // Add message to Thankyou page
    40             add_filter( 'woocommerce_thankyou_order_received_text', array( $this, 'pei_payment_wc_thankyou_order_received_text' ), 10, 2 );
    41         }
    42 
    43         public function init_form_fields() {
    44             $this->form_fields = require(PEI_PAYMENT_PLUGIN_PATH . '/includes/admin/pei_payment-settings.php');
    45         }
    46 
    47         /**
    48          * Generate payment fields
    49          */
    50         public function payment_fields() {
    51             if ( $this->description ) {
    52                 echo wpautop( wptexturize( $this->description ) );
    53             }
    54         }
    55 
    56         /**
    57          * Process payment from the Checkout
    58          */
    59         public function process_payment( $order_id ) {
    60             $order = wc_get_order($order_id);
    61             $status = 'pending';
    62 
    63 
    64             /** Get Pei URL **/
    65             $formatted_name = ( !empty( trim( $order->get_formatted_shipping_full_name() ) ) ) ? $order->get_formatted_shipping_full_name() : $order->get_formatted_billing_full_name();
    66             $params = array(
    67                 'description' => apply_filters('pei_payment_order_description', sprintf(__('Compra de %s en %s', 'pei-payment-gateway'), trim($formatted_name), get_bloginfo('name')), $order),
    68                 'amount' => (int) $order->get_total(),
    69                 'callback' => $order->get_checkout_order_received_url()
     96            $response = array(
     97                'result'    => 'failure',
    7098            );
    71             $response = PEI_CONN()->pc_get_url($order->get_id(), $params);
    72 
    73             if ( $response['response'] ) {
    74                 $order->add_order_note( sprintf(__('Checkout iniciado: %s', 'pei-payment-gateway'), $this->method_title) );
    75                 wc_reduce_stock_levels($order->get_id());
    76                 // Remove cart
    77                 WC()->cart->empty_cart();
    78 
    79                 $response = array(
    80                     'result'    => 'success',
    81                     'redirect'  => esc_url($response['pei_url'])
     99        }
     100
     101        // Set order status
     102        $order->update_status( $status );
     103
     104        return $response;
     105    }
     106
     107    /**
     108     * Styles on Checkout order received
     109     */
     110    public function pei_payment_styles() {
     111        if ( is_order_received_page() ) {
     112            ?>
     113            <style type="text/css">
     114                /** Thankyou page **/
     115                .pei-message-wrapper {
     116                    display: block;
     117                    padding: 15px;
     118                }
     119
     120                .pei-message-wrapper p {
     121                    margin: 0;
     122                    padding: 0;
     123                }
     124
     125                .pei-pending {
     126                    background: #fff3cd;
     127                    border: 2px solid #ffeeba;
     128                    color: #856404;
     129                }
     130
     131                .pei-processing {
     132                    background-color: #d4edda;
     133                    border: 2px solid #c3e6cb;
     134                    color: #155724;
     135                }
     136            </style>
     137            <?php
     138        }
     139    }
     140
     141    /**
     142     * Show transaction number to order items totals
     143     * Validate get_payment_method to only shows when it is requiered
     144     */
     145    public function pei_payment_wc_get_order_item_totals( $total_rows, $order, $tax_display ) {
     146        $transaction_id = $order->get_transaction_id();
     147
     148        if ( $order->get_payment_method() != $this->id )
     149            return $total_rows;
     150
     151        if ( !empty($transaction_id) ) {
     152            foreach ($total_rows as $key => $row) {
     153                $new_rows[$key] = $row;
     154                if ($key == 'payment_method') {
     155                    $new_rows[$this->id] = array(
     156                        'label' => apply_filters('pei_payment_transaction_id_label', __('Transacción:', 'pei-payment-gateway')),
     157                        'value' => $transaction_id
     158                    );
     159                }
     160            }
     161            $total_rows = $new_rows;
     162        }
     163
     164        return $total_rows;
     165    }
     166
     167    /**
     168     * Thankyou page response
     169     */
     170    public function pei_payment_wc_thankyou_order_received_text( $text, $order ) {
     171        if ( $order->get_payment_method() != $this->id )
     172            return $text;
     173
     174        if ( $order->has_status( 'pending' ) ) {
     175            ob_start();
     176            ?>
     177            <span class="pei-message-wrapper pei-pending"><?= __('La respuesta del pago de su orden se mantiene pendiente. Le notificaremos cuando el proceso sea completado.', 'pei-payment-gateway') ?></span>
     178            <?php
     179            $text = ob_get_clean();
     180        }
     181
     182        if ( $order->has_status( 'processing' ) ) {
     183            ob_start();
     184            ?>
     185            <span class="pei-message-wrapper pei-processing"><?= __('Su pago usando Pei ha sido recibido. Gracias.', 'pei-payment-gateway') ?></span>
     186            <?php
     187            $text = ob_get_clean();
     188        }
     189
     190        return $text;
     191    }
     192
     193    /**
     194     * Save array of transaction to DB
     195     */
     196    public function pei_payment_save_to_db( $data = array() ) {
     197        global $wpdb;
     198        $return = array(
     199            'response' => false
     200        );
     201       
     202        try {
     203            /* BEGIN Insert into database */
     204            $table_transactions = $wpdb->prefix . 'pei_transactions';
     205            $data = array(
     206                'user_id' => isset($data['user_id']) ? $data['user_id'] : get_current_user_id(),
     207                'amount' => isset($data['amount']) ? $data['amount'] : '',
     208                'order_id' => isset($data['order_id']) ? $data['order_id'] : '',
     209                'authcode' => isset($data['authcode']) ? $data['authcode'] : '',
     210                'transactionid' => isset($data['transactionid']) ? $data['transactionid'] : '',
     211                'error' => isset($data['error']) ? $data['error'] : '',
     212                'transaction_date' => date_i18n('Y-m-d H:i:s'),
     213                'status' => isset($data['status']) ? $data['status'] : '',
     214                'payment_method' => 'pei_payment',
     215            );
     216            $inserted_id = $wpdb->insert($table_transactions, $data);
     217
     218            if (!$inserted_id) {
     219                throw new Exception(__('Algo salió mal guardando la transacción en la tabla de control.', 'pei-payment-gateway'));
     220            } else {
     221                $return = array(
     222                    'response' => true,
     223                    'message' => __('Transacción guardada en la tabla de control.', 'pei-payment-gateway')
    82224                );
    83             } else {
    84                 $this->pei_log('Response Error: ' . json_encode($response));
    85 
    86                 if ( isset($response['message']) ) {
    87                     $order->add_order_note( $response['message'], 1 );
    88                     wc_add_notice( $response['message'], 'error' );
    89                 }
    90 
    91                 if ( isset($response['response_checkout']) ) {
    92                     $this->pei_log('response_checkout: ' . $response['response_checkout']);
    93                     $order->add_order_note( $response['response_checkout'] );
    94                 }
    95                
    96                 $response = array(
    97                     'result'    => 'failure',
    98                 );
    99             }
    100 
    101             // Set order status
    102             $order->update_status( $status );
    103 
    104             return $response;
    105         }
    106 
    107         /**
    108          * Styles on Checkout order received
    109          */
    110         public function pei_payment_styles() {
    111             if ( is_order_received_page() ) {
    112                 ?>
    113                 <style type="text/css">
    114                     /** Thankyou page **/
    115                     .pei-message-wrapper {
    116                         display: block;
    117                         padding: 15px;
    118                     }
    119 
    120                     .pei-message-wrapper p {
    121                         margin: 0;
    122                         padding: 0;
    123                     }
    124 
    125                     .pei-pending {
    126                         background: #fff3cd;
    127                         border: 2px solid #ffeeba;
    128                         color: #856404;
    129                     }
    130 
    131                     .pei-processing {
    132                         background-color: #d4edda;
    133                         border: 2px solid #c3e6cb;
    134                         color: #155724;
    135                     }
    136                 </style>
    137                 <?php
    138             }
    139         }
    140 
    141         /**
    142          * Show transaction number to order items totals
    143          * Validate get_payment_method to only shows when it is requiered
    144          */
    145         public function pei_payment_wc_get_order_item_totals( $total_rows, $order, $tax_display ) {
    146             $transaction_id = $order->get_transaction_id();
    147 
    148             if ( $order->get_payment_method() != $this->id )
    149                 return $total_rows;
    150 
    151             if ( !empty($transaction_id) ) {
    152                 foreach ($total_rows as $key => $row) {
    153                     $new_rows[$key] = $row;
    154                     if ($key == 'payment_method') {
    155                         $new_rows[$this->id] = array(
    156                             'label' => apply_filters('pei_payment_transaction_id_label', __('Transacción:', 'pei-payment-gateway')),
    157                             'value' => $transaction_id
    158                         );
    159                     }
    160                 }
    161                 $total_rows = $new_rows;
    162             }
    163 
    164             return $total_rows;
    165         }
    166 
    167         /**
    168          * Thankyou page response
    169          */
    170         public function pei_payment_wc_thankyou_order_received_text( $text, $order ) {
    171             if ( $order->get_payment_method() != $this->id )
    172                 return $text;
    173 
    174             if ( $order->has_status( 'pending' ) ) {
    175                 ob_start();
    176                 ?>
    177                 <span class="pei-message-wrapper pei-pending"><?= __('La respuesta del pago de su orden se mantiene pendiente. Le notificaremos cuando el proceso sea completado.', 'pei-payment-gateway') ?></span>
    178                 <?php
    179                 $text = ob_get_clean();
    180             }
    181 
    182             if ( $order->has_status( 'processing' ) ) {
    183                 ob_start();
    184                 ?>
    185                 <span class="pei-message-wrapper pei-processing"><?= __('Su pago usando Pei ha sido recibido. Gracias.', 'pei-payment-gateway') ?></span>
    186                 <?php
    187                 $text = ob_get_clean();
    188             }
    189 
    190             return $text;
    191         }
    192 
    193         /**
    194          * Save array of transaction to DB
    195          */
    196         public function pei_payment_save_to_db( $data = array() ) {
    197             global $wpdb;
    198             $return = array(
    199                 'response' => false
    200             );
    201            
    202             try {
    203                 /* BEGIN Insert into database */
    204                 $table_transactions = $wpdb->prefix . 'pei_transactions';
    205                 $data = array(
    206                     'user_id' => isset($data['user_id']) ? $data['user_id'] : get_current_user_id(),
    207                     'amount' => isset($data['amount']) ? $data['amount'] : '',
    208                     'order_id' => isset($data['order_id']) ? $data['order_id'] : '',
    209                     'authcode' => isset($data['authcode']) ? $data['authcode'] : '',
    210                     'transactionid' => isset($data['transactionid']) ? $data['transactionid'] : '',
    211                     'error' => isset($data['error']) ? $data['error'] : '',
    212                     'transaction_date' => date_i18n('Y-m-d H:i:s'),
    213                     'status' => isset($data['status']) ? $data['status'] : ''
    214                 );
    215                 $inserted_id = $wpdb->insert($table_transactions, $data);
    216 
    217                 if (!$inserted_id) {
    218                     throw new Exception(__('Algo salió mal guardando la transacción en la tabla de control.', 'pei-payment-gateway'));
    219                 } else {
    220                     $return = array(
    221                         'response' => true,
    222                         'message' => __('Transacción guardada en la tabla de control.', 'pei-payment-gateway')
    223                     );
    224                 }
    225                 $wpdb->flush();
    226                 /* END Insert into database */
    227             } catch(Exception $e) {
    228                 $error_message = $e->getMessage();
    229                 $return['message'] = $error_message;
    230                 $this->pei_log($error_message);
    231             }
    232 
    233             return $return;
    234         }
    235 
    236         /**
    237          * Logger
    238          */
    239         public function pei_log( $message ) {
    240             $this->logger->add( $this->id, $message . "\n" );
    241         }
     225            }
     226            $wpdb->flush();
     227            /* END Insert into database */
     228        } catch(Exception $e) {
     229            $error_message = $e->getMessage();
     230            $return['message'] = $error_message;
     231            $this->pei_log($error_message);
     232        }
     233
     234        return $return;
     235    }
     236
     237    /**
     238     * Logger
     239     */
     240    public function pei_log( $message ) {
     241        $this->logger->add( $this->id, $message . "\n" );
    242242    }
    243243}
     
    250250function pei_payment_override_wc_stock_management() {
    251251    $wcppg = new WC_PEI_Payment_Gateway();
    252     if ( $wcppg->pei_hold_order > 0 ) {
     252    if ( isset( $wcppg->pei_hold_order ) && $wcppg->pei_hold_order > 0 ) {
    253253        update_option( 'woocommerce_hold_stock_minutes', $wcppg->pei_hold_order );
    254254        update_option( 'woocommerce_manage_stock', 'yes' );
  • pei-payments/trunk/languages/pei-payment-gateway.pot

    r2412696 r2717683  
    1 # Copyright (C) 2020 WC Pei Payment Gateway
    2 # This file is distributed under the same license as the WC Pei Payment Gateway package.
     1# Copyright (C) 2022 Gente mas Gente, S.A.
     2# This file is distributed under the GPLv3.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: WC Pei Payment Gateway\n"
     5"Project-Id-Version: Pago con pei 2.0.0_Betav3\n"
     6"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/pei-payments\n"
     7"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     8"Language-Team: LANGUAGE <LL@li.org>\n"
    69"MIME-Version: 1.0\n"
    710"Content-Type: text/plain; charset=UTF-8\n"
    811"Content-Transfer-Encoding: 8bit\n"
    9 "X-Poedit-Basepath: ..\n"
    10 "X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;_n_noop:1,2;_nx:1,2,4c;_nx_noop:1,2,3c;_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
    11 "X-Poedit-SearchPath-0: .\n"
    12 "X-Poedit-SearchPathExcluded-0: *.js\n"
    13 "X-Poedit-SourceCharset: UTF-8\n"
    14 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
    15 
     12"POT-Creation-Date: 2022-04-05T05:12:41+00:00\n"
     13"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
     14"X-Generator: WP-CLI 2.5.0\n"
     15"X-Domain: pei-payment-gateway\n"
     16
     17#. Plugin Name of the plugin
     18msgid "Pago con pei"
     19msgstr ""
     20
     21#. Plugin URI of the plugin
     22msgid "https://www.go-pei.com/busines/woocommerce/"
     23msgstr ""
     24
     25#. Description of the plugin
     26msgid "Acepta pagos SINPE desde cualquier cuenta y sin compartir información innecesaria o privada. Visualiza reportes y sigue el paso de todos los pagos realizados por el botón de pago pei en tu sitio web."
     27msgstr ""
     28
     29#. Author of the plugin
     30msgid "Gente mas Gente, S.A."
     31msgstr ""
     32
     33#. Author URI of the plugin
     34msgid "https://www.grupogente.com/"
     35msgstr ""
     36
     37#: includes/admin/pei_cc_payment-settings.php:5
    1638#: includes/admin/pei_payment-settings.php:6
    1739msgid "Producción"
    1840msgstr ""
    1941
     42#: includes/admin/pei_cc_payment-settings.php:6
    2043#: includes/admin/pei_payment-settings.php:7
    2144msgid "Sandbox"
    2245msgstr ""
    2346
     47#: includes/admin/pei_cc_payment-settings.php:7
     48msgid "Código/BusinessId"
     49msgstr ""
     50
     51#: includes/admin/pei_cc_payment-settings.php:8
     52msgid "API Key"
     53msgstr ""
     54
     55#: includes/admin/pei_cc_payment-settings.php:13
    2456#: includes/admin/pei_payment-settings.php:11
    2557msgid "Habilitar / Deshabilitar"
    2658msgstr ""
    2759
     60#: includes/admin/pei_cc_payment-settings.php:15
    2861#: includes/admin/pei_payment-settings.php:13
    2962msgid "Habilitar pasarela de pagos"
    3063msgstr ""
    3164
     65#: includes/admin/pei_cc_payment-settings.php:19
    3266#: includes/admin/pei_payment-settings.php:17
    3367msgid "Título"
    3468msgstr ""
    3569
     70#: includes/admin/pei_cc_payment-settings.php:21
    3671#: includes/admin/pei_payment-settings.php:19
    3772msgid "Título de la pasarela a mostrar durando el proceso de finalización de pago."
    3873msgstr ""
    3974
    40 #: includes/admin/pei_payment-settings.php:20
    41 msgid "Pagar con Pei"
    42 msgstr ""
    43 
     75#: includes/admin/pei_cc_payment-settings.php:22
     76msgid "Pagar con tarjeta crédito/débito (Multimoney)"
     77msgstr ""
     78
     79#: includes/admin/pei_cc_payment-settings.php:25
    4480#: includes/admin/pei_payment-settings.php:23
    4581msgid "Descripción"
    4682msgstr ""
    4783
     84#: includes/admin/pei_cc_payment-settings.php:27
    4885#: includes/admin/pei_payment-settings.php:25
    4986msgid "Descripción del método de pago a mostrar durante el proceso de finalización de pago."
    5087msgstr ""
    5188
     89#: includes/admin/pei_cc_payment-settings.php:28
     90msgid "Pague seguro usando su tarjeta de Crédito o Débito."
     91msgstr ""
     92
     93#: includes/admin/pei_cc_payment-settings.php:31
     94#: includes/admin/pei_payment-settings.php:34
     95msgid "Credenciales del API"
     96msgstr ""
     97
     98#: includes/admin/pei_cc_payment-settings.php:33
     99msgid "Ingrese las credenciales del API de Pei para procesar los pagos."
     100msgstr ""
     101
     102#: includes/admin/pei_cc_payment-settings.php:36
     103#: includes/admin/pei_payment-settings.php:39
     104msgid "Ambiente"
     105msgstr ""
     106
     107#: includes/admin/pei_cc_payment-settings.php:43
     108#: includes/admin/pei_payment-settings.php:46
     109msgid "Elija el ambiente a utilizar para procesar el pago."
     110msgstr ""
     111
     112#: includes/admin/pei_cc_payment-settings.php:48
     113#: includes/admin/pei_cc_payment-settings.php:53
     114msgid "Ingrese el %s proporcionado por Pei."
     115msgstr ""
     116
     117#: includes/admin/pei_payment-settings.php:20
     118msgid "Pagar con pei"
     119msgstr ""
     120
    52121#: includes/admin/pei_payment-settings.php:26
    53 msgid "Usando tus cuentas IBAN registradas en pei"
     122msgid "Usando sus cuentas IBAN registradas en pei."
    54123msgstr ""
    55124
     
    58127msgstr ""
    59128
    60 #: includes/admin/pei_payment-settings.php:34
    61 msgid "Credenciales del API"
    62 msgstr ""
    63 
    64129#: includes/admin/pei_payment-settings.php:36
    65 msgid "Ingrese las credenciales del API de Pei para procesar los pagos."
    66 msgstr ""
    67 
    68 #: includes/admin/pei_payment-settings.php:39
    69 msgid "Ambiente"
    70 msgstr ""
    71 
    72 #: includes/admin/pei_payment-settings.php:46
    73 msgid "Elija el ambiente a utilizar para procesar el pago."
    74 msgstr ""
    75 
    76 #: includes/admin/pei_payment-settings.php:49, includes/admin/pei_payment-settings.php:65
     130msgid "Ingrese las credenciales del API de pei para procesar los pagos."
     131msgstr ""
     132
     133#: includes/admin/pei_payment-settings.php:49
     134#: includes/admin/pei_payment-settings.php:65
    77135msgid "URL del API en (%s)"
    78136msgstr ""
    79137
    80 #: includes/admin/pei_payment-settings.php:51, includes/admin/pei_payment-settings.php:67
    81 msgid "URL para conectar con el API de Pei en %s."
    82 msgstr ""
    83 
    84 #: includes/admin/pei_payment-settings.php:55, includes/admin/pei_payment-settings.php:71
     138#: includes/admin/pei_payment-settings.php:51
     139#: includes/admin/pei_payment-settings.php:67
     140msgid "URL para conectar con el API de pei en %s."
     141msgstr ""
     142
     143#: includes/admin/pei_payment-settings.php:55
     144#: includes/admin/pei_payment-settings.php:71
    85145msgid "BusinessId (%s)"
    86146msgstr ""
    87147
    88 #: includes/admin/pei_payment-settings.php:57, includes/admin/pei_payment-settings.php:73
    89 msgid "Ingrese el BusinessId para %s proporcionado por Pei."
    90 msgstr ""
    91 
    92 #: includes/admin/pei_payment-settings.php:60, includes/admin/pei_payment-settings.php:76
     148#: includes/admin/pei_payment-settings.php:57
     149#: includes/admin/pei_payment-settings.php:73
     150msgid "Ingrese el BusinessId para %s proporcionado por pei."
     151msgstr ""
     152
     153#: includes/admin/pei_payment-settings.php:60
     154#: includes/admin/pei_payment-settings.php:76
    93155msgid "API Key (%s)"
    94156msgstr ""
    95157
    96 #: includes/admin/pei_payment-settings.php:62, includes/admin/pei_payment-settings.php:78
    97 msgid "Ingrese el API Key para %s proporcionado por Pei.."
     158#: includes/admin/pei_payment-settings.php:62
     159#: includes/admin/pei_payment-settings.php:78
     160msgid "Ingrese el API Key para %s proporcionado por pei.."
    98161msgstr ""
    99162
     
    103166
    104167#: includes/admin/pei_payment-settings.php:83
    105 msgid "Administre el estado de las órdenes basado en la respuesta de Pei."
     168msgid "Administre el estado de las órdenes basado en la respuesta de pei."
    106169msgstr ""
    107170
     
    114177msgstr ""
    115178
    116 #: includes/class-pei_payment-checkout-process.php:8
     179#: includes/class-pei_cc_payment-endpoint.php:98
     180msgid "Intentar pagar nuevamente"
     181msgstr ""
     182
     183#: includes/class-pei_cc_payment-endpoint.php:115
     184#: includes/class-pei_payment-webhook.php:132
     185msgid "Su pago fue rechazado y su orden ha fallado."
     186msgstr ""
     187
     188#: includes/class-pei_cc_payment-endpoint.php:116
     189#: includes/class-pei_cc_payment-endpoint.php:124
     190#: includes/class-pei_payment-webhook.php:127
     191msgid "Referencia del banco"
     192msgstr ""
     193
     194#: includes/class-pei_cc_payment-endpoint.php:117
     195msgid "Código de error"
     196msgstr ""
     197
     198#: includes/class-pei_cc_payment-endpoint.php:121
     199#: includes/class-pei_payment-webhook.php:125
     200msgid "Su pago ha sido aceptado y su orden se encuentra en proceso."
     201msgstr ""
     202
     203#: includes/class-pei_cc_payment-endpoint.php:123
     204msgid "Código de estado"
     205msgstr ""
     206
     207#: includes/class-pei_cc_payment-endpoint.php:128
     208msgid "Ver el detalle de orden"
     209msgstr ""
     210
     211#: includes/class-pei_cc_payment-endpoint.php:148
     212msgid "Error al procesar su pago. Intente nuevamente."
     213msgstr ""
     214
     215#: includes/class-pei_cc_payment-endpoint.php:166
     216msgid "Ocurrió algún problema al procesar su pago."
     217msgstr ""
     218
     219#: includes/class-pei_cc_payment-ws.php:69
     220#: includes/class-pei_cc_payment-ws.php:72
     221#: includes/class-pei_payment-ws.php:56
     222#: includes/class-pei_payment-ws.php:59
     223msgid "Error"
     224msgstr ""
     225
     226#: includes/class-pei_cc_payment.php:11
     227msgid "Pagos con tarjeta crédito/débito vía Multimoney"
     228msgstr ""
     229
     230#: includes/class-pei_cc_payment.php:12
     231msgid "Configuraciones para Pasarela de pagos Pei para aceptar pagos con tarjeta."
     232msgstr ""
     233
     234#: includes/class-pei_cc_payment.php:79
     235#: includes/class-pei_payment.php:67
     236msgid "Compra de %s en %s"
     237msgstr ""
     238
     239#: includes/class-pei_cc_payment.php:94
     240#: includes/class-pei_payment.php:74
     241msgid "Checkout iniciado: %s"
     242msgstr ""
     243
     244#: includes/class-pei_cc_payment.php:145
     245#: includes/class-pei_payment.php:156
     246msgid "Transacción:"
     247msgstr ""
     248
     249#: includes/class-pei_cc_payment.php:182
     250#: includes/class-pei_payment.php:219
     251msgid "Algo salió mal guardando la transacción en la tabla de control."
     252msgstr ""
     253
     254#: includes/class-pei_cc_payment.php:186
     255#: includes/class-pei_payment.php:223
     256msgid "Transacción guardada en la tabla de control."
     257msgstr ""
     258
     259#: includes/class-pei_payment-checkout-process.php:11
    117260msgid "Error en la autenticación."
    118261msgstr ""
    119262
    120 #: includes/class-pei_payment-checkout-process.php:9
     263#: includes/class-pei_payment-checkout-process.php:12
     264msgid "No se encuentra el recurso solicitado."
     265msgstr ""
     266
     267#: includes/class-pei_payment-checkout-process.php:13
     268msgid "El servicio no está disponible."
     269msgstr ""
     270
     271#: includes/class-pei_payment-checkout-process.php:14
    121272msgid "El monto de la compra es inferior al monto mínimo permitido."
    122273msgstr ""
    123274
    124 #: includes/class-pei_payment-checkout-process.php:10
     275#: includes/class-pei_payment-checkout-process.php:15
    125276msgid "Comercio no tiene una cuenta activa en la moneda elegida."
    126277msgstr ""
    127278
    128 #: includes/class-pei_payment-checkout-process.php:11
     279#: includes/class-pei_payment-checkout-process.php:16
    129280msgid "Error desconocido al intentar obtener la URL de pago de Pei."
    130281msgstr ""
    131282
    132 #: includes/class-pei_payment-checkout-process.php:12
     283#: includes/class-pei_payment-checkout-process.php:17
    133284msgid "Error desconocido al procesar el pago."
    134285msgstr ""
    135286
    136 #: includes/class-pei_payment-checkout-process.php:13
     287#: includes/class-pei_payment-checkout-process.php:18
    137288msgid "Error desconocido no identificado."
     289msgstr ""
     290
     291#: includes/class-pei_payment-checkout-process.php:22
     292msgid "Pago exitoso"
     293msgstr ""
     294
     295#: includes/class-pei_payment-checkout-process.php:23
     296msgid "Autenticación exitosa"
     297msgstr ""
     298
     299#: includes/class-pei_payment-checkout-process.php:24
     300#: includes/class-pei_payment-checkout-process.php:26
     301msgid "Error en la autenticación"
     302msgstr ""
     303
     304#: includes/class-pei_payment-checkout-process.php:25
     305#: includes/class-pei_payment-checkout-process.php:30
     306msgid "Error al procesar el pago"
     307msgstr ""
     308
     309#: includes/class-pei_payment-checkout-process.php:27
     310#: includes/class-pei_payment-checkout-process.php:28
     311msgid "Error de tarjeta"
    138312msgstr ""
    139313
     
    146320msgstr ""
    147321
    148 #: includes/class-pei_payment-webhook.php:132
    149 msgid "Su pago fue rechazado y su orden ha fallado."
    150 msgstr ""
    151 
    152 #: includes/class-pei_payment-webhook.php:125
    153 msgid "Su pago ha sido aceptado y su orden se encuentra en proceso."
    154 msgstr ""
    155 
    156322#: includes/class-pei_payment-webhook.php:126
    157323msgid "ID"
    158324msgstr ""
    159325
    160 #: includes/class-pei_payment-webhook.php:127
    161 msgid "Referencia del banco"
    162 msgstr ""
    163 
    164326#: includes/class-pei_payment-webhook.php:155
    165 msgid "El siguiente URL de webhook %1$s debes colocarlo en tu cuenta de pei Business en la sección de URL de notificaciones. Si tienes alguna duda puedes escribirnos a %2$s."
    166 msgstr ""
    167 
    168 #: includes/class-pei_payment-ws.php:49, includes/class-pei_payment-ws.php:46
    169 msgid "Error"
     327msgid "El siguiente URL de webhook %1$s debes colocarlo en tu cuenta de pei Business en la sección de URL de notificaciones. Si tienes alguna duda puedes escribirnos a %2$s ."
    170328msgstr ""
    171329
     
    178336msgstr ""
    179337
    180 #: includes/class-pei_payment.php:67
    181 msgid "Compra de %s en %s"
    182 msgstr ""
    183 
    184 #: includes/class-pei_payment.php:74
    185 msgid "Checkout iniciado: %s"
    186 msgstr ""
    187 
    188 #: includes/class-pei_payment.php:156
    189 msgid "Transacción:"
    190 msgstr ""
    191 
    192 #: includes/class-pei_payment.php:174
     338#: includes/class-pei_payment.php:177
    193339msgid "La respuesta del pago de su orden se mantiene pendiente. Le notificaremos cuando el proceso sea completado."
    194340msgstr ""
    195341
    196 #: includes/class-pei_payment.php:182
     342#: includes/class-pei_payment.php:185
    197343msgid "Su pago usando Pei ha sido recibido. Gracias."
    198344msgstr ""
    199345
    200 #: includes/class-pei_payment.php:219
    201 msgid "Transacción guardada en la tabla de control."
    202 msgstr ""
    203 
    204 #: includes/class-pei_payment.php:215
    205 msgid "Algo salió mal guardando la transacción en la tabla de control."
    206 msgstr ""
    207 
    208 #: includes/pei_payment-misc.php:7, includes/pei_payment-misc.php:7
     346#: wc-pei-payment-gateway.php:56
     347msgid "%s requiere %sWooCommerce%s para ser instalado y activado."
     348msgstr ""
     349
     350#: wc-pei-payment-gateway.php:192
    209351msgid "Pagos con pei"
    210352msgstr ""
    211353
    212 #: includes/pei_payment-misc.php:17
     354#: wc-pei-payment-gateway.php:195
     355msgid "Pagos vía Multimoney"
     356msgstr ""
     357
     358#: wc-pei-payment-gateway.php:195
     359msgid "Pagos con tarjeta vía Multimoney"
     360msgstr ""
     361
     362#: wc-pei-payment-gateway.php:205
    213363msgid "Ajustes"
    214364msgstr ""
    215 
    216 #: wc-pei-payment-gateway.php:50
    217 msgid "%s requiere %sWooCommerce%s para ser instalado y activado."
    218 msgstr ""
  • pei-payments/trunk/readme.txt

    r2412697 r2717683  
    9797
    9898== Changelog ==
     99* 2.0.0
     100- New: Nueva opción para aceptar pagos con tarjeta de Crédito/Débito
     101- Update: Columna para tabla de transacciones para identificar el tipo de transacción
    99102
     103* 1.0.0
     104- Versión inicial
     105- Pagos usando Pei
     106- Tabla de bitácora para controlar las transacciones
    100107
    101108== Upgrade Notice ==
  • pei-payments/trunk/wc-pei-payment-gateway.php

    r2412696 r2717683  
    44 * Plugin URI:  https://www.go-pei.com/busines/woocommerce/
    55 * Description: Acepta pagos SINPE desde cualquier cuenta y sin compartir información innecesaria o privada. Visualiza reportes y sigue el paso de todos los pagos realizados por el botón de pago pei en tu sitio web.
    6  * Version:     1.0.0
     6 * Version:     2.0.0
    77 * Requires at least: 4.4
    8  * Tested up to: 5.5.1
     8 * Tested up to: 5.9.3
    99 * WC requires at least: 3.0
    10  * WC tested up to: 4.5.2
     10 * WC tested up to: 6.3.1
    1111 * Author:      Gente mas Gente, S.A.
    1212 * Author URI:  https://www.grupogente.com/
    13  * Text Domain: pei-payments
     13 * Text Domain: pei-payment-gateway
    1414 * Domain Path: /languages
    1515 * License:     GPLv3
    1616 */
     17
    1718if (!defined('ABSPATH')) exit;
    1819
    19 if (!defined('PEI_PAYMENT_VERSION'))
    20     define('PEI_PAYMENT_VERSION', '1.0.0');
    21 
    22 if (!defined('PEI_PAYMENT_ID'))
    23     define('PEI_PAYMENT_ID', 'pei_payment');
    24 
    25 if (!defined('PEI_PAYMENT_PLUGIN_FILE'))
    26     define('PEI_PAYMENT_PLUGIN_FILE', plugin_basename(__FILE__));
    27 
    28 if (!defined('PEI_PAYMENT_PLUGIN_PATH'))
    29     define('PEI_PAYMENT_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
    30 
    31 if (!defined('PEI_PAYMENT_PLUGIN_URL'))
    32     define('PEI_PAYMENT_PLUGIN_URL', plugin_dir_url(__FILE__));
    33 
    34 /**
    35 ** Load misc. and other files
    36 **/
     20if ( ! defined( 'PEI_PAYMENT_VERSION' ) ) {
     21    define( 'PEI_PAYMENT_VERSION', '2.0.0' );
     22}
     23
     24if ( ! defined( 'PEI_PAYMENT_ID' ) ) {
     25    define( 'PEI_PAYMENT_ID', 'pei_payment' );
     26}
     27
     28if ( ! defined( 'PEI_PAYMENT_PLUGIN_FILE' ) ) {
     29    define( 'PEI_PAYMENT_PLUGIN_FILE', plugin_basename( __FILE__ ) );
     30}
     31
     32if ( ! defined( 'PEI_PAYMENT_PLUGIN_PATH' ) ) {
     33    define( 'PEI_PAYMENT_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
     34}
     35
     36if ( ! defined( 'PEI_PAYMENT_PLUGIN_URL' ) ) {
     37    define( 'PEI_PAYMENT_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
     38}
     39
     40/**
     41 * Load misc. and other files
     42 */
    3743include PEI_PAYMENT_PLUGIN_PATH . '/includes/class-pei_payment-ws.php';
    38 
    39 /**
    40 ** Check if WooCommerce is active
    41 **/
     44include PEI_PAYMENT_PLUGIN_PATH . '/includes/class-pei_cc_payment-ws.php';
     45
     46/**
     47 * Check if WooCommerce is active
     48 */
    4249function pei_payment_gateway_missing_wc_notice() {
    4350    if ( current_user_can( 'activate_plugins' ) ) :
     
    6067
    6168/**
    62 ** WebHook Notice
    63 **/
     69 * WebHook Notice
     70 */
    6471function pei_payment_gateway_wc_webhook_notice() {
    6572    $wcppw = new PEI_Payment_Webhook_Handler();
     
    7885
    7986/**
    80 ** Pei Payment Gateway init
    81 **/
     87 * Pei Payment Gateway init
     88 *
     89 * @since 1.0.0
     90 * @version 2.0.0
     91 */
    8292function pei_payment_gateway_init() {
    83     if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
    84         add_action('admin_notices', 'pei_payment_gateway_missing_wc_notice');
     93    if ( !in_array( 'woocommerce/woocommerce.php', get_option( 'active_plugins' ) ) ) {
     94        add_action( 'admin_notices', 'pei_payment_gateway_missing_wc_notice' );
    8595        return;
    8696    }
     97
     98    if ( ! class_exists( 'WC_Payment_Gateway' ) ) return;
    8799
    88100    /** Init Payment Gateway **/
    89101    include PEI_PAYMENT_PLUGIN_PATH . '/includes/class-pei_payment.php';
    90102    include PEI_PAYMENT_PLUGIN_PATH . '/includes/class-pei_payment-webhook.php';
    91     if (!class_exists('WC_PEI_Payment_Gateway')) return;
     103    include PEI_PAYMENT_PLUGIN_PATH . '/includes/class-pei_cc_payment.php';
     104    include PEI_PAYMENT_PLUGIN_PATH . '/includes/class-pei_cc_payment-endpoint.php';
     105    include PEI_PAYMENT_PLUGIN_PATH . '/includes/class-pei_payment-checkout-process.php';
     106
     107    if ( ! class_exists( 'WC_PEI_Payment_Gateway' ) || ! class_exists( 'WC_PEI_CC_Payment_Gateway' ) ) return;
    92108
    93109    function pei_payment_gateway_class($methods) {
    94110        $methods[] = 'WC_PEI_Payment_Gateway';
     111        $methods[] = 'WC_PEI_CC_Payment_Gateway';
    95112
    96113        return $methods;
    97114    }
    98     add_filter('woocommerce_payment_gateways', 'pei_payment_gateway_class');
     115    add_filter( 'woocommerce_payment_gateways', 'pei_payment_gateway_class' );
    99116
    100117    /** Load language **/
    101     load_plugin_textdomain('pei-payment-gateway', false, plugin_basename(dirname(__FILE__)) . '/languages');
     118    load_plugin_textdomain( 'pei-payment-gateway', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
    102119
    103120    /** WebHook URL **/
    104     add_action('admin_notices', 'pei_payment_gateway_wc_webhook_notice');
     121    add_action( 'admin_notices', 'pei_payment_gateway_wc_webhook_notice' );
    105122
    106123    /** Create Transaction table **/
    107124    $site_option_version = get_site_option('pei_payment_gateway_version');
    108     if ($site_option_version != PEI_PAYMENT_VERSION || empty($site_option_version)) {
     125    if ( $site_option_version != PEI_PAYMENT_VERSION || empty( $site_option_version ) ) {
    109126        pei_payment_gateway_install();
    110127    }
    111 }
    112 add_action('plugins_loaded', 'pei_payment_gateway_init');
    113 
    114 /**
    115 ** Create table and save payment gateway version
    116 ** Table to store all processed transactions for this payment gateway
    117 **/
     128   
     129    $site_update_table = get_site_option( 'pei_payment_table_transactions_updated' );
     130    if ( version_compare( PEI_PAYMENT_VERSION, '1.1', '>' ) && empty( $site_update_table ) ) {
     131        pei_payment_alter_transactions_table();
     132    }
     133
     134    flush_rewrite_rules();
     135}
     136add_action( 'plugins_loaded', 'pei_payment_gateway_init' );
     137
     138/**
     139 * Create table and save payment gateway version
     140 * Table to store all processed transactions for this payment gateway
     141 */
    118142function pei_payment_gateway_install() {
    119143    global $wpdb;
     
    141165
    142166/**
     167 * Alter column status for previous installed plugins
     168 *
     169 * @version 2.0.0
     170 */
     171function pei_payment_alter_transactions_table() {
     172    global $wpdb;
     173
     174    $table_bitacora = $wpdb->prefix . 'pei_transactions';
     175    $sql = "ALTER TABLE " . $table_bitacora;
     176    $sql .= " ADD payment_method varchar(20) NULL DEFAULT NULL,";
     177    $sql .= " CHANGE COLUMN `status` `status` varchar(5) NULL DEFAULT NULL;";
     178    $result = $wpdb->query( $sql );
     179
     180    if ( $result ) {
     181        update_option( 'pei_payment_table_transactions_updated', PEI_PAYMENT_VERSION );
     182    } else {
     183        update_option( 'pei_payment_table_transactions_updated_error', $sql );
     184    }
     185}
     186
     187/**
    143188 * Add setting links to WC
    144189 */
     
    147192        'woocommerce', __('Pagos con pei', 'pei-payment-gateway'), __('Pagos con pei', 'pei-payment-gateway'), 'manage_options', admin_url('admin.php?page=wc-settings&tab=checkout&section=' . PEI_PAYMENT_ID)
    148193    );
    149 }
    150 add_action('admin_menu', 'pei_payment_gateway_admin_submenu');
     194    add_submenu_page(
     195        'woocommerce', __('Pagos vía Multimoney', 'pei-payment-gateway'), __('Pagos con tarjeta vía Multimoney', 'pei-payment-gateway'), 'manage_options', admin_url('admin.php?page=wc-settings&tab=checkout&section=pei_cc_payment')
     196    );
     197}
     198add_action( 'admin_menu', 'pei_payment_gateway_admin_submenu' );
    151199
    152200/**
     
    161209    return array_merge($plugin_links, $links);   
    162210}
    163 add_filter('plugin_action_links_' . PEI_PAYMENT_PLUGIN_FILE, 'pei_payment_gateway_links');
     211add_filter( 'plugin_action_links_' . PEI_PAYMENT_PLUGIN_FILE, 'pei_payment_gateway_links' );
Note: See TracChangeset for help on using the changeset viewer.