| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Pagantis\ModuleUtils\Exception\OrderNotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Pagantis\OrdersApiClient\Model\Order\User\Address; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Pagantis\ModuleUtils\Exception\UnknownException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | define('TABLE_PAGANTIS_LOG', 'pagantis_log'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | define('TABLE_PAGANTIS_CONFIG', 'pagantis_config'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | define('TABLE_PAGANTIS_ORDERS', 'pagantis_order'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | define('TABLE_PAGANTIS_CONCURRENCY', 'pagantis_concurrency'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | define('__ROOT__', dirname(dirname(__FILE__))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class pagantis | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** @var  String $is_guest */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     public $is_guest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** @var Array $extraConfig */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public $extraConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** @var String $form_action_url */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public $form_action_url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** @var String $base_url */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public $base_url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** @var String $os_order_reference */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public $os_order_reference; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     /** @var notifyController $pgNotify */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public $pgNotify; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public $defaultConfigs = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         'PAGANTIS_TITLE'=>'Instant Financing', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         'PAGANTIS_SIMULATOR_DISPLAY_TYPE'=>'pgSDK.simulator.types.SIMPLE', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         'PAGANTIS_SIMULATOR_DISPLAY_SKIN'=>'pgSDK.simulator.skins.BLUE', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         'PAGANTIS_SIMULATOR_DISPLAY_POSITION'=>'hookDisplayProductButtons', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         'PAGANTIS_SIMULATOR_START_INSTALLMENTS'=>3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         'PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'=>12, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'=>'default', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'=>'pgSDK.simulator.positions.INNER', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'=>'default', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'=>'default', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         'PAGANTIS_FORM_DISPLAY_TYPE'=>0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         'PAGANTIS_DISPLAY_MIN_AMOUNT'=>1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         'PAGANTIS_URL_OK'=>'', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         'PAGANTIS_URL_KO'=>'', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         'PAGANTIS_TITLE_EXTRA' => 'Paga hasta en 12 cómodas cuotas con Paga+Tarde. Solicitud totalmente online y sin papeleos,¡y la respuesta es inmediata!' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     * Constructor | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 53 |  |  |     */ | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     public function __construct() | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         $this->version = '8.0.0'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         $this->code = 'pagantis'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         $this->sort_order = 0; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         if (strpos($_SERVER[REQUEST_URI], "checkout_payment.php") <= 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |             $this->title = MODULE_PAYMENT_PAGANTIS_TEXT_ADMIN_TITLE; // Payment module title in Admin | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |             $this->title = MODULE_PAYMENT_PAGANTIS_TEXT_CATALOG_TITLE; // Payment module title in Catalog | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         $this->enabled = ((MODULE_PAYMENT_PAGANTIS_STATUS == 'True') ? true : false); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |         $this->extraConfig = $this->getExtraConfig(); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |          | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |         $this->base_url = dirname( | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |             sprintf( | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |                 "%s://%s%s%s", | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |                 isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |                 $_SERVER['SERVER_NAME'], | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |                 isset($_SERVER['SERVER_PORT']) ? ":".$_SERVER['SERVER_PORT'] : '', | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |                 $_SERVER['REQUEST_URI'] | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |             ) | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |         $this->form_action_url = $this->base_url . '/ext/modules/payment/pagantis/bypass.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     /*************** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * CLASS METHODS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      **************/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     * Here you can implement using payment zones (refer to standard PayPal module as reference) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     public function update_status() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     * Here you may define client side javascript that will verify any input fields you use in the payment method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     * selection page. Refer to standard cc module as reference (cc.php). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     public function javascript_validation() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     * Llamada cuando el usuario esta en la pantalla de eleccion de tipo de pago | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * This function outputs the payment method title/text and if required, the input fields. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     * Si hay un pedido generado previamente y no confirmado, se borra | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     * Caso de uso: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     * - el usuario llega a la pantalla de confirmacion | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     * - se genera el pedido (pero no se genera entrada en orders_status_history) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     * - el usuario decide realizar algun cambio en su compra antes de pasar a pagantis | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     * - entra de nuevo en la pantalla de seleccion de tipo de pago (puede elegir otra forma de pago) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     * - se comprueba que no exista el pedido generado anteriormente | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     * - se borra el pedido que se habia generado inicialmente. Ya no es valido | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     public function selection() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         return array('id' => $this->code, 'module' => $this->title); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     * Use this function implement any checks of any conditions after payment method has been selected. You most probably | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     *  don't need to implement anything here. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     public function pre_confirmation_check() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      * Implement any checks or processing on the order information before proceeding to payment confirmation. You most | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     probably don't need to implement anything here. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     * Llamada cuando el usuario entra en la pantalla de confirmacion | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     * Se genera el pedido: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     * - con el estado predefinido para el modulo pagantis | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     * - sin notificacion a cliente ni administrador | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     * - no se borra el carrito asociado al pedido | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     public function confirmation() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      * This sends the data to the payment gateway for processing. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * (These are hidden fields on the checkout confirmation page) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     public function process_button() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |             include_once('./ext/modules/payment/pagantis/vendor/autoload.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             global $order, $customer_id, $sendto, $billto, $cart, $languages_id, $currency, $currencies, $shipping, $payment, $comments, $customer_default_address_id, $cartID; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             $global_vars = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             $global_vars['customer_id'] = serialize($customer_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             $global_vars['sendTo'] = serialize($sendto); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             $global_vars['billTo'] = serialize($billto); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             $global_vars['cart'] = serialize($cart); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |             $global_vars['languages_id'] = serialize($languages_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             $global_vars['currency'] = serialize($currency); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |             $global_vars['currencies'] = serialize($currencies); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |             $global_vars['shipping'] = serialize($shipping); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             $global_vars['payment'] = serialize($payment); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |             $global_vars['comments'] = serialize($comments); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |             $global_vars['$customer_default_address_id'] = serialize($customer_default_address_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |             $global_vars['cartID'] = serialize($cartID); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |             $global_vars['sessiontoken'] = serialize($_SESSION['sessiontoken']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |             if (!isset($order)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |                 throw new UnknownException("Order not found"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |             $id_hash = time().serialize($order->products).''.serialize($order->customer).''.serialize($order->delivery); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |             $this->os_order_reference = md5($id_hash); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |             $_SESSION['order_id'] = $this->os_order_reference; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |             $userAddress = new Address(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |             $userAddress | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |                 ->setZipCode($order->billing['postcode']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |                 ->setFullName($order->billing['firstname'].' '.$order->billing['lastname']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |                 ->setCountryCode('ES') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |                 ->setCity($order->billing['city']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |                 ->setAddress($order->billing['street_address']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |                 ->setFixPhone($order->customer['telephone']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |                 ->setMobilePhone($order->customer['telephone']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             $orderBillingAddress = $userAddress; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |             $orderShippingAddress = new Address(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |             $orderShippingAddress | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |                 ->setZipCode($order->delivery['postcode']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |                 ->setFullName($order->billing['firstname'].' '.$order->billing['lastname']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |                 ->setCountryCode('ES') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |                 ->setCity($order->delivery['city']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |                 ->setAddress($order->delivery['street_address']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |                 ->setFixPhone($order->customer['telephone']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |                 ->setMobilePhone($order->customer['telephone']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |             $orderUser = new \Pagantis\OrdersApiClient\Model\Order\User(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |             $orderUser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |                 ->setAddress($userAddress) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |                 ->setFullName($order->billing['firstname'].' '.$order->billing['lastname']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |                 ->setBillingAddress($orderBillingAddress) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |                 ->setEmail($order->customer['email_address']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |                 ->setFixPhone($order->customer['telephone']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |                 ->setMobilePhone($order->customer['telephone']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |                 ->setShippingAddress($orderShippingAddress); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |             $previousOrders = $this->getOrders(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |             foreach ((array)$previousOrders as $k => $previousOrder) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |                 $orderHistory = new \Pagantis\OrdersApiClient\Model\Order\User\OrderHistory(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |                 $orderHistory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |                     ->setAmount(intval(100 * $previousOrder['value'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |                     ->setDate(new \DateTime($previousOrder['date_purchased'])) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |                 ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |                 $orderUser->addOrderHistory($orderHistory); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |             $details      = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |             $shippingCost = number_format($order->info['shipping_cost'], 2, '.', ''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |             $details->setShippingCost(intval(strval(100 * $shippingCost))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |             foreach ($order->products as $item) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |                 $product = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details\Product(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |                 $product | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |                     ->setAmount(intval(100 * number_format(($item['final_price'] * $item['qty']), 2))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |                     ->setQuantity(intval($item['qty'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |                     ->setDescription($item['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |                 $details->addProduct($product); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |             $orderShoppingCart = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |             $orderShoppingCart | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |                 ->setDetails($details) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |                 ->setOrderReference($this->os_order_reference) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |                 ->setPromotedAmount(0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |                 ->setTotalAmount(intval($order->info['total'] * 100)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |             $callback_url = $this->base_url.'/ext/modules/payment/pagantis/notify.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |             $checkoutProcessUrl = htmlspecialchars_decode( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |                 tep_href_link(FILENAME_CHECKOUT_PROCESS, "order_id=$this->os_order_reference&from=order", 'SSL', true, false) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |             $cancelUrl              = trim(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL', false)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |             $orderConfigurationUrls = new \Pagantis\OrdersApiClient\Model\Order\Configuration\Urls(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |             $orderConfigurationUrls | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |                 ->setCancel($cancelUrl) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |                 ->setKo($cancelUrl) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |                 ->setAuthorizedNotificationCallback($callback_url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |                 ->setRejectedNotificationCallback($callback_url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |                 ->setOk($checkoutProcessUrl); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |             $orderChannel = new \Pagantis\OrdersApiClient\Model\Order\Configuration\Channel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |             $orderChannel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |                 ->setAssistedSale(false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |                 ->setType(\Pagantis\OrdersApiClient\Model\Order\Configuration\Channel::ONLINE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |             $orderConfiguration = new \Pagantis\OrdersApiClient\Model\Order\Configuration(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |             $orderConfiguration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |                 ->setChannel($orderChannel) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |                 ->setUrls($orderConfigurationUrls); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |             $metadataOrder = new \Pagantis\OrdersApiClient\Model\Order\Metadata(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |             $metadata      = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |                 'oscommerce' => PROJECT_VERSION, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |                 'pagantis'   => $this->version, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |                 'php'        => phpversion() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |             foreach ($metadata as $key => $metadatum) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |                 $metadataOrder->addMetadata($key, $metadatum); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |             $orderApiClient = new \Pagantis\OrdersApiClient\Model\Order(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |             $orderApiClient | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |                 ->setConfiguration($orderConfiguration) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |                 ->setMetadata($metadataOrder) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |                 ->setShoppingCart($orderShoppingCart) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |                 ->setUser($orderUser); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |             $publicKey     = trim(MODULE_PAYMENT_PAGANTIS_PK); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |             $secretKey     = trim(MODULE_PAYMENT_PAGANTIS_SK); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |             $orderClient   = new \Pagantis\OrdersApiClient\Client($publicKey, $secretKey); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |             $pagantisOrder = $orderClient->createOrder($orderApiClient); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |             if ($pagantisOrder instanceof \Pagantis\OrdersApiClient\Model\Order) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |                 $url = $pagantisOrder->getActionUrls()->getForm(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |                 $this->insertRow($this->os_order_reference, $pagantisOrder->getId(), serialize($global_vars)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |                 throw new OrderNotFoundException(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |             if ($url == "") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |                 throw new UnknownException(_("No ha sido posible obtener una respuesta de Pagantis")); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |             } else { //if ($this->extraConfig['PAGANTIS_FORM_DISPLAY_TYPE'] == '0') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |                 $output = "\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |                 $output.= tep_draw_hidden_field("formUrl", $url) . "\n"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |                 $output.= tep_draw_hidden_field("cancelUrl", $cancelUrl) . "\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |                 return $output; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |             } //TODO IFRAME | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |         } catch (\Exception $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |             tep_redirect($cancelUrl); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |     public function before_process() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |         include_once('./ext/modules/payment/pagantis/notifyController.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |         $this->pgNotify = new notifyController(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |         $this->pgNotify->setOscommerceOrderId($_GET['order_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |         $this->pgNotify->setOrigin(isset($_GET['from']) ? ($_GET['from']) : 'order'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |         $this->pgNotify->processInformation(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |     * Post-processing activities | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |     * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |     * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |     public function after_process() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |         $this->pgNotify->confirmInformation(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |     public function output_error() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |     public function check() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |         if (!isset($this->_check)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |             $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAGANTIS_STATUS'"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |             $this->_check = tep_db_num_rows($check_query); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |         $this->installPagantisTables(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |         return $this->_check; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |      * This is where you define module's configurations (displayed in admin). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |     public function install() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |         global $messageStack; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |         if (defined('MODULE_PAYMENT_PAGANTIS_STATUS')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |             tep_redirect(tep_href_link(FILENAME_MODULES, 'set=payment&module=pagantis', 'NONSSL')); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |             return 'failed'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |         tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Pagantis module', 'MODULE_PAYMENT_PAGANTIS_STATUS', 'True', '', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |         tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Public Key', 'MODULE_PAYMENT_PAGANTIS_PK', '', 'MANDATORY. You can get in your pagantis profile', '6', '0', now())"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |         tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Secret Key', 'MODULE_PAYMENT_PAGANTIS_SK', '', 'MANDATORY. You can get in your pagantis profile', '6', '0', now())"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |         $this->installPagantisTables(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |      * Create the neccesary tables for the module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |     private function installPagantisTables() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |         $sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_LOG . " (  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |                           id int NOT NULL AUTO_INCREMENT,  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |                           log text NOT NULL,  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |                           createdAt timestamp DEFAULT CURRENT_TIMESTAMP,  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |                           UNIQUE KEY id (id))"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |         tep_db_query($sql); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |         $sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_CONFIG . " ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |                             id int NOT NULL AUTO_INCREMENT,  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |                             config varchar(60) NOT NULL,  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |                             value varchar(200) NOT NULL,  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |                             UNIQUE KEY id(id))"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |         tep_db_query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |         // check if table has records | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |         $check_query = tep_db_query("select value from " . TABLE_PAGANTIS_CONFIG); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |         if(tep_db_num_rows($check_query) === 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |             foreach ((array)$this->defaultConfigs as $configKey => $configValue) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |                 $query = "INSERT INTO " . TABLE_PAGANTIS_CONFIG . " (config, value) values ('$configKey', '$configValue')"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |                 tep_db_query($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |         $sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_ORDERS . " ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |                             id int NOT NULL AUTO_INCREMENT,  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |                             os_order_id varchar(50),  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |                             os_order_reference varchar(50) NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |                             pagantis_order_id varchar(50) NOT NULL,  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |                             globals text, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |                             UNIQUE KEY id(id))"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |         tep_db_query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |         $sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_CONCURRENCY . " ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |                             id varchar(50) NOT NULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |                             `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |                             UNIQUE KEY id(id))"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |         tep_db_query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |      * Standard functionality to uninstall the module. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |     public function remove() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  |         $checkTable = tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_LOG."'"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  |         if (tep_db_num_rows($checkTable) > 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |             tep_db_query("drop table " . TABLE_PAGANTIS_LOG); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  |         $checkTable = tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_CONFIG."'"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  |         if (tep_db_num_rows($checkTable) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |             tep_db_query("drop table " . TABLE_PAGANTIS_CONFIG); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  |         $checkTable = tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_ORDERS."'"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |         if (tep_db_num_rows($checkTable) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  |             tep_db_query("drop table " . TABLE_PAGANTIS_ORDERS); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |         $checkTable = tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_CONCURRENCY."'"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  |         if (tep_db_num_rows($checkTable) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  |             tep_db_query("drop table " . TABLE_PAGANTIS_CONCURRENCY); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  |         $query = "delete from ".TABLE_ORDERS_STATUS." where orders_status_id='6'"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |         tep_db_query($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  |     * Internal list of configuration keys used for configuration of the module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  |     * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  |     * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |     public function keys() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |         return array('MODULE_PAYMENT_PAGANTIS_STATUS', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  |            'MODULE_PAYMENT_PAGANTIS_PK', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |            'MODULE_PAYMENT_PAGANTIS_SK' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  |            ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  |     private function getOrders() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  |         $this->is_guest = 'true'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  |         if (trim($_SESSION['customer_id']) != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  |             $this->is_guest = 'false'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  |             $query = sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  |                 "select orders_total.value, orders.date_purchased from orders  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  | JOIN orders_status_history ON orders.orders_id=orders_status_history.orders_id  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  | JOIN orders_total ON orders.orders_id=orders_total.orders_id  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  | where orders.customers_id='%s' and orders_status_history.orders_status_id in ('2','3') and orders_total.class='ot_total'", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  |                 $_SESSION['customer_id'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |             $response = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  |             $resultsSelect = tep_db_query($query); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  |             while ($orderRow = tep_db_fetch_array($resultsSelect)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  |                 $response[] = $orderRow; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  |         return $response; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  |      * @param $orderId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  |      * @param $pagantisOrderId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  |      * @param $globalVars | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  |     private function insertRow($orderId, $pagantisOrderId, $globalVars) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  |         $query = "select * from ". TABLE_PAGANTIS_ORDERS ." where os_order_reference='$orderId'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  |         $resultsSelect = tep_db_query($query); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  |         $countResults = tep_db_num_rows($resultsSelect); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  |         if ($countResults == 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  |             $query = "INSERT INTO ". TABLE_PAGANTIS_ORDERS ."(os_order_reference, pagantis_order_id, globals) values ('$orderId', '$pagantisOrderId','$globalVars')"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  |             $query = "UPDATE " . TABLE_PAGANTIS_ORDERS . " set pagantis_order_id='$pagantisOrderId' where os_order_reference='$orderId'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  |         tep_db_query($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 492 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 493 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 494 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 495 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 496 |  |  |     private function getExtraConfig() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 497 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  |         $checkTable = tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS."'"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  |         $response = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  |         if (tep_db_num_rows($checkTable) > 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  |             $query       = "select * from ".TABLE_PAGANTIS_CONFIG; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  |             $result      = tep_db_query($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  |             $resultArray = tep_db_fetch_array($result); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  |             $response    = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  |             foreach ((array)$resultArray as $key => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  |                 $response[$key] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  |         return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 512 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 513 |  |  |  |