Plugin Directory

Changeset 3132372


Ignore:
Timestamp:
08/07/2024 11:45:12 PM (18 months ago)
Author:
taylor1991
Message:

Fixed the error when making the payment in the checkout section

Location:
woo-xchange-payments/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • woo-xchange-payments/trunk/XChange.js

    r2683383 r3132372  
    11/****************************************************************
    22 * @author      : Jekferson Diaz
    3  * @name        : XChange
    4  * @description  : Objeto de Dominio XChange
    5  * @copyright (c)  Xchange
     3 * @name        : Quikly Pay
     4 * @description  : Objeto de Dominio Quikly Pay
     5 * @copyright (c)  QUIKLY GROUP LTD
    66 *****************************************************************/
    77XChange = (function() {
     
    1515        console.log(response);
    1616        jQuery.ajax({
    17             url: "https://paydh51l52.execute-api.us-east-1.amazonaws.com/v1/xchange",
     17            url: "https://mdjc7112pd.execute-api.us-east-1.amazonaws.com/v1/xchange",
    1818            type: "POST",
    1919            data: jQuery(".woocommerce-checkout").serialize(),
     
    4444           
    4545                $data = data;
     46                console.log("data recibe", $data);
    4647
    4748                var object = {
  • woo-xchange-payments/trunk/helpers.php

    r2597007 r3132372  
    1111    wp_enqueue_script( 'xchange_paybox_script_index', "https://paybox.quikly.app/paybox/index_Wordpress.js", array("jquery"), '1.0', false );
    1212    wp_enqueue_script( 'xchange_paybox_script', plugins_url() . "/woo-xchange-payments/XChange.js", array("jquery", "xchange_paybox_script_index"), '1.0', false );
     13
     14    // x   
     15
     16    $data_to_pass = array(
     17        'order_id' => WC()->session->get('current_order_id')
     18    );
     19
     20    // Pasa los datos al script
     21    wp_localize_script('xchange_paybox_script', 'payboxData', $data_to_pass);
    1322}
    1423
     
    8493
    8594    $paybox_production = false;
    86    
     95       
    8796    if ($adb_xchange_sandbox_state !== "yes") { 
    8897        $paybox_production = true;
     
    92101        wp_enqueue_script( 'jquery' );
    93102    }
     103
     104       
    94105    ?>
    95106        <script type="text/javascript">
     
    104115                PayboxRequired: [
    105116                    <?php echo $adb_validation_fields_lista; ?>
    106                 ]
    107             };
     117                ],
     118                OrderKey: "<?php echo $order_key; ?>"
     119            }
    108120            XChange.init(data);
    109121        </script>       
  • woo-xchange-payments/trunk/readme.txt

    r2684585 r3132372  
    55Requires PHP: 5.6
    66Requires at least: 5.8
    7 Tested up to: 5.8
     7Tested up to: 6.6.1
    88Stable tag: 2.3.4
    9 Plugin URI: https://pay.quikly.app/web/developer
    10 Version: 2.0.1
     9Plugin URI: https://quiklypay.com/web/developer
     10Version: 3.0
    1111License: GPL2
    1212License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1515 == Description ==
    1616
    17 This plugin integrates Woocommerce with Quikly Payment Facilitator button, which you can use as a Payment gateway for all major credit cards and even Paypal accounts. Quikly has its headquarters in London, United Kingdom and is expanding its services in Latin America. It has the lowest fees in the Latin America market, for more information you can ckeckout the official website. https://pay.quikly.app
     17This plugin integrates Woocommerce with Quikly Payment Facilitator button, which you can use as a Payment gateway for all major credit and debit cards. Quikly has its headquarters in London, United Kingdom and is expanding its services in Latin America. It has the lowest fees in the Latin America market, for more information you can ckeckout the official website. https://quiklypay.com
    1818
    1919 = Minimum Requirements =
     
    3333==  Plugin Configuration ==
    3434
    35 Once installed, go to Woocommerce -> Settings Pick Checkout Tab and once on that tab go to Payment gateways and click on Quikly, once on Quikly, click on Enable Quikly, and put your Quikly account data. Also, we put the default wordpress, checkout requirred fields as mandatory before the Quikly Modal pop ups like, #billing_email" if you add your custom requirred fields, please add them on the Form Validation Fields area in Quikly tab, on this format: Ex: #billing_email", "#my_custom_field", "#my_custom_field2" always use the #id css format. If requirred fields are not filled then Quikly Modal is not going to PopUp. So check this detail before implementing.
     35Once installed, go to Woocommerce -> Settings Pick Checkout Tab and once on that tab go to Payment gateways and click on Quikly Pay, once on Quikly Pay, click on Enable Quikly Pay, and put your Quikly Pay account data. Also, we put the default wordpress, checkout requirred fields as mandatory before the Quikly Modal pop ups like, #billing_email" if you add your custom requirred fields, please add them on the Form Validation Fields area in Quikly tab, on this format: Ex: #billing_email", "#my_custom_field", "#my_custom_field2" always use the #id css format. If requirred fields are not filled then Quikly Pay Modal is not going to PopUp. So check this detail before implementing.
    3636
    3737==  Security Tips ==
    3838
    39 Before using Quikly, enable the sandbox option, to test the gateway. Only the paranoid survive as Andy Grove, CEO of Intel once said. So test before implementing, here is some sandbox credit card numbers and data to test, https://pay.quikly.app/web/developer Once you see that the order has been marked on the checkout page as processed (not really its, sandbox), disable sandbox.  By the way, on sandbox, for security reasons, payments and are not processed in Quikly and the order is not recorded in woocommerce. If you wish to test, that order processing please contact us to guide you on how to do that on the code. For security reasons, sandbox testing is limited.
     39Before using Quikly Pay, enable the sandbox option, to test the gateway. Only the paranoid survive as Andy Grove, CEO of Intel once said. So test before implementing, here is some sandbox credit card numbers and data to test, https://quiklypay.com/web/developer Once you see that the order has been marked on the checkout page as processed (not really its, sandbox), disable sandbox.  By the way, on sandbox, for security reasons, payments and are not processed in Quikly and the order is not recorded in woocommerce. If you wish to test, that order processing please contact us to guide you on how to do that on the code. For security reasons, sandbox testing is limited.
    4040Also remember once the plugin is deleted all Quikly data will be erased.
    4141
     
    8080* New: Production plugin for new version
    8181
     82= 3.0 = Released on Aug 8, 2024
     83
     84* New: Fixed the error when making the payment in the checkout section
     85
    8286== Screenshots ==
    8387
     
    86903. The settings of plugin
    8791
    88 
    8992==  More information ==
    9093
    91 For more information or doubts contact at https://pay.quikly.app, [email protected]
     94For more information or doubts contact at https://quiklypay.com/web/developer, [email protected]
    9295
    9396
  • woo-xchange-payments/trunk/xchange.php

    r2684585 r3132372  
    22/*
    33 * Plugin Name: WooCommerce Quikly Payments
    4  * Plugin URI: https://pay.quikly.app/developer
     4 * Plugin URI: https://quiklypay.com/developer
    55 * Description: Sell in your ecommerce with any credit / debit card through our plugin.
    66
    77 * Version: 2
    8  * Author: QUIKLY GROUP UK LTD
    9  * Author URI: https://pay.quikly.app
     8 * Author: QUIKLY GROUP LTD
     9 * Author URI: https://quiklypay.com
    1010 * License: GPL2
    1111 */
     
    1313
    1414
    15  if ( ! defined( 'ABSPATH' ) ) {
     15if (!defined('ABSPATH')) {
    1616    exit; /* Exit if accessed directly. Security measure to avoid direct access to plugin under Wordpress Security Guidelines*/
    1717}
     
    3030/*********** PART 1. wp-admin Area Scripts and start of the WC_Payment_Gateway which is the Woocommerce API Gateway Plugin Creation Class *************************/
    3131
    32  
    33  /*
     32
     33/*
    3434 * This action hook registers our PHP class as a WooCommerce payment gateway
    3535 */
    36  
    37 
    38 add_filter( 'woocommerce_payment_gateways', 'xchange_add_gateway_class' );
    39 function xchange_add_gateway_class( $gateways ) {
     36
     37function xchange_add_message_listener_script()
     38{
     39    ?>
     40    <script type="text/javascript">
     41        // Escucha los mensajes entrantes
     42        window.addEventListener('message', function (event) {
     43            // Valida el origen para asegurarte de que es seguro
     44            // if (event.origin !== "https://tu-dominio-de-iframe.com") { // Cambia a tu dominio de iframe
     45            //  console.warn('Origen no válido:', event.origin);
     46            //  return;
     47            // }
     48
     49            // Manejar el mensaje de éxito
     50            //console.log("eventoooooo", event);
     51            if (event.data.status === 'success') {
     52                console.log('Pago exitoso recibido en WordPress:', event.data.paymentIntent);
     53                console.log('Orden Id', event.data.orderId)
     54
     55                // Llama a una función de PHP para procesar el pago exitoso
     56                jQuery.ajax({
     57                    url: "<?php echo admin_url('admin-ajax.php'); ?>",
     58                    type: "POST",
     59                    data: {
     60                        action: 'procesar_pago_exitoso',
     61                        paymentIntent: event.data.paymentIntent,
     62                        orderId: event.data.orderId // Supongamos que el orderId viene en event.data
     63                    },
     64                    success: function (response) {
     65                        console.log('Pago procesado con éxito en el servidor:', response);
     66                        window.location.href = response.data.redirect;
     67                    }
     68                });
     69            } else {
     70                jQuery.ajax({
     71                    url: "<?php echo admin_url('admin-ajax.php'); ?>",
     72                    type: "POST",
     73                    data: {
     74                        action: 'procesar_pago_fallido',
     75                        paymentIntent: event.data.paymentIntent,
     76                        orderId: event.data.orderId // Supongamos que el orderId viene en event.data
     77                    },
     78                    success: function (response) {
     79                        console.log('Pago no fue procesado:', response);
     80                    }
     81                });
     82            }
     83        });
     84    </script>
     85    <?php
     86}
     87add_action('wp_footer', 'xchange_add_message_listener_script');
     88
     89
     90// Añade la función para manejar el AJAX
     91function procesar_pago_exitoso()
     92{ // Elimina $order_id aquí
     93    if (isset($_POST['paymentIntent']) && isset($_POST['orderId'])) {
     94        // Obtén los datos de la transacción
     95        $paymentIntent = $_POST['paymentIntent'];
     96        $order_id = intval($_POST['orderId']); // Asegúrate de que el ID sea un número entero
     97
     98        // Obtener la orden
     99        $order = wc_get_order($order_id);
     100
     101        if ($order) {
     102            // Actualiza el estado del pedido a "procesando" o cualquier otro estado deseado
     103            $order->update_status('processing', __('Payment received, awaiting fulfillment', 'woocommerce'));
     104
     105            // Reduce el inventario de productos
     106            wc_reduce_stock_levels($order_id);
     107
     108            // Vacía el carrito
     109            WC()->cart->empty_cart();
     110
     111            // Envía una respuesta JSON
     112            // Obtiene la URL de retorno
     113            $redirect_url = $order->get_checkout_order_received_url();
     114
     115            // Envía una respuesta JSON
     116            wp_send_json_success(
     117                array(
     118                    'message' => 'Pago procesado correctamente.',
     119                    'paymentIntent' => $paymentIntent,
     120                    'orderId' => $order_id,
     121                    'redirect' => $redirect_url  // Incluye la URL de redirección
     122                )
     123            );
     124
     125            // Retorna el resultado y redirige a la página de agradecimiento
     126            return array(
     127                'result' => 'success',
     128                'redirect' => get_return_url($order)
     129            );
     130        } else {
     131            wp_send_json_error('No se encontró la orden.');
     132        }
     133    } else {
     134        wp_send_json_error('Datos de transacción no recibidos.');
     135    }
     136    wp_die();
     137}
     138add_action('wp_ajax_procesar_pago_exitoso', 'procesar_pago_exitoso');
     139add_action('wp_ajax_nopriv_procesar_pago_exitoso', 'procesar_pago_exitoso');
     140
     141
     142function procesar_pago_fallido()
     143{
     144    if (isset($_POST['paymentIntent']) && isset($_POST['orderId'])) {
     145        // Obtén los datos de la transacción
     146        $paymentIntent = $_POST['paymentIntent'];
     147        $order_id = intval($_POST['orderId']); // Asegúrate de que el ID sea un número entero
     148
     149        // Obtener la orden
     150        $order = wc_get_order($order_id);
     151
     152        if ($order) {
     153            // Actualiza el estado del pedido a "failed"
     154            $order->update_status('failed', __('Payment failed, order canceled', 'woocommerce'));
     155
     156            // Envía una respuesta JSON
     157            wp_send_json_success(
     158                array(
     159                    'message' => 'Pago fallido, estado de la orden actualizado.',
     160                    'paymentIntent' => $paymentIntent,
     161                    'orderId' => $order_id // Incluye el orderId en la respuesta
     162                )
     163            );
     164
     165            // Retorna el resultado y redirige a la página de agradecimiento
     166            return array(
     167                'result' => 'success',
     168                'redirect' => get_return_url($order)
     169            );
     170        } else {
     171            wp_send_json_error('No se encontró la orden.');
     172        }
     173    } else {
     174        wp_send_json_error('Datos de transacción no recibidos.');
     175    }
     176    wp_die();
     177}
     178add_action('wp_ajax_procesar_pago_fallido', 'procesar_pago_fallido');
     179add_action('wp_ajax_nopriv_procesar_pago_fallido', 'procesar_pago_fallido');
     180
     181
     182
     183add_filter('woocommerce_payment_gateways', 'xchange_add_gateway_class');
     184function xchange_add_gateway_class($gateways)
     185{
    40186    $gateways[] = 'WC_Xchange_Gateway'; // your class name is here
    41187    return $gateways;
    42188}
    43  
     189
    44190/*
    45191 * The class itself, please note that it is inside plugins_loaded action hook
    46192 */
    47 add_action( 'plugins_loaded', 'xchange_init_gateway_class' );
    48 
    49 function xchange_init_gateway_class() {
    50 
    51     class WC_Xchange_Gateway extends WC_Payment_Gateway {
    52 
    53         /**
    54          * Class constructor
    55          */
    56         public function __construct() {
     193add_action('plugins_loaded', 'xchange_init_gateway_class');
     194
     195function xchange_init_gateway_class()
     196{
     197
     198    class WC_Xchange_Gateway extends WC_Payment_Gateway
     199    {
     200
     201        /**
     202         * Class constructor
     203         */
     204        public function __construct()
     205        {
    57206
    58207            $this->id = 'xchange'; // payment gateway plugin ID
    59208            $this->icon = 'https://cdn.quikly.app/img/logo_cms.png'; // URL of the icon that will be displayed on checkout page near your gateway name
    60209            $this->has_fields = true; // in case you need a custom credit card form
    61             // Supports the default credit card form
    62             $this->supports = array('default_credit_card_form');
     210            // Supports the default credit card form
     211            $this->supports = array('default_credit_card_form');
    63212            $this->method_title = 'Quikly Pay';
    64             $this->method_description = 'Quikly pay is a method for pay'; // will be displayed on the options page
    65             //$this->method_adb_username_email = 'XChange Username';
     213            $this->method_description = 'Accept credit/debit card payments in your store, sign up now and start accepting payments in just 5 minutes'; // will be displayed on the options page
     214            //$this->method_adb_username_email = 'XChange Username';
    66215
    67216            // gateways can support subscriptions, refunds, saved payment methods, this case Products
     
    75224            $this->supports = array('default_credit_card_form');
    76225
    77             // This basically defines your settings which are then loaded with init_settings()
    78             $this->init_form_fields();
    79                 // After init_settings() is called, you can get the settings and load them into variables, e.g:
    80             // $this->title = $this->get_option( 'title' );
    81             $this->init_settings();
    82 
    83             // Turn these settings into variables we can use
    84             foreach ($this->settings as $setting_key => $value) {
    85                 $this->$setting_key = $value;
    86             }
    87            
    88             $this->title = $this->get_option( 'title' );
    89             $this->description = $this->get_option( 'description' );
    90             $this->enabled = $this->get_option( 'enabled' );
    91             $this->sandbox = $this->get_option( 'sandbox' );
    92             $this->validation = $this->get_option( 'validation' );
    93             $this->customer_firstname = $this->get_option( 'customer_firstname' );
    94             $this->customer_lastname = $this->get_option( 'customer_lastname' );
    95             $this->customer_email = $this->get_option( 'customer_email' );
     226            // This basically defines your settings which are then loaded with init_settings()
     227            $this->init_form_fields();
     228            // After init_settings() is called, you can get the settings and load them into variables, e.g:
     229            // $this->title = $this->get_option( 'title' );
     230            $this->init_settings();
    96231
    97232            // Turn these settings into variables we can use
    98             foreach ($this->settings as $setting_key => $value) {
    99                 $this->$setting_key = $value;
    100             }
     233            foreach ($this->settings as $setting_key => $value) {
     234                $this->$setting_key = $value;
     235            }
     236
     237            $this->title = $this->get_option('title');
     238            $this->description = $this->get_option('description');
     239            $this->enabled = $this->get_option('enabled');
     240            $this->sandbox = $this->get_option('sandbox');
     241            $this->validation = $this->get_option('validation');
     242            $this->customer_firstname = $this->get_option('customer_firstname');
     243            $this->customer_lastname = $this->get_option('customer_lastname');
     244            $this->customer_email = $this->get_option('customer_email');
     245
     246            // Turn these settings into variables we can use
     247            foreach ($this->settings as $setting_key => $value) {
     248                $this->$setting_key = $value;
     249            }
    101250
    102251            // Turn these settings into variables we can use
    103252            /*foreach ( $this->settings as $setting_key => $value ) {
    104                 $this->$setting_key = $value;
    105             }*/
     253                                                                               $this->$setting_key = $value;
     254                                                                           }*/
    106255            ///End
    107256
    108257            // This action hook saves the settings
    109             add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
    110        
     258            add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
     259
    111260
    112261            // We need custom JavaScript to obtain a token
    113262            //add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
    114          
     263
    115264            // You can also register a webhook here
    116265            // add_action( 'woocommerce_api_{webhook name}', array( $this, 'webhook' ) );
    117266
    118         }  // End Constructor
    119 
    120         function admin_options() {
    121            
    122             $data = '
     267        }  // End Constructor
     268
     269        function admin_options()
     270        {
     271
     272            $data = '
    123273                jQuery(document).on("ready", function(){
    124274                    if (jQuery("#woocommerce_xchange_advanced_options")[0].checked) {
     
    149299                });
    150300            ';
    151            
    152             wp_enqueue_script( 'xchange_admin_script', 'https://paybox.quikly.app/js/data.js', array(), '1.0' );
    153             wp_add_inline_script( 'xchange_admin_script', $data );
    154         ?>
    155             <h2>
    156                 <?php
    157                     _e($this->method_title, 'woocommerce');
    158                     wc_back_link( __( null, 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) );
     301
     302            wp_enqueue_script('xchange_admin_script', 'https://paybox.quikly.app/js/data.js', array(), '1.0');
     303            wp_add_inline_script('xchange_admin_script', $data);
     304            ?>
     305            <h2>
     306                <?php
     307                _e($this->method_title, 'woocommerce');
     308                wc_back_link(__(null, 'woocommerce'), admin_url('admin.php?page=wc-settings&tab=checkout'));
    159309                ?>
    160310            </h2>
    161             <?php
    162                 echo wpautop( wp_kses_post( $this->method_description ) );
    163             ?>
    164             <table class="form-table">
    165                 <?php
    166                 if ( empty( $form_fields ) ) {
     311            <?php
     312            echo wpautop(wp_kses_post($this->method_description));
     313            ?>
     314            <table class="form-table">
     315                <?php
     316                if (empty($form_fields)) {
    167317                    $form_fields = $this->get_form_fields();
    168318                }
    169319                $html = '';
    170                 foreach ( $form_fields as $k => $v ) {
    171                     $type = $this->get_field_type( $v );
    172                     if ( method_exists( $this, 'generate_' . $type . '_html' ) ) {
    173                         $html .= $this->{'generate_' . $type . '_html'}( $k, $v );
     320                foreach ($form_fields as $k => $v) {
     321                    $type = $this->get_field_type($v);
     322                    if (method_exists($this, 'generate_' . $type . '_html')) {
     323                        $html .= $this->{'generate_' . $type . '_html'}($k, $v);
    174324                    } else {
    175                         $html .= $this->generate_text_html( $k, $v );
     325                        $html .= $this->generate_text_html($k, $v);
    176326                    }
    177327                }
    178                 if ( $echo ) {
     328                if ($echo) {
    179329                    echo $html;
    180330                } else {
    181331                    echo $html;
    182332                }
    183                 ?>
    184             </table>
    185         <?php
    186         }
    187  
     333                ?>
     334            </table>
     335            <?php
     336        }
     337
    188338        /**
    189339         * Admin Settings on the wp-admin/woocommerce/settings/xchange
    190340         */
    191         public function init_form_fields(){
    192      
     341        public function init_form_fields()
     342        {
     343
    193344            $this->form_fields = array(
    194345                'enabled' => array(
    195                     'title'       => 'Enable/Disable',
    196                     'label'       => 'Enable Quikly pay',
    197                     'type'        => 'checkbox',
     346                    'title' => 'Enable/Disable',
     347                    'label' => 'Enable Quikly Pay',
     348                    'type' => 'checkbox',
    198349                    'description' => '',
    199                     'default'     => 'no'
     350                    'default' => 'no'
    200351                ),
    201352
    202353                'sandbox' => array(
    203                     'title'       => 'Quikly pay Sandbox',
    204                     'label'       => 'Enable SandBox',
    205                     'type'        => 'checkbox',
    206                     'description' => 'Quikly pay sandbox can be used to test payments. Recommended before using it in production environment.',
    207                     'default'     => 'yes'
     354                    'title' => 'Quikly Pay Sandbox',
     355                    'label' => 'Enable SandBox',
     356                    'type' => 'checkbox',
     357                    'description' => 'Quikly Pay sandbox can be used to test payments. Recommended before using it in production environment.',
     358                    'default' => 'yes'
    208359                ),
    209360
    210361                'title' => array(
    211                     'title'       => 'Title',
    212                     'type'        => 'text',
     362                    'title' => 'Title',
     363                    'type' => 'text',
    213364                    'description' => 'This controls the title which the user sees during checkout.',
    214                     'default'     => 'Quikly Pay',
    215                     'desc_tip'    => true,
     365                    'default' => 'Quikly Pay',
     366                    'desc_tip' => true,
    216367                ),
    217368                'description' => array(
    218                     'title'       => 'Description',
    219                     'type'        => 'textarea',
     369                    'title' => 'Description',
     370                    'type' => 'textarea',
    220371                    'description' => 'This controls the description which the user sees during checkout.',
    221                     'default'     =>  'Buy with your credit card with our payment method.' ,
    222                 ),
    223                
     372                    'default' => 'Buy with credit/debit card in the safest way online.',
     373                ),
     374
    224375                'adb_username_email' => array(
    225                     'title'       => 'User Email',
    226                     'type'        => 'text',
    227                     'description' => 'Your Quikly pay Email',
    228                 ),
    229            
     376                    'title' => 'User Email',
     377                    'type' => 'text',
     378                    'description' => 'Your Quikly Pay Email',
     379                ),
     380
    230381                'adb_username' => array(
    231                     'title'       => 'Username',
    232                     'type'        => 'text',
    233                     'description'     => 'Your Quikly pay Username'
     382                    'title' => 'Username',
     383                    'type' => 'text',
     384                    'description' => 'Your Quikly Pay Username'
    234385
    235386                ),
    236387
    237388                'advanced_options' => array(
    238                     'title'       => 'Advanced Options',
    239                     'label'       => 'Advanced Options',
    240                     'type'        => 'checkbox',
     389                    'title' => 'Advanced Options',
     390                    'label' => 'Advanced Options',
     391                    'type' => 'checkbox',
    241392                    'description' => '',
    242393                ),
    243394
    244395                'customer_firstname' => array(
    245                     'title'       => 'Customer Firstname',
    246                     'type'        => 'text',
     396                    'title' => 'Customer Firstname',
     397                    'type' => 'text',
    247398                    'description' => "Indicate the id of the element that contains the customer's firstname. <b>Default: #billing_first_name</b>",
    248                     'default'     =>  '#billing_first_name' ,
     399                    'default' => '#billing_first_name',
    249400                ),
    250401
    251402                'customer_lastname' => array(
    252                     'title'       => 'Customer Lastname',
    253                     'type'        => 'text',
     403                    'title' => 'Customer Lastname',
     404                    'type' => 'text',
    254405                    'description' => "Indicate the id of the item that contains the customer's lastname. <b>Default: #billing_last_name</b>",
    255                     'default'     =>  '#billing_last_name' ,
     406                    'default' => '#billing_last_name',
    256407                ),
    257408
    258409                'customer_email' => array(
    259                     'title'       => 'Customer Email',
    260                     'type'        => 'text',
     410                    'title' => 'Customer Email',
     411                    'type' => 'text',
    261412                    'description' => "Indicate the id of the item that contains the customer's email. <b>Default: #billing_email</b>",
    262                     'default'     =>  '#billing_email' ,
     413                    'default' => '#billing_email',
    263414                ),
    264415
    265416                'validation' => array(
    266                     'title'       => 'Form Validation Fields',
    267                     'type'        => 'textarea',
     417                    'title' => 'Form Validation Fields',
     418                    'type' => 'textarea',
    268419                    'description' => 'Required fields to be validated on Checkout Form before XChange pops up (if not filled XChange Modal wont pop up), leave your custom fields, between "", Ex: "#billing_email" , "#my_custom_field"',
    269                     'default'     =>   
     420                    'default' =>
    270421                        '"#billing_first_name",
    271422                        "#billing_last_name",
     
    284435
    285436        // Process Payment Woocommerce API - Funcion para Procesar pedido de Wordpress / Woocommerce
    286  
    287         public function process_payment( $order_id ) {
    288            
    289             //wc_add_notice( __('Pago ha sido procesado exitosamente !', 'woothemes'), 'success' );
    290             return ;
     437
     438        public function process_payment($order_id)
     439        {
     440
     441            $order = wc_get_order($order_id);
     442
     443            if ($order) {
     444                // Actualiza el estado del pedido a "procesando" o cualquier otro estado deseado
     445                //$order->update_status('processing', __('Payment received, awaiting fulfillment', 'woocommerce'));
     446
     447                // Reduce el inventario de productos
     448                //wc_reduce_stock_levels($order_id);
     449
     450                // Vacía el carrito
     451                //WC()->cart->empty_cart();
     452
     453                // Retorna el resultado y redirige a la página de agradecimiento
     454                // return array(
     455                //  'result' => 'success',
     456                //  'redirect' => $this->get_return_url($order)
     457                // );
     458                $order->update_status('on-hold', __('Esperando pago', 'woocommerce'));
     459                WC()->session->set('current_order_id', $order_id);
     460
     461                $order_key = $order->get_order_key();
     462
     463                // Retorna el order_id y order_key
     464                wp_send_json_success(
     465                    array(
     466                        'order_id' => $order_id,
     467                        'order_key' => $order_key
     468                    )
     469                );
     470
     471                WC()->session->set('current_order_id', $order_id);
     472
     473                // Guarda el order_key en la sesión
     474                $order_key = $order->get_order_key();
     475                WC()->session->set('current_order_key', $order_key);
     476
     477                // No hacer más acciones después de enviar la respuesta JSON
     478
     479                //wc_add_notice(__('Pago ha sido procesado exitosamente !', 'woothemes'), 'success');
     480                return;
     481
     482
     483
     484
     485
     486                // Encola los scripts y pasa los datos a los scripts
     487                // add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
     488
     489                // // Retorna el resultado y redirige a la página de agradecimiento
     490                // return array(
     491                //  'result' => 'success',
     492                //  'redirect' => $this->get_return_url($order)
     493                // );
     494
     495            }
    291496        }
    292497
    293498        // Validate form fields
    294         public function validate_fields() {
     499        public function validate_fields()
     500        {
    295501            return true;
    296502        }
    297503
    298504        // To add the Xchange Button on the Xchange payment box
    299         public function payment_fields() {
     505        public function payment_fields()
     506        {
    300507
    301508            //Grab description data as this is erased when payment fields enabled
    302             $adb_xchange_settings2 = get_option( 'woocommerce_xchange_settings' );
     509            $adb_xchange_settings2 = get_option('woocommerce_xchange_settings');
    303510            $adb_xchange_description_admin_area = $adb_xchange_settings2['description'];
    304511
    305             do_action('woocommerce_credit_card_form_start'); 
    306             echo '<p>' . $adb_xchange_description_admin_area . '</p><br/><div id="ButtonPaybox"></div>';
    307             do_action('woocommerce_credit_card_form_end');   
     512            do_action('woocommerce_credit_card_form_start');
     513            echo '<p>' . $adb_xchange_description_admin_area . '</p><br/><div id="ButtonPaybox"></div>';
     514            do_action('woocommerce_credit_card_form_end');
    308515
    309516        } // End Add custom button
Note: See TracChangeset for help on using the changeset viewer.