function execPayment($cart)
 {
     global $cart;
     global $smarty;
     $invoice_address = new Address((int) $cart->id_address_invoice);
     if ($invoice_address->id_country == 110) {
         return;
     }
     $curr_currency = CurrencyCore::getCurrency($cart->id_currency);
     if ((int) $curr_currency['paypal_support'] === 1) {
         return;
     }
     $delivery = new Address(intval($cart->id_address_delivery));
     $invoice = new Address(intval($cart->id_address_invoice));
     $customer = new Customer(intval($cart->id_customer));
     global $cookie, $smarty;
     //Verify currencies and display payment form
     $currencies = Currency::getCurrencies();
     $authorized_currencies = array_flip(explode(',', $this->currencies));
     $currencies_used = array();
     foreach ($currencies as $key => $currency) {
         if (isset($authorized_currencies[$currency['id_currency']])) {
             $currencies_used[] = $currencies[$key];
         }
     }
     $smarty->assign('currencies_used', $currencies_used);
     $products = $cart->getProducts();
     foreach ($products as $key => $product) {
         $products[$key]['name'] = str_replace('"', '\'', $product['name']);
         $products[$key]['name'] = htmlentities(utf8_decode($product['name']));
     }
     $CheckoutUrl = 'https://www.2checkout.com/checkout/spurchase';
     $x_receipt_link_url = 'http://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/checkout/validation.php';
     $sid = Configuration::get('CHECKOUT_SID');
     $total = number_format($cart->getOrderTotal(true, 3), 0, '.', '');
     $cart_order_id = $cart->id;
     $email = $customer->email;
     $secure_key = $customer->secure_key;
     $demo = "Y";
     // Change to "Y" for demo mode
     $outside_state = "XX";
     // This will pre-select Outside USA and Canada, if state does not exist
     // Invoice Parameters
     $card_holder_name = $invoice->firstname . ' ' . $invoice->lastname;
     $street_address = $invoice->address1;
     $street_address2 = $invoice->address2;
     $phone = $invoice->phone_mobile;
     $city = $invoice->city;
     $state = (Validate::isLoadedObject($invoice) and $invoice->id_state) ? new State(intval($invoice->id_state)) : false;
     $zip = $invoice->postcode;
     $country = $invoice->country;
     // Shipping Parameters
     $ship_name = $delivery->firstname . ' ' . $invoice->lastname;
     $ship_street_address = $delivery->address1;
     $ship_street_address2 = $delivery->address2;
     $ship_city = $delivery->city;
     $ship_state = (Validate::isLoadedObject($delivery) and $delivery->id_state) ? new State(intval($delivery->id_state)) : false;
     $ship_zip = $delivery->postcode;
     $ship_country = $delivery->country;
     if ($cart->id_currency != 2) {
         $total = Tools::convertPrice($total, $cart->id_currency, false);
         $this_currency = CurrencyCore::getCurrency($cart->id_currency);
         $curr_conversion_msg = "<p>Dear Customer, we do not accept payments in <b>{$this_currency['name']}</b>, we will process the equivalent amount of <b>" . Tools::displayPrice($total, 2) . "</b> in USD(United States Dollar).</p> <p>The currency conversion rates are provided by openexchangerates.org</p>";
         $smarty->assign("curr_conversion_msg", $curr_conversion_msg);
     }
     $total = round($total);
     $smarty->assign(array('CheckoutUrl' => $CheckoutUrl, 'return_url' => $return_url, 'sid' => $sid, 'total' => $total, 'cart_order_id' => $cart_order_id, 'email' => $email, 'demo' => $demo, 'outside_state' => $outside_state, 'secure_key' => $secure_key, 'card_holder_name' => $card_holder_name, 'street_address' => $street_address, 'street_address2' => $street_address2, 'phone' => $phone, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country, 'ship_name' => $ship_name, 'ship_street_address' => $ship_street_address, 'ship_street_address2' => $ship_street_address2, 'ship_city' => $ship_city, 'ship_state' => $ship_state, 'ship_zip' => $ship_zip, 'ship_country' => $ship_country, 'products' => $products, 'x_receipt_link_url' => $x_receipt_link_url, 'TotalAmount' => number_format($total), 'this_path' => $this->_path, 'this_path_ssl' => Configuration::get('PS_FO_PROTOCOL') . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . "modules/{$this->name}/"));
     /* Complementos */
     $cart = new Cart($cookie->id_cart);
     $address = new Address($cart->id_address_delivery, intval($cookie->id_lang));
     $state = State::getNameById($address->id_state);
     $state = $state ? '(' . $state . ')' : '';
     $str_address = ($address->company ? $address->company . '<br>' : '') . $address->firstname . ' ' . $address->lastname . '<br>' . $address->address1 . '<br>' . ($address->address2 ? $address->address2 . '<br>' : '') . $address->postcode . ' ' . $address->city . '<br>' . $address->country . $state;
     $smarty->assign('address', $str_address);
     $carrier = Carrier::getCarriers(intval($cookie->id_lang));
     if ($carrier) {
         foreach ($carrier as $c) {
             if ($cart->id_carrier == $c[id_carrier]) {
                 $smarty->assign('carrier', $c['name']);
                 break;
             }
         }
     }
     /* FIN Complementos */
     return $this->display(__FILE__, 'payment_execution.tpl');
 }
 public function addressImport()
 {
     $this->receiveTab();
     $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
     $handle = $this->openCsvFile();
     AdminImportController::setLocale();
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
         if (Tools::getValue('convert')) {
             $line = $this->utf8EncodeArray($line);
         }
         $info = AdminImportController::getMaskedRow($line);
         AdminImportController::setDefaultValues($info);
         $address = new Address();
         AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $address);
         if (isset($address->country) && is_numeric($address->country)) {
             if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) {
                 $address->id_country = (int) $address->country;
             }
         } elseif (isset($address->country) && is_string($address->country) && !empty($address->country)) {
             if ($id_country = Country::getIdByName(null, $address->country)) {
                 $address->id_country = (int) $id_country;
             } else {
                 $country = new Country();
                 $country->active = 1;
                 $country->name = AdminImportController::createMultiLangField($address->country);
                 $country->id_zone = 0;
                 // Default zone for country to create
                 $country->iso_code = Tools::strtoupper(Tools::substr($address->country, 0, 2));
                 // Default iso for country to create
                 $country->contains_states = 0;
                 // Default value for country to create
                 $lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
                 if (($field_error = $country->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $country->add()) {
                     $address->id_country = (int) $country->id;
                 } else {
                     $this->errors[] = sprintf(Tools::displayError('%s cannot be saved'), $country->name[$default_language_id]);
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
         if (isset($address->state) && is_numeric($address->state)) {
             if (State::getNameById((int) $address->state)) {
                 $address->id_state = (int) $address->state;
             }
         } elseif (isset($address->state) && is_string($address->state) && !empty($address->state)) {
             if ($id_state = State::getIdByName($address->state)) {
                 $address->id_state = (int) $id_state;
             } else {
                 $state = new State();
                 $state->active = 1;
                 $state->name = $address->state;
                 $state->id_country = isset($country->id) ? (int) $country->id : 0;
                 $state->id_zone = 0;
                 // Default zone for state to create
                 $state->iso_code = Tools::strtoupper(Tools::substr($address->state, 0, 2));
                 // Default iso for state to create
                 $state->tax_behavior = 0;
                 if (($field_error = $state->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $state->add()) {
                     $address->id_state = (int) $state->id;
                 } else {
                     $this->errors[] = sprintf(Tools::displayError('%s cannot be saved'), $state->name);
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
         if (isset($address->customer_email) && !empty($address->customer_email)) {
             if (Validate::isEmail($address->customer_email)) {
                 // a customer could exists in different shop
                 $customer_list = Customer::getCustomersByEmail($address->customer_email);
                 if (count($customer_list) == 0) {
                     $this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be saved.'), Db::getInstance()->getMsgError(), $address->customer_email, isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
                 }
             } else {
                 $this->errors[] = sprintf(Tools::displayError('"%s" is not a valid email address.'), $address->customer_email);
                 continue;
             }
         } elseif (isset($address->id_customer) && !empty($address->id_customer)) {
             if (Customer::customerIdExistsStatic((int) $address->id_customer)) {
                 $customer = new Customer((int) $address->id_customer);
                 // a customer could exists in different shop
                 $customer_list = Customer::getCustomersByEmail($customer->email);
                 if (count($customer_list) == 0) {
                     $this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be saved.'), Db::getInstance()->getMsgError(), $customer->email, (int) $address->id_customer);
                 }
             } else {
                 $this->errors[] = sprintf(Tools::displayError('The customer ID #%d does not exist in the database, and therefore cannot be saved.'), $address->id_customer);
             }
         } else {
             $customer_list = array();
             $address->id_customer = 0;
         }
         if (isset($address->manufacturer) && is_numeric($address->manufacturer) && Manufacturer::manufacturerExists((int) $address->manufacturer)) {
             $address->id_manufacturer = (int) $address->manufacturer;
         } elseif (isset($address->manufacturer) && is_string($address->manufacturer) && !empty($address->manufacturer)) {
             $manufacturer = new Manufacturer();
             $manufacturer->name = $address->manufacturer;
             if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) {
                 $address->id_manufacturer = (int) $manufacturer->id;
             } else {
                 $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
                 $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
             }
         }
         if (isset($address->supplier) && is_numeric($address->supplier) && Supplier::supplierExists((int) $address->supplier)) {
             $address->id_supplier = (int) $address->supplier;
         } elseif (isset($address->supplier) && is_string($address->supplier) && !empty($address->supplier)) {
             $supplier = new Supplier();
             $supplier->name = $address->supplier;
             if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $supplier->add()) {
                 $address->id_supplier = (int) $supplier->id;
             } else {
                 $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $supplier->name, isset($supplier->id) && !empty($supplier->id) ? $supplier->id : 'null');
                 $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
             }
         }
         $res = false;
         if (($field_error = $address->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $address->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
             if (isset($customer_list) && count($customer_list) > 0) {
                 $filter_list = array();
                 foreach ($customer_list as $customer) {
                     if (in_array($customer['id_customer'], $filter_list)) {
                         continue;
                     }
                     $filter_list[] = $customer['id_customer'];
                     unset($address->id);
                     $address->id_customer = $customer['id_customer'];
                     $res = $address->add();
                     if (!$res) {
                         $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $info['alias'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
                     }
                 }
             } else {
                 $address->force_id = (bool) Tools::getValue('forceIDs');
                 if ($address->id && $address->addressExists($address->id)) {
                     $res = $address->update();
                 }
                 if (!$res) {
                     $res = $address->add();
                 }
             }
         }
         if (!$res) {
             $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $info['alias'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
             $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
         }
     }
     $this->closeCsvFile($handle);
 }
Exemple #3
0
 public function hookPayment($params)
 {
     global $cookie;
     $this->_validateErrors = array();
     session_start();
     $_SESSION['params1'] = '';
     $_SESSION['cart_currency'] = '';
     $_SESSION['cart_amount'] = '';
     $_SESSION['params1'] = $params;
     if (!$this->active) {
         return;
     }
     global $smarty;
     $address = new Address(intval($params['cart']->id_address_invoice));
     $customer = new Customer(intval($params['cart']->id_customer));
     $merchant_id = trim(Configuration::get('CCAVENUE_MERCHANT_ID'));
     $access_code = trim(Configuration::get('CCAVENUE_ACCESS_CODE'));
     $encryption_key = trim(Configuration::get('CCAVENUE_ENCRYPTION_KEY'));
     $ccavenue_title = trim(Configuration::get('CCAVENUE_TITLE'));
     $Redirect_Url = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/ccavenue/validation.php';
     $Cancel_Url = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/ccavenue/validation.php';
     $language = 'EN';
     $currency = $this->getCurrency('INR');
     $OrderId = date('Ymdhis') . '-' . intval($params['cart']->id);
     $Amount = $params['cart']->getOrderTotal(true, 3);
     $_SESSION['cart_amount'] = $Amount;
     $default_currency_support_ccavnenue = 'INR';
     $default_currency_id = Db::getInstance()->getValue("\n\t\t\t\t\t\tSELECT `id_currency`\n\t\t\t\t\t\tFROM `" . _DB_PREFIX_ . "currency`\n\t\t\t\t\t\tWHERE `iso_code` = '" . $default_currency_support_ccavnenue . "'");
     $base_currency_id = Configuration::get('PS_CURRENCY_DEFAULT');
     $default_currency = new Currency((int) $default_currency_id);
     $base_currency = new Currency((int) $base_currency_id);
     $base_currency_code = $base_currency->iso_code;
     $current_currency = new Currency((int) $params['cart']->id_currency);
     $_SESSION['cart_currency'] = $params['cart']->id_currency;
     $current_currency_code = $current_currency->iso_code;
     $billing_name = $address->firstname . $address->lastname;
     $billing_address = $address->address1 . $address->address2;
     $billing_city = $address->city;
     $billing_zip = $address->postcode;
     $billing_tel = $address->phone;
     $billing_email = $customer->email;
     $country = new Country(intval($address->id_country));
     $state = new State(intval($address->id_state));
     $billing_state = $state->getNameById($address->id_state);
     $land_id = $params['cart']->id_lang;
     $billing_country = $country->getNameById($land_id, $address->id_country);
     $merchant_param1 = (int) $params['cart']->id;
     $merchant_param2 = date('YmdHis');
     $merchant_param3 = $params['cart']->secure_key;
     $cust_notes_message = Message::getMessageByCartId(intval($params['cart']->id));
     $cust_notes = $cust_notes_message['message'];
     $billing_cust_notes = $cust_notes;
     $delivery_name = '';
     $delivery_address = '';
     $delivery_city = '';
     $delivery_state = '';
     $delivery_tel = '';
     $delivery_zip = '';
     $delivery_country = '';
     $delivery_name = $address->firstname . $address->lastname;
     $delivery_address = $address->address1 . $address->address2;
     $delivery_city = $address->city;
     $delivery_zip = $address->postcode;
     $delivery_tel = $address->phone;
     $delivery_state = $billing_state;
     $delivery_country = $billing_country;
     $merchant_data_array = array();
     $merchant_data_array['merchant_id'] = $merchant_id;
     $merchant_data_array['order_id'] = $OrderId;
     $merchant_data_array['currency'] = 'INR';
     $merchant_data_array['amount'] = $Amount;
     $merchant_data_array['redirect_url'] = $Redirect_Url;
     $merchant_data_array['cancel_url'] = $Cancel_Url;
     $merchant_data_array['language'] = $language;
     $merchant_data_array['billing_name'] = $billing_name;
     $merchant_data_array['billing_address'] = $billing_address;
     $merchant_data_array['billing_city'] = $billing_city;
     $merchant_data_array['billing_state'] = $billing_state;
     $merchant_data_array['billing_zip'] = $billing_zip;
     $merchant_data_array['billing_country'] = $billing_country;
     $merchant_data_array['billing_tel'] = $billing_tel;
     $merchant_data_array['billing_email'] = $billing_email;
     $merchant_data_array['delivery_name'] = $delivery_name;
     $merchant_data_array['delivery_address'] = $delivery_address;
     $merchant_data_array['delivery_city'] = $delivery_city;
     $merchant_data_array['delivery_state'] = $delivery_state;
     $merchant_data_array['delivery_zip'] = $delivery_zip;
     $merchant_data_array['delivery_country'] = $delivery_country;
     $merchant_data_array['delivery_tel'] = $delivery_tel;
     $merchant_data_array['merchant_param1'] = $merchant_param1;
     $merchant_data_array['merchant_param2'] = $merchant_param2;
     $merchant_data_array['merchant_param3'] = $merchant_param3;
     $merchant_data = implode("&", $merchant_data_array);
     $ccavenue_post_data = '';
     $ccavenue_post_data_array = array();
     foreach ($merchant_data_array as $key => $value) {
         $ccavenue_post_data_array[] .= $key . '=' . urlencode($value);
     }
     $ccavenue_post_data = implode("&", $ccavenue_post_data_array);
     $encrypted_data = $this->encrypt($ccavenue_post_data, $encryption_key);
     $smarty->assign(array('ccavenueUrl' => $this->getccavenueUrl(), 'ccavenue_title' => $ccavenue_title, 'encRequest' => $encrypted_data, 'access_code' => $access_code));
     $ccavenue_payment_error_status = '';
     $ccavenue_error_message = '';
     if ($cookie->__get("ccavenue_validate_error_message")) {
         $ccavenue_error_message = $cookie->__get("ccavenue_validate_error_message");
     }
     if ($ccavenue_error_message != '') {
         $ccavenue_payment_error_status = 'ERROR';
     }
     $smarty->assign('payment_status', $ccavenue_payment_error_status);
     $smarty->assign('message', $ccavenue_error_message);
     return $this->display(__FILE__, 'payccavenue.tpl');
 }
Exemple #4
0
 public static function getAddress(Address $address)
 {
     return array('first_name' => $address->firstname, 'last_name' => $address->lastname, 'phone' => $address->phone, 'alt_phone' => $address->phone_mobile, 'street' => $address->address1, 'address_addition' => $address->address2, 'city' => $address->city, 'state' => State::getNameById($address->id_state), 'country' => Country::getIsoById($address->id_country), 'postcode' => $address->postcode);
 }
Exemple #5
0
 public function hookPayment($params)
 {
     global $cart;
     global $smarty, $cart, $cookie;
     $invoice_address = new Address((int) $cart->id_address_invoice);
     $key = Configuration::get('PAYU_MERCHANT_ID');
     $salt = Configuration::get('PAYU_SALT');
     if (!$this->active) {
         return;
     }
     $mode = Configuration::get('PAYU_MODE');
     $log = Configuration::get('PAYU_LOGS');
     $amount = $cart->getOrderTotal(true, Cart::BOTH);
     $curr_currency = CurrencyCore::getCurrency($cart->id_currency);
     if ($invoice_address->id_country == 110) {
         $key = 'VLBB6Z';
         $salt = 'KQUxLUkT';
         if ($cart->id_currency != 4) {
             //convert to USD(default)
             $amount = Tools::convertPrice($amount, $cart->id_currency, false);
             //convert to INT
             $amount = Tools::convertPrice($amount, 4);
             $inr_currency = CurrencyCore::getCurrency(4);
             $curr_conversion_msg = "<p>Dear Customer, any order with an Indian billing address entails processing of the order value in {$inr_currency['iso_code']} ({$inr_currency['name']}). The order value of <b>" . Tools::displayPrice($amount, 4) . "</b> will be processed.</p><p>Currency conversion rates are provided by  openexchangerates.org</p>";
             $smarty->assign("curr_conversion_msg", $curr_conversion_msg);
         }
     } else {
         if ((int) $curr_currency['paypal_support'] === 1 && $cart->id_currency != 2) {
             //For all Paypal supported curencies except USD, we dont show PayU
             return;
         } else {
             if ($cart->id_currency != 2) {
                 // Currency not supported by Paypal and not USD, convert to USD and proceed
                 $amount = Tools::convertPrice($amount, $cart->id_currency, false);
                 $this_currency = CurrencyCore::getCurrency($cart->id_currency);
                 $curr_conversion_msg = "<p>Unfortunately we are unable to accept payments in <b>{$this_currency['name']}</b>.</p> <p>An equivalent order value of USD <b>" . Tools::displayPrice($amount, 2) . "</b> will be processed.</p>";
                 $smarty->assign("curr_conversion_msg", $curr_conversion_msg);
             }
         }
     }
     $amount = round($amount);
     //else
     //return;
     //convert to INR if the currency is not
     //if ($cart->id_currency != 4)
     //$amount = Tools::convertPrice($amount, 4, true);
     $customer = new Customer((int) $cart->id_customer);
     $action = 'https://test.payu.in/_payment.php';
     $txnid = $cart->id;
     $productInfo = 'Payu product information';
     $firstname = $customer->firstname;
     $Lastname = $customer->lastname;
     $deloveryAddress = new Address((int) $cart->id_address_invoice);
     $Zipcode = $deloveryAddress->postcode;
     $email = $customer->email;
     $phone = $deloveryAddress->phone;
     $deloveryAddress->country = Country::getNameById(1, $deloveryAddress->id_country);
     $deloveryAddress->state = State::getNameById($deloveryAddress->id_state);
     if ($mode == 'real') {
         $action = 'https://secure.payu.in/_payment.php';
     }
     $request = $key . '|' . $txnid . '|' . $amount . '|' . $productInfo . '|' . $firstname . '|' . $email . '|||||||||||' . $salt;
     $Hash = hash('sha512', $key . '|' . $txnid . '|' . $amount . '|' . $productInfo . '|' . $firstname . '|' . $email . '|||||||||||' . $salt);
     $baseUrl = Tools::getShopDomain(true, true) . __PS_BASE_URI__;
     if ($log == 1) {
         $query = "insert into ps_payu_order(id_order,payment_request) values({$orderId},'{$request}')";
         Db::getInstance()->Execute($query);
     }
     $surl = $baseUrl . 'modules/' . $this->name . '/success.php';
     $curl = $baseUrl . 'modules/' . $this->name . '/failure.php';
     $Furl = $baseUrl . 'modules/' . $this->name . '/failure.php';
     $Pg = 'CC';
     $payuInfo = array('action' => $action, 'key' => $key, 'txnid' => $txnid, 'amount' => $amount, 'productinfo' => $productInfo, 'firstname' => $firstname, 'Lastname' => $Lastname, 'Zipcode' => $Zipcode, 'email' => $email, 'phone' => $phone, 'surl' => $surl, 'Furl' => $Furl, 'curl' => $curl, 'Hash' => $Hash, 'Pg' => $Pg, 'deliveryAddress' => $deloveryAddress);
     $smarty->assign('Message', 'Please wait, you will be redirected to payu website');
     $smarty->assign($payuInfo);
     return $this->display(__FILE__, 'payu.tpl');
 }
Exemple #6
0
 /**
  * Return useful informations for cart
  *
  * @return array Cart details
  */
 function getSummaryDetails()
 {
     global $cookie;
     $delivery = new Address((int) $this->id_address_delivery);
     $invoice = new Address((int) $this->id_address_invoice);
     // New layout system with personalization fields
     $formattedAddresses['invoice'] = AddressFormat::getFormattedLayoutData($invoice);
     $formattedAddresses['delivery'] = AddressFormat::getFormattedLayoutData($delivery);
     $total_tax = $this->getOrderTotal() - $this->getOrderTotal(false);
     if ($total_tax < 0) {
         $total_tax = 0;
     }
     $total_free_ship = 0;
     if ($free_ship = Tools::convertPrice((double) Configuration::get('PS_SHIPPING_FREE_PRICE'), new Currency((int) $this->id_currency))) {
         $discounts = $this->getDiscounts();
         $total_free_ship = $free_ship - ($this->getOrderTotal(true, Cart::ONLY_PRODUCTS) + $this->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
         foreach ($discounts as $discount) {
             if ($discount['id_discount_type'] == 3) {
                 $total_free_ship = 0;
                 break;
             }
         }
     }
     return array('delivery' => $delivery, 'delivery_state' => State::getNameById($delivery->id_state), 'invoice' => $invoice, 'invoice_state' => State::getNameById($invoice->id_state), 'formattedAddresses' => $formattedAddresses, 'carrier' => new Carrier((int) $this->id_carrier, $cookie->id_lang), 'products' => $this->getProducts(false), 'discounts' => $this->getDiscounts(false, true), 'is_virtual_cart' => (int) $this->isVirtualCart(), 'total_discounts' => $this->getOrderTotal(true, Cart::ONLY_DISCOUNTS), 'total_discounts_tax_exc' => $this->getOrderTotal(false, Cart::ONLY_DISCOUNTS), 'total_wrapping' => $this->getOrderTotal(true, Cart::ONLY_WRAPPING), 'total_wrapping_tax_exc' => $this->getOrderTotal(false, Cart::ONLY_WRAPPING), 'total_shipping' => $this->getOrderShippingCost(), 'total_shipping_tax_exc' => $this->getOrderShippingCost(NULL, false), 'total_products_wt' => $this->getOrderTotal(true, Cart::ONLY_PRODUCTS), 'total_products' => $this->getOrderTotal(false, Cart::ONLY_PRODUCTS), 'total_price' => $this->getOrderTotal(), 'total_tax' => $total_tax, 'total_price_without_tax' => $this->getOrderTotal(false), 'free_ship' => $total_free_ship);
 }
 /**
  * Set the values of the fields that will be exported
  *
  * @param array $kiala_order content of the KialaOrder object
  * @return array|bool fields to be exported or false
  */
 public function initRecordData($kiala_order, $dspid)
 {
     if (!Validate::isLoadedObject($kiala_order)) {
         return false;
     }
     $order = new Order($kiala_order->id_order);
     $cart = new Cart($order->id_cart);
     $customer = new Customer($kiala_order->id_customer);
     $address = new Address($order->id_address_delivery);
     if (!Validate::isLoadedObject($order) || !Validate::isLoadedObject($customer) || !Validate::isLoadedObject($address)) {
         return false;
     }
     $products = $cart->getProducts();
     $width = 1;
     $height = 1;
     $depth = 1;
     foreach ($products as $product) {
         $width = $width < $product['width'] ? $product['width'] : $width;
         $height = $height < $product['height'] ? $product['height'] : $height;
         $depth = $depth < $product['depth'] ? $product['depth'] : $depth;
     }
     // volume in liters
     $volume = $width * $height * $depth / 1000;
     if ($volume < 1) {
         $volume = 1;
     }
     $prefix = Configuration::get('KIALA_NUMBER_PREFIX');
     $fields = array();
     $fields['partnerId']['value'] = $dspid;
     // Parcel information
     $fields['parcelBarcode']['value'] = '';
     $fields['parcelNumber']['value'] = $prefix . $kiala_order->id;
     $fields['orderNumber']['value'] = $prefix . $kiala_order->id;
     $fields['orderDate']['value'] = $this->formatDate($order->date_add);
     $fields['invoiceNumber']['value'] = $order->invoice_number ? $order->invoice_number : '';
     $fields['invoiceDate']['value'] = $this->formatDate($order->invoice_date);
     $fields['shipmentNumber']['value'] = '';
     // @todo Need to check currency = EUR
     if ($order->module == 'cashondelivery') {
         $cod_amount = $order->total_paid;
     } else {
         $cod_amount = '0';
     }
     $fields['CODAmount']['value'] = sprintf('%.2f', $cod_amount);
     $fields['CODCurrency']['value'] = 'EUR';
     $fields['commercialValue']['value'] = sprintf('%.2f', $kiala_order->commercialValue);
     $fields['commercialCurrency']['value'] = 'EUR';
     $fields['parcelWeight']['value'] = sprintf('%.3f', $order->getTotalWeight());
     $fields['parcelVolume']['value'] = sprintf('%.3f', $volume);
     $fields['parcelDescription']['value'] = $kiala_order->parcelDescription;
     // Point information
     $fields['kialaPoint']['value'] = $kiala_order->point_short_id;
     $fields['backupKialaPoint']['value'] = '';
     // Recipient information
     $fields['customerId']['value'] = $customer->id;
     $fields['customerName']['value'] = $customer->lastname;
     $fields['customerFirstName']['value'] = $customer->firstname;
     switch ($customer->id_gender) {
         case '1':
             $title = $this->kiala_instance->l('Mr.');
             break;
         case '2':
             $title = $this->kiala_instance->l('Ms.');
             break;
         default:
             $title = '';
     }
     $fields['customerTitle']['value'] = $title;
     $fields['customerExtraAddressLine']['value'] = $address->address2;
     $fields['customerStreet']['value'] = $address->address1;
     $fields['customerStreetNumber']['value'] = '';
     $fields['customerLocality']['value'] = State::getNameById($address->id_state);
     $fields['customerZip']['value'] = $address->postcode;
     $fields['customerCity']['value'] = $address->city;
     $fields['customerCountry']['value'] = Country::getIsoById($address->id_country);
     $fields['customerLanguage']['value'] = strtolower(Language::getIsoById($order->id_lang));
     $fields['positiveNotificationRequested']['value'] = 'Y';
     $fields['customerPhone1']['value'] = $address->phone;
     $fields['customerPhone2']['value'] = $address->phone_mobile;
     $fields['customerPhone3']['value'] = '';
     $fields['customerEmail1']['value'] = $customer->email;
     $fields['customerEmail2']['value'] = '';
     $fields['customerEmail3']['value'] = '';
     return $fields;
 }
 function processPayment($token)
 {
     include dirname(__FILE__) . '/lib/Twocheckout/TwocheckoutApi.php';
     $cart = $this->context->cart;
     $user = $this->context->customer;
     $delivery = new Address(intval($cart->id_address_delivery));
     $invoice = new Address(intval($cart->id_address_invoice));
     $customer = new Customer(intval($cart->id_customer));
     $currencies = Currency::getCurrencies();
     $authorized_currencies = array_flip(explode(',', $this->currencies));
     $currencies_used = array();
     foreach ($currencies as $key => $currency) {
         if (isset($authorized_currencies[$currency['id_currency']])) {
             $currencies_used[] = $currencies[$key];
         }
     }
     foreach ($currencies_used as $currency) {
         if ($currency['id_currency'] == $cart->id_currency) {
             $order_currency = $currency['iso_code'];
         }
     }
     try {
         $params = array("sellerId" => Configuration::get('TWOCHECKOUT_SID'), "merchantOrderId" => $cart->id, "token" => $token, "currency" => $order_currency, "total" => number_format($cart->getOrderTotal(true, 3), 2, '.', ''), "billingAddr" => array("name" => $invoice->firstname . ' ' . $invoice->lastname, "addrLine1" => $invoice->address1, "addrLine2" => $invoice->address2, "city" => $invoice->city, "state" => $invoice->country == "United States" || $invoice->country == "Canada" ? State::getNameById($invoice->id_state) : 'XX', "zipCode" => $invoice->postcode, "country" => $invoice->country, "email" => $customer->email, "phoneNumber" => $invoice->phone));
         if ($delivery) {
             $shippingAddr = array("name" => $delivery->firstname . ' ' . $delivery->lastname, "addrLine1" => $delivery->address1, "addrLine2" => $delivery->address2, "city" => $delivery->city, "state" => (Validate::isLoadedObject($delivery) and $delivery->id_state) ? new State(intval($delivery->id_state)) : 'XX', "zipCode" => $delivery->postcode, "country" => $delivery->country);
             array_merge($shippingAddr, $params);
         }
         if (Configuration::get('TWOCHECKOUT_SANDBOX')) {
             TwocheckoutApi::setCredentials(Configuration::get('TWOCHECKOUT_SID'), Configuration::get('TWOCHECKOUT_PRIVATE'), 'sandbox');
         } else {
             TwocheckoutApi::setCredentials(Configuration::get('TWOCHECKOUT_SID'), Configuration::get('TWOCHECKOUT_PRIVATE'));
         }
         $charge = Twocheckout_Charge::auth($params);
     } catch (Twocheckout_Error $e) {
         $message = 'Payment Authorization Failed';
         Tools::redirect('index.php?controller=order&step=3&twocheckouterror=' . $message);
     }
     if (isset($charge['response']['responseCode'])) {
         $order_status = (int) Configuration::get('TWOCHECKOUT_ORDER_STATUS');
         $message = $charge['response']['responseMsg'];
         $this->validateOrder((int) $this->context->cart->id, _PS_OS_PAYMENT_, $charge['response']['total'], $this->displayName, $message, array(), null, false, $this->context->customer->secure_key);
         Tools::redirect('index.php?controller=order-confirmation?key=' . $user->secure_key . '&id_cart=' . (int) $cart->id . '&id_module=' . (int) $this->module->id . '&id_order=' . (int) $this->module->currentOrder);
     } else {
         $message = 'Payment Authorization Failed';
         Tools::redirect('index.php?controller=order&step=3&twocheckouterror=' . $message);
     }
 }
 /**
  * @param $module
  * @return array
  */
 protected static function getTaxRates($module)
 {
     $taxRates = array();
     $taxRuleGroups = TaxRulesGroup::getTaxRulesGroups(true);
     foreach ($taxRuleGroups as $taxRuleGroup) {
         if (version_compare(_PS_VERSION_, '1.5.0.1', '<')) {
             $taxRules = TaxRule::getTaxRulesByGroupId($taxRuleGroup['id_tax_rules_group']);
         } else {
             $taxRules = TaxRule::getTaxRulesByGroupId($module->context->language->id, $taxRuleGroup['id_tax_rules_group']);
         }
         // $idCountry is only relevant for Prestashop versions <1.5.0.1
         foreach ($taxRules as $idCountry => $taxRuleItem) {
             $resultTaxRate = array();
             $resultTaxRate['zipcode_type'] = 'all';
             if (version_compare(_PS_VERSION_, '1.5.0.1', '>=')) {
                 $taxRuleItemTmp = new TaxRule($taxRuleItem['id_tax_rule']);
                 $idCountry = $taxRuleItemTmp->id_country;
                 $idState = $taxRuleItemTmp->id_state;
                 $idTax = $taxRuleItemTmp->id_tax;
                 if (!empty($taxRuleItemTmp->zipcode_from) && !empty($taxRuleItemTmp->zipcode_to)) {
                     $resultTaxRate['zipcode_type'] = 'range';
                     $resultTaxRate['zipcode_range_from'] = $taxRuleItemTmp->zipcode_from ? $taxRuleItemTmp->zipcode_from : null;
                     $resultTaxRate['zipcode_range_to'] = $taxRuleItemTmp->zipcode_to ? $taxRuleItemTmp->zipcode_to : null;
                 }
             } else {
                 $idTax = self::getTaxIdFromTaxRule($taxRuleItem);
                 $idState = key($taxRuleItem);
             }
             /** @var TaxCore $taxItem */
             $taxItem = new Tax($idTax, $module->context->language->id);
             $country = Country::getIsoById($idCountry);
             if (version_compare(_PS_VERSION_, '1.5.0.1', '<')) {
                 $state = State::getNameById($idState);
             } else {
                 $stateModel = new State($idState);
                 $state = $stateModel->iso_code;
             }
             $resultTaxRate['key'] = self::getTaxRateKey($taxItem, $country, $state);
             //Fix for 1.4.x.x the taxes were exported multiple
             if (version_compare(_PS_VERSION_, '1.5.0', '<') && self::arrayValueExists('key', $resultTaxRate['key'], $taxRates)) {
                 continue;
             }
             if (!is_string($country)) {
                 $country = '';
             }
             $resultTaxRate['display_name'] = $taxItem->name;
             $resultTaxRate['tax_percent'] = $taxItem->rate;
             $resultTaxRate['country'] = $country;
             $resultTaxRate['state'] = !empty($state) ? $country . '-' . $state : null;
             if ($taxItem->active && Configuration::get('PS_TAX') == 1) {
                 $taxRates[] = $resultTaxRate;
             }
         }
     }
     return $taxRates;
 }
 public function hookDisplayAdminOrder($params)
 {
     if (!$this->hasShiptomyidOption($params['id_order'])) {
         return;
     }
     $shipto_order = ShiptomyidOrder::getByIdOrder($params['id_order']);
     if (!Validate::isLoadedObject($shipto_order)) {
         return false;
     }
     $order = new Order($shipto_order->id_order);
     if ($order->current_state == self::$os_ps_canceled || $order->current_state == self::$os_cancel) {
         return false;
     }
     $shipto_order->country_name = Country::getNameById($this->context->language->id, $shipto_order->id_country);
     $shipto_order->state_name = State::getNameById($shipto_order->id_state);
     $this->context->smarty->assign(array('shipto_order' => $shipto_order));
     return $this->display($this->_path, 'admin-order.tpl');
 }
Exemple #11
0
 /**
  * it is used to create a list of relevant addresses for given address.
  * used in admin panel to validate the postcode
  *
  * @param array $address The content will be the edit form for address from admin
  *                       $address contain next keys
  *                       MANDATORY
  *                       country
  *                       city
  *
  * OPTIONAL
  *      region
  *      address
  *      street
  * @return bool|string
  */
 public function findAllSimilarAddressesForAddress($address)
 {
     $address['region'] = '';
     $country_name = '';
     if (!empty($address['country_id'])) {
         $country_object = new Country();
         $country_name = $country_object->getNameById($address['lang_id'], $address['country_id']);
         $address['country'] = $country_name;
     }
     if ($this->isEnabledAutocompleteForPostcode($country_name)) {
         if ($address['region_id']) {
             $region_name = State::getNameById($address['region_id']);
             $address['region'] = $region_name;
         }
         if (empty($address['region'])) {
             $regions = DpdGroupDpdPostcodeMysql::identifyRegionByCity($address['city']);
             if ($regions && count($regions) == 1) {
                 $address['region'] = array_pop($regions);
             }
         }
         $found_addresses = self::getInstance()->searchSimilarAddresses($address);
         return $found_addresses;
     }
     return false;
 }
Exemple #12
0
 /**
  * @param float $amount
  * @param string $method
  * @param string|null $issuer
  * @param int $cart_id
  * @return array
  */
 protected function _getPaymentData($amount, $method, $issuer, $cart_id, $secure_key)
 {
     $payment_data = array("amount" => $amount, "method" => $method, "issuer" => $issuer, "description" => str_replace('%', $cart_id, $this->module->getConfigValue('MOLLIE_DESCRIPTION')), "redirectUrl" => $this->context->link->getModuleLink('mollie', 'return', array('cart_id' => $cart_id, 'utm_nooverride' => 1)), "webhookUrl" => $this->context->link->getModuleLink('mollie', 'webhook'), "metadata" => array("cart_id" => $cart_id, "secure_key" => $secure_key));
     // Send webshop locale
     if ($this->module->getConfigValue('MOLLIE_PAYMENTSCREEN_LOCALE') === Mollie::PAYMENTSCREEN_LOCALE_SEND_WEBSITE_LOCALE) {
         $locale = $this->_getWebshopLocale();
         if (preg_match('/^[a-z]{2}(?:[\\-_][A-Z]{2})?$/iu', $locale)) {
             $payment_data['locale'] = $locale;
         }
     }
     if (isset($this->context, $this->context->cart)) {
         if (isset($this->context->cart->id_address_invoice)) {
             $billing = new Address(intval($this->context->cart->id_address_invoice));
             $payment_data['billingCity'] = $billing->city;
             $payment_data['billingRegion'] = State::getNameById($billing->id_state);
             $payment_data['billingPostal'] = $billing->postcode;
             $payment_data['billingCountry'] = Country::getIsoById($billing->id_country);
         }
         if (isset($this->context->cart->id_address_delivery)) {
             $shipping = new Address(intval($this->context->cart->id_address_delivery));
             $payment_data['shippingCity'] = $shipping->city;
             $payment_data['shippingRegion'] = State::getNameById($shipping->id_state);
             $payment_data['shippingPostal'] = $shipping->postcode;
             $payment_data['shippingCountry'] = Country::getIsoById($shipping->id_country);
         }
     }
     return $payment_data;
 }
 function execPayment($cart)
 {
     $delivery = new Address(intval($cart->id_address_delivery));
     $invoice = new Address(intval($cart->id_address_invoice));
     $customer = new Customer(intval($cart->id_customer));
     global $cookie, $smarty;
     //Verify currencies and display payment form
     $cart_details = $cart->getSummaryDetails(null, true);
     $currencies = Currency::getCurrencies();
     $authorized_currencies = array_flip(explode(',', $this->currencies));
     $currencies_used = array();
     foreach ($currencies as $key => $currency) {
         if (isset($authorized_currencies[$currency['id_currency']])) {
             $currencies_used[] = $currencies[$key];
         }
     }
     $smarty->assign('currencies_used', $currencies_used);
     $order_currency = '';
     foreach ($currencies_used as $key => $currency) {
         if ($currency['id_currency'] == $cart->id_currency) {
             $order_currency = $currency['iso_code'];
         }
     }
     $products = $cart->getProducts();
     foreach ($products as $key => $product) {
         $products[$key]['name'] = str_replace('"', '\'', $product['name']);
         $products[$key]['name'] = htmlentities(utf8_decode($product['name']));
     }
     $discounts = $cart_details['discounts'];
     $carrier = $cart_details['carrier'];
     if (_PS_VERSION_ < '1.5') {
         $shipping_cost = $cart_details['total_shipping_tax_exc'];
     } else {
         $shipping_cost = $this->context->cart->getTotalShippingCost();
     }
     $CheckoutUrl = 'https://www.2checkout.com/checkout/purchase';
     $sid = Configuration::get('CHECKOUT_SID');
     $display = Configuration::get('CHECKOUT_DISPLAY');
     $amount = number_format($cart->getOrderTotal(true, 3), 2, '.', '');
     $cart_order_id = $cart->id;
     $email = $customer->email;
     $secure_key = $customer->secure_key;
     $demo = "N";
     // Change to "Y" for demo mode
     $outside_state = "XX";
     // This will pre-select Outside USA and Canada, if state does not exist
     // Invoice Parameters
     $card_holder_name = $invoice->firstname . ' ' . $invoice->lastname;
     $street_address = $invoice->address1;
     $street_address2 = $invoice->address2;
     $phone = $invoice->phone;
     $city = $invoice->city;
     $state = (Validate::isLoadedObject($invoice) and $invoice->id_state) ? new State(intval($invoice->id_state)) : false;
     $zip = $invoice->postcode;
     $country = $invoice->country;
     // Shipping Parameters
     $ship_name = $delivery->firstname . ' ' . $invoice->lastname;
     $ship_street_address = $delivery->address1;
     $ship_street_address2 = $delivery->address2;
     $ship_city = $delivery->city;
     $ship_state = (Validate::isLoadedObject($delivery) and $delivery->id_state) ? new State(intval($delivery->id_state)) : false;
     $ship_zip = $delivery->postcode;
     $ship_country = $delivery->country;
     $check_total = $this->checkTotal($cart);
     if (Configuration::get('CHECKOUT_CURRENCY') > 0) {
         $currency_from = Currency::getCurrency($cart->id_currency);
         $currency_to = Currency::getCurrency(Configuration::get('CHECKOUT_CURRENCY'));
         $amount = Tools::ps_round($amount / $currency_from['conversion_rate'], 2);
         $total = Tools::ps_round($amount *= $currency_to['conversion_rate'], 2);
         $order_currency = $currency_to['iso_code'];
         $override_currency = $currency_to;
     } else {
         $total = number_format($cart->getOrderTotal(true, 3), 2, '.', '');
         $override_currency = 0;
     }
     $smarty->assign(array('CheckoutUrl' => $CheckoutUrl, 'check_total' => $check_total, 'sid' => $sid, 'display' => $display, 'total' => $total, 'cart_order_id' => $cart_order_id, 'email' => $email, 'outside_state' => $outside_state, 'secure_key' => $secure_key, 'card_holder_name' => $card_holder_name, 'street_address' => $street_address, 'street_address2' => $street_address2, 'phone' => $phone, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country, 'ship_name' => $ship_name, 'ship_street_address' => $ship_street_address, 'ship_street_address2' => $ship_street_address2, 'ship_city' => $ship_city, 'ship_state' => $ship_state, 'ship_zip' => $ship_zip, 'ship_country' => $ship_country, 'products' => $products, 'currency_code' => $order_currency, 'override_currency' => $override_currency, 'TotalAmount' => $total, 'this_path' => $this->_path, 'this_path_ssl' => Configuration::get('PS_FO_PROTOCOL') . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . "modules/{$this->name}/"));
     //shipping lineitem
     if ($shipping_cost > 0) {
         $smarty->assign('shipping_cost', $shipping_cost);
     }
     //tax lineitem
     if ($cart_details['total_tax'] > 0) {
         $smarty->assign('tax', $cart_details['total_tax']);
     }
     //coupon lineitem
     if ($cart_details['total_discounts'] > 0) {
         $smarty->assign('discount', $cart_details['total_discounts_tax_exc']);
     }
     $cart = new Cart($cookie->id_cart);
     $address = new Address($cart->id_address_delivery, intval($cookie->id_lang));
     $state = State::getNameById($address->id_state);
     $state = $state ? '(' . $state . ')' : '';
     $str_address = ($address->company ? $address->company . '<br>' : '') . $address->firstname . ' ' . $address->lastname . '<br>' . $address->address1 . '<br>' . ($address->address2 ? $address->address2 . '<br>' : '') . $address->postcode . ' ' . $address->city . '<br>' . $address->country . $state;
     $smarty->assign('address', $str_address);
     $carrier = Carrier::getCarriers(intval($cookie->id_lang));
     if ($carrier) {
         foreach ($carrier as $c) {
             if ($cart->id_carrier == $c['id_carrier']) {
                 $smarty->assign('carrier', $c['name']);
                 break;
             }
         }
     }
     return $this->display(__FILE__, 'payment_execution.tpl');
 }
Exemple #14
0
 /**
  * Return useful informations for cart
  *
  * @return array Cart details
  */
 function getSummaryDetails()
 {
     global $cookie;
     $delivery = new Address(intval($this->id_address_delivery));
     $invoice = new Address(intval($this->id_address_invoice));
     return array('delivery' => $delivery, 'delivery_state' => State::getNameById($delivery->id_state), 'invoice' => $invoice, 'invoice_state' => State::getNameById($invoice->id_state), 'carrier' => new Carrier(intval($this->id_carrier), $cookie->id_lang), 'products' => $this->getProducts(false), 'discounts' => $this->getDiscounts(), 'total_discounts' => $this->getOrderTotal(true, 2), 'total_discounts_tax_exc' => $this->getOrderTotal(false, 2), 'total_wrapping' => $this->getOrderTotal(true, 6), 'total_wrapping_tax_exc' => $this->getOrderTotal(false, 6), 'total_shipping' => $this->getOrderShippingCost(), 'total_shipping_tax_exc' => $this->getOrderShippingCost(NULL, false), 'total_products_wt' => $this->getOrderTotal(true, 1), 'total_products' => $this->getOrderTotal(false, 1), 'total_price' => $this->getOrderTotal(), 'total_tax' => $this->getOrderTotal() - $this->getOrderTotal(false), 'total_price_without_tax' => $this->getOrderTotal(false));
 }
 function execPayment($cart)
 {
     $delivery = new Address(intval($cart->id_address_delivery));
     $invoice = new Address(intval($cart->id_address_invoice));
     $customer = new Customer(intval($cart->id_customer));
     global $cookie, $smarty;
     //Verify currencies and display payment form
     $cart_details = $cart->getSummaryDetails(null, true);
     $currencies = Currency::getCurrencies();
     $authorized_currencies = array_flip(explode(',', $this->currencies));
     $currencies_used = array();
     foreach ($currencies as $key => $currency) {
         if (isset($authorized_currencies[$currency['id_currency']])) {
             $currencies_used[] = $currencies[$key];
         }
     }
     $order_currency = '';
     foreach ($currencies_used as $key => $currency) {
         if ($currency['id_currency'] == $cart->id_currency) {
             $order_currency = $currency['iso_code'];
         }
     }
     $products = $cart->getProducts();
     foreach ($products as $key => $product) {
         $products[$key]['name'] = str_replace('"', '\'', $product['name']);
         $products[$key]['name'] = htmlentities(utf8_decode($product['name']));
     }
     $discounts = $cart_details['discounts'];
     $carrier = $cart_details['carrier'];
     if (_PS_VERSION_ < '1.5') {
         $shipping_cost = $cart_details['total_shipping_tax_exc'];
     } else {
         $shipping_cost = $this->context->cart->getTotalShippingCost();
     }
     $CheckoutUrl = 'https://www.2checkout.com/checkout/purchase';
     $sid = Configuration::get('TWOCHECKOUTPP_SID');
     $amount = number_format($cart->getOrderTotal(true, 3), 2, '.', '');
     $cart_order_id = $cart->id;
     $email = $customer->email;
     $secure_key = $customer->secure_key;
     $demo = "N";
     // Change to "Y" for demo mode
     $outside_state = "XX";
     // This will pre-select Outside USA and Canada, if state does not exist
     // Invoice Parameters
     $card_holder_name = $invoice->firstname . ' ' . $invoice->lastname;
     $street_address = $invoice->address1;
     $street_address2 = $invoice->address2;
     $phone = $invoice->phone;
     $city = $invoice->city;
     $state = (Validate::isLoadedObject($invoice) and $invoice->id_state) ? new State(intval($invoice->id_state)) : false;
     $zip = $invoice->postcode;
     $country = $invoice->country;
     // Shipping Parameters
     $ship_name = $delivery->firstname . ' ' . $invoice->lastname;
     $ship_street_address = $delivery->address1;
     $ship_street_address2 = $delivery->address2;
     $ship_city = $delivery->city;
     $ship_state = (Validate::isLoadedObject($delivery) and $delivery->id_state) ? new State(intval($delivery->id_state)) : false;
     $ship_zip = $delivery->postcode;
     $ship_country = $delivery->country;
     $check_total = $this->checkTotal($cart);
     if (Configuration::get('TWOCHECKOUTPP_CURRENCY') > 0) {
         $currency_from = Currency::getCurrency($cart->id_currency);
         $currency_to = Currency::getCurrency(Configuration::get('TWOCHECKOUTPP_CURRENCY'));
         $amount = Tools::ps_round($amount / $currency_from['conversion_rate'], 2);
         $total = Tools::ps_round($amount *= $currency_to['conversion_rate'], 2);
         $order_currency = $currency_to['iso_code'];
         $override_currency = $currency_to;
     } else {
         $total = number_format($cart->getOrderTotal(true, 3), 2, '.', '');
         $override_currency = 0;
     }
     $cart = new Cart($cookie->id_cart);
     $address = new Address($cart->id_address_delivery, intval($cookie->id_lang));
     $state = State::getNameById($address->id_state);
     $state = $state ? '(' . $state . ')' : '';
     $str_address = ($address->company ? $address->company . '<br>' : '') . $address->firstname . ' ' . $address->lastname . '<br>' . $address->address1 . '<br>' . ($address->address2 ? $address->address2 . '<br>' : '') . $address->postcode . ' ' . $address->city . '<br>' . $address->country . $state;
     $carrier = Carrier::getCarriers(intval($cookie->id_lang));
     if ($carrier) {
         foreach ($carrier as $c) {
             if ($cart->id_carrier == $c['id_carrier']) {
                 $carrier_name = $c['name'];
                 break;
             }
         }
     }
     $params = array();
     $params['sid'] = $sid;
     $params['paypal_direct'] = 'Y';
     $params['currency_code'] = $order_currency;
     $params['return_url'] = $this->context->link->getPageLink('order', true, NULL, "step=3");
     $params['merchant_order_id'] = $cart_order_id;
     $params['email'] = $email;
     $params['phone'] = $phone;
     $params['card_holder_name'] = $card_holder_name;
     $params['street_address'] = $street_address;
     $params['street_address2'] = $street_address2;
     $params['city'] = $city;
     $params['state'] = $state;
     $params['zip'] = $zip;
     $params['country'] = $country;
     $params['ship_name'] = $ship_name;
     $params['ship_street_address'] = $ship_street_address;
     $params['ship_street_address2'] = $ship_street_address2;
     $params['ship_city'] = $ship_city;
     $params['ship_state'] = $ship_state ? $ship_state->name : $outside_state;
     $params['ship_zip'] = $ship_zip;
     $params['ship_country'] = $ship_country;
     if (sprintf("%01.2f", $check_total) == sprintf("%01.2f", $total)) {
         $params['mode'] = '2CO';
         $i = 0;
         foreach ($products as $product) {
             $params['li_' . $i . '_type'] = 'product';
             $params['li_' . $i . '_id'] = $product['id_product'];
             $params['li_' . $i . '_name'] = $product['name'];
             $params['li_' . $i . '_description'] = $product['description_short'];
             $params['li_' . $i . '_quantity'] = $product['quantity'];
             $params['li_' . $i . '_price'] = $product['price'];
             $i++;
         }
         if ($shipping_cost > 0) {
             $params['li_' . $i . '_type'] = 'shipping';
             $params['li_' . $i . '_name'] = $carrier_name;
             $params['li_' . $i . '_price'] = $shipping_cost;
             $i++;
         }
         if ($cart_details['total_tax'] > 0) {
             $params['li_' . $i . '_type'] = 'tax';
             $params['li_' . $i . '_name'] = 'Tax';
             $params['li_' . $i . '_price'] = $cart_details['total_tax'];
             $i++;
         }
         if ($cart_details['total_discounts_tax_exc'] > 0) {
             $params['li_' . $i . '_type'] = 'coupon';
             $params['li_' . $i . '_name'] = 'Discounts';
             $params['li_' . $i . '_price'] = $cart_details['total_discounts_tax_exc'];
             $i++;
         }
     } else {
         $params['cart_order_id'] = $cart_order_id;
         $params['total'] = sprintf("%01.2f", $total);
     }
     $redirect_url = $CheckoutUrl . '?' . http_build_query($params);
     header('Location: ' . $redirect_url);
 }
 protected function _assignAddress()
 {
     //if guest checkout disabled and flag is_guest  in cookies is actived
     if (Configuration::get('PS_GUEST_CHECKOUT_ENABLED') == 0 and (int) self::$cookie->is_guest != Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
         self::$cookie->logout();
         Tools::redirect('');
     } elseif (!Customer::getAddressesTotalById((int) self::$cookie->id_customer)) {
         //Tools::redirect('address.php?back=order.php?step=1');
         //self::$smarty->assign('no_address', 1);
     }
     $customer = new Customer((int) self::$cookie->id_customer);
     if (Validate::isLoadedObject($customer)) {
         /* Getting customer addresses */
         $customerAddresses = $customer->getAddresses((int) self::$cookie->id_lang);
         // Getting a list of formated address fields with associated values
         $formatedAddressFieldsValuesList = array();
         foreach ($customerAddresses as $address) {
             $tmpAddress = new Address($address['id_address']);
             $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields'] = AddressFormat::getOrderedAddressFields($address['id_country']);
             $formatedAddressFieldsValuesList[$address['id_address']]['formated_fields_values'] = AddressFormat::getFormattedAddressFieldsValues($tmpAddress, $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields']);
             unset($tmpAddress);
         }
         self::$smarty->assign(array('addresses' => $customerAddresses, 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList));
         /* Setting default addresses for cart */
         if ((!isset(self::$cart->id_address_delivery) or empty(self::$cart->id_address_delivery)) and sizeof($customerAddresses)) {
             self::$cart->id_address_delivery = (int) $customerAddresses[0]['id_address'];
             $update = 1;
         }
         if ((!isset(self::$cart->id_address_invoice) or empty(self::$cart->id_address_invoice)) and sizeof($customerAddresses)) {
             self::$cart->id_address_invoice = (int) $customerAddresses[0]['id_address'];
             $update = 1;
         }
         /* Update cart addresses only if needed */
         if (isset($update) and $update) {
             self::$cart->update();
         }
         /* If delivery address is valid in cart, assign it to Smarty */
         if (isset(self::$cart->id_address_delivery)) {
             $deliveryAddress = new Address((int) self::$cart->id_address_delivery);
             if ($deliveryAddress->id_state) {
                 $deliveryAddress->state = State::getNameById($deliveryAddress->id_state);
             }
             if (Validate::isLoadedObject($deliveryAddress) and $deliveryAddress->id_customer == $customer->id) {
                 self::$smarty->assign('delivery', $deliveryAddress);
             }
         }
         /* If invoice address is valid in cart, assign it to Smarty */
         if (isset(self::$cart->id_address_invoice)) {
             $invoiceAddress = new Address((int) self::$cart->id_address_invoice);
             if ($invoiceAddress->id_state) {
                 $invoiceAddress->state = State::getNameById($invoiceAddress->id_state);
             }
             if (Validate::isLoadedObject($invoiceAddress) and $invoiceAddress->id_customer == $customer->id) {
                 self::$smarty->assign('invoice', $invoiceAddress);
             }
         }
         //assign countries
         $countries = Country::getCountries(1);
         $country_names = Country::getActiveCountries();
         self::$smarty->assign('countries', $countries);
         self::$smarty->assign('country_names', $country_names);
         if (isset(self::$cookie->id_country)) {
             $id_current_country = self::$cookie->id_country;
         } else {
             $id_current_country = Tools::getValue('id_country', (int) $customer->id_country);
         }
         self::$smarty->assign('current_country', $id_current_country);
         //default to USA
         if (!$id_current_country) {
             $id_current_country = 21;
         }
         //assign states
         $country = new Country($id_current_country);
         if ($country->contains_states) {
             $stateData = State::getStatesByIdCountry($customer->id_country);
             self::$smarty->assign('states', $stateData);
         }
     }
     if ($oldMessage = Message::getMessageByCartId((int) self::$cart->id)) {
         self::$smarty->assign('oldMessage', $oldMessage['message']);
     }
     //Assign token for new address
     self::$smarty->assign('token', Tools::getToken(false));
     self::$smarty->assign('id_carrier', self::$cart->id_carrier);
 }
 public function storeContactImportOne($info, $shop_is_feature_active, $regenerate, $force_ids, $validateOnly = false)
 {
     AdminImportController::setDefaultValues($info);
     if ($force_ids && isset($info['id']) && (int) $info['id']) {
         $store = new Store((int) $info['id']);
     } else {
         if (array_key_exists('id', $info) && (int) $info['id'] && Store::existsInDatabase((int) $info['id'], 'store')) {
             $store = new Store((int) $info['id']);
         } else {
             $store = new Store();
         }
     }
     AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $store);
     if (isset($store->image) && !empty($store->image)) {
         if (!AdminImportController::copyImg($store->id, null, $store->image, 'stores', !$regenerate)) {
             $this->warnings[] = $store->image . ' ' . $this->trans('cannot be copied.', array(), 'Admin.Parameters.Notification');
         }
     }
     if (isset($store->hours) && is_array($store->hours)) {
         $store->hours = serialize($store->hours);
     }
     if (isset($store->country) && is_numeric($store->country)) {
         if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $store->country)) {
             $store->id_country = (int) $store->country;
         }
     } elseif (isset($store->country) && is_string($store->country) && !empty($store->country)) {
         if ($id_country = Country::getIdByName(null, $store->country)) {
             $store->id_country = (int) $id_country;
         } else {
             $country = new Country();
             $country->active = 1;
             $country->name = AdminImportController::createMultiLangField($store->country);
             $country->id_zone = 0;
             // Default zone for country to create
             $country->iso_code = Tools::strtoupper(Tools::substr($store->country, 0, 2));
             // Default iso for country to create
             $country->contains_states = 0;
             // Default value for country to create
             $lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
             if (($field_error = $country->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $country->add()) {
                 $store->id_country = (int) $country->id;
             } else {
                 if (!$validateOnly) {
                     $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
                     $this->errors[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), $country->name[$default_language_id]);
                 }
                 if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
     }
     if (isset($store->state) && is_numeric($store->state)) {
         if (State::getNameById((int) $store->state)) {
             $store->id_state = (int) $store->state;
         }
     } elseif (isset($store->state) && is_string($store->state) && !empty($store->state)) {
         if ($id_state = State::getIdByName($store->state)) {
             $store->id_state = (int) $id_state;
         } else {
             $state = new State();
             $state->active = 1;
             $state->name = $store->state;
             $state->id_country = isset($country->id) ? (int) $country->id : 0;
             $state->id_zone = 0;
             // Default zone for state to create
             $state->iso_code = Tools::strtoupper(Tools::substr($store->state, 0, 2));
             // Default iso for state to create
             $state->tax_behavior = 0;
             if (($field_error = $state->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $state->add()) {
                 $store->id_state = (int) $state->id;
             } else {
                 if (!$validateOnly) {
                     $this->errors[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), $state->name);
                 }
                 if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
     }
     $res = false;
     if (($field_error = $store->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $store->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
         if ($store->id && $store->storeExists($store->id)) {
             $res = $validateOnly ? $validateOnly : $store->update();
         }
         $store->force_id = (bool) $force_ids;
         if (!$res) {
             $res = $validateOnly ? $validateOnly : $store->add();
         }
         if (!$res) {
             $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $info['name'], isset($info['id']) ? $info['id'] : 'null');
         }
     } else {
         $this->errors[] = $this->l('Store is invalid') . ' (' . $store->name . ')';
         $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '');
     }
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     if (!$this->errors) {
         if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) {
             $this->product->quantity = 0;
         }
         $this->product->description = $this->transformDescriptionWithImg($this->product->description);
         // Assign to the template the id of the virtual product. "0" if the product is not downloadable.
         $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
         $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
         if (Tools::isSubmit('submitCustomizedDatas')) {
             // If cart has not been saved, we need to do it so that customization fields can have an id_cart
             // We check that the cookie exists first to avoid ghost carts
             if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) {
                 $this->context->cart->add();
                 $this->context->cookie->id_cart = (int) $this->context->cart->id;
             }
             $this->pictureUpload();
             $this->textRecord();
             $this->formTargetFormat();
         } elseif (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) {
             $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture.');
         }
         $pictures = array();
         $text_fields = array();
         if ($this->product->customizable) {
             $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true);
             foreach ($files as $file) {
                 $pictures['pictures_' . $this->product->id . '_' . $file['index']] = $file['value'];
             }
             $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true);
             foreach ($texts as $text_field) {
                 $text_fields['textFields_' . $this->product->id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']);
             }
         }
         $this->context->smarty->assign(array('pictures' => $pictures, 'textFields' => $text_fields));
         $this->product->customization_required = false;
         $customization_fields = $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false;
         if (is_array($customization_fields)) {
             foreach ($customization_fields as $customization_field) {
                 if ($this->product->customization_required = $customization_field['required']) {
                     break;
                 }
             }
         }
         // Assign template vars related to the category + execute hooks related to the category
         $this->assignCategory();
         // Assign template vars related to the price and tax
         $this->assignPriceAndTax();
         // Assign template vars related to the images
         $this->assignImages();
         // Assign attribute groups to the template
         $this->assignAttributesGroups();
         // Assign attributes combinations to the template
         $this->assignAttributesCombinations();
         // Pack management
         $pack_items = Pack::isPack($this->product->id) ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array();
         $this->context->smarty->assign('packItems', $pack_items);
         $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1));
         if (isset($this->category->id) && $this->category->id) {
             $return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category));
         } else {
             $return_link = 'javascript: history.back();';
         }
         $accessories = $this->product->getAccessories($this->context->language->id);
         if ($this->product->cache_is_pack || count($accessories)) {
             $this->context->controller->addCSS(_THEME_CSS_DIR_ . 'product_list.css');
         }
         if ($this->product->customizable) {
             $customization_datas = $this->context->cart->getProductCustomization($this->product->id, null, true);
         }
         // by webkul
         $htl_features = array();
         $obj_hotel_room_type = new HotelRoomType();
         $room_info_by_product_id = $obj_hotel_room_type->getRoomTypeInfoByIdProduct($this->product->id);
         $hotel_id = $room_info_by_product_id['id_hotel'];
         if (isset($hotel_id) && $hotel_id) {
             $obj_hotel_branch = new HotelBranchInformation();
             $hotel_info_by_id = $obj_hotel_branch->hotelBranchInfoById($hotel_id);
             $hotel_policies = $hotel_info_by_id['policies'];
             $hotel_name = $hotel_info_by_id['hotel_name'];
             $country = Country::getNameById($this->context->language->id, $hotel_info_by_id['country_id']);
             $state = State::getNameById($hotel_info_by_id['state_id']);
             $hotel_location = $hotel_info_by_id['city'] . ', ' . $state . ', ' . $country;
             $obj_hotel_feaures_ids = $obj_hotel_branch->getFeaturesOfHotelByHotelId($hotel_id);
             if (isset($obj_hotel_feaures_ids) && $obj_hotel_feaures_ids) {
                 foreach ($obj_hotel_feaures_ids as $key => $value) {
                     $obj_htl_ftr = new HotelFeatures();
                     $htl_info = $obj_htl_ftr->getFeatureInfoById($value['feature_id']);
                     $htl_features[] = $htl_info['name'];
                 }
             }
         }
         $date_from = Tools::getValue('date_from');
         $date_to = Tools::getValue('date_to');
         if (!($date_from = Tools::getValue('date_from'))) {
             $date_from = date('Y-m-d');
             $date_to = date('Y-m-d', strtotime($date_from) + 86400);
         }
         if (!($date_to = Tools::getValue('date_to'))) {
             $date_to = date('Y-m-d', strtotime($date_from) + 86400);
         }
         $obj_booking_detail = new HotelBookingDetail();
         $num_days = $obj_booking_detail->getNumberOfDays($date_from, $date_to);
         $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id);
         if (!$priceDisplay || $priceDisplay == 2) {
             $price_tax = true;
         } elseif ($priceDisplay == 1) {
             $price_tax = false;
         }
         $price_tax_incl = Product::getPriceStatic($this->product->id, $price_tax);
         $total_price = $price_tax_incl * $num_days;
         $obj_booking_dtl = new HotelBookingDetail();
         $hotel_room_data = $obj_booking_dtl->DataForFrontSearch($date_from, $date_to, $hotel_id, $this->product->id, 1);
         $obj_htl_cart_booking_data = new HotelCartBookingData();
         $num_cart_rooms = $obj_htl_cart_booking_data->getCountRoomsByIdCartIdProduct($this->context->cart->id, $this->product->id, $date_from, $date_to);
         if ($hotel_room_data) {
             $total_available_rooms = $hotel_room_data['stats']['num_avail'] - $num_cart_rooms;
         }
         //end
         $location_enable = Configuration::get('WK_HOTEL_LOCATION_ENABLE');
         $hotel_branch_obj = new HotelBranchInformation();
         $hotel_info = $hotel_branch_obj->getActiveHotelBranchesInfo();
         $search_data['date_from'] = $date_from;
         $search_data['date_to'] = $date_to;
         $search_data['htl_dtl'] = $hotel_branch_obj->hotelBranchInfoById($hotel_id);
         if (Tools::getValue('error')) {
             $this->context->smarty->assign('error', Tools::getValue('error'));
         }
         $this->context->smarty->assign(array('stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => $customization_fields, 'id_customization' => empty($customization_datas) ? null : $customization_datas[0]['id_customization'], 'accessories' => $accessories, 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'ratting_img_path' => _MODULE_DIR_ . 'hotelreservationsystem/views/img/Slices/icons-sprite.png', 'num_reviews' => ProductComment::getCommentNumber($this->product->id), 'ratting' => ProductComment::getAverageGrade($this->product->id)['grade'], 'total_available_rooms' => $total_available_rooms, 'all_hotels_info' => $hotel_info, 'location_enable' => $location_enable, 'total_price' => $total_price, 'product_controller_url' => $this->context->link->getPageLink('product'), 'num_days' => $num_days, 'date_from' => $date_from, 'date_to' => $date_to, 'hotel_location' => $hotel_location, 'hotel_name' => $hotel_name, 'hotel_policies' => $hotel_policies, 'hotel_features' => $htl_features, 'ftr_img_src' => _PS_IMG_ . 'rf/', 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->id) : array(), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'HOOK_PRODUCT_CONTENT' => Hook::exec('displayProductContent', array('product' => $this->product)), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'body_classes' => array($this->php_self . '-' . $this->product->id, $this->php_self . '-' . $this->product->link_rewrite, 'category-' . (isset($this->category) ? $this->category->id : ''), 'category-' . (isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : '')), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE'), 'search_data' => $search_data));
     }
     $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl');
 }
Exemple #19
0
 public function addressImport()
 {
     $this->receiveTab();
     $defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT');
     $handle = $this->openCsvFile();
     self::setLocale();
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) {
         if (Tools::getValue('convert')) {
             $line = $this->utf8_encode_array($line);
         }
         $info = self::getMaskedRow($line);
         self::setDefaultValues($info);
         $address = new Address();
         self::array_walk($info, array('AdminImport', 'fillInfo'), $address);
         if (isset($address->country) and is_numeric($address->country)) {
             if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) {
                 $address->id_country = (int) $address->country;
             }
         } elseif (isset($address->country) and is_string($address->country) and !empty($address->country)) {
             if ($id_country = Country::getIdByName(NULL, $address->country)) {
                 $address->id_country = (int) $id_country;
             } else {
                 $country = new Country();
                 $country->active = 1;
                 $country->name = self::createMultiLangField($address->country);
                 $country->id_zone = 0;
                 // Default zone for country to create
                 $country->iso_code = strtoupper(substr($address->country, 0, 2));
                 // Default iso for country to create
                 $country->contains_states = 0;
                 // Default value for country to create
                 $langFieldError = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
                 if (($fieldError = $country->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $country->add()) {
                     $address->id_country = (int) $country->id;
                 } else {
                     $this->_errors[] = $country->name[$defaultLanguageId] . ' ' . Tools::displayError('Cannot be saved');
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
                 }
             }
         }
         if (isset($address->state) and is_numeric($address->state)) {
             if (State::getNameById((int) $address->state)) {
                 $address->id_state = (int) $address->state;
             }
         } elseif (isset($address->state) and is_string($address->state) and !empty($address->state)) {
             if ($id_state = State::getIdByName($address->state)) {
                 $address->id_state = (int) $id_state;
             } else {
                 $state = new State();
                 $state->active = 1;
                 $state->name = $address->state;
                 $state->id_country = isset($country->id) ? (int) $country->id : 0;
                 $state->id_zone = 0;
                 // Default zone for state to create
                 $state->iso_code = strtoupper(substr($address->state, 0, 2));
                 // Default iso for state to create
                 $state->tax_behavior = 0;
                 if (($fieldError = $state->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $state->add()) {
                     $address->id_state = (int) $state->id;
                 } else {
                     $this->_errors[] = $state->name . ' ' . Tools::displayError('Cannot be saved');
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
                 }
             }
         }
         if (isset($address->customer_email) and !empty($address->customer_email)) {
             if (Validate::isEmail($address->customer_email)) {
                 $customer = Customer::customerExists($address->customer_email, true);
                 if ($customer) {
                     $address->id_customer = (int) $customer;
                 } else {
                     $this->_errors[] = mysql_error() . ' ' . $address->customer_email . ' ' . Tools::displayError('does not exist in database') . ' ' . (isset($info['id']) ? ' (ID ' . $info['id'] . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                 }
             } else {
                 $this->_errors[] = '"' . $address->customer_email . '" :' . Tools::displayError('Is not a valid Email');
             }
         }
         if (isset($address->manufacturer) and is_numeric($address->manufacturer) and Manufacturer::manufacturerExists((int) $address->manufacturer)) {
             $address->id_manufacturer = (int) $address->manufacturer;
         } elseif (isset($address->manufacturer) and is_string($address->manufacturer) and !empty($address->manufacturer)) {
             $manufacturer = new Manufacturer();
             $manufacturer->name = $address->manufacturer;
             if (($fieldError = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $manufacturer->add()) {
                 $address->id_manufacturer = (int) $manufacturer->id;
             } else {
                 $this->_errors[] = mysql_error() . ' ' . $manufacturer->name . (isset($manufacturer->id) ? ' (' . $manufacturer->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                 $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
             }
         }
         if (isset($address->supplier) and is_numeric($address->supplier) and Supplier::supplierExists((int) $address->supplier)) {
             $address->id_supplier = (int) $address->supplier;
         } elseif (isset($address->supplier) and is_string($address->supplier) and !empty($address->supplier)) {
             $supplier = new Supplier();
             $supplier->name = $address->supplier;
             if (($fieldError = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $supplier->add()) {
                 $address->id_supplier = (int) $supplier->id;
             } else {
                 $this->_errors[] = mysql_error() . ' ' . $supplier->name . (isset($supplier->id) ? ' (' . $supplier->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                 $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
             }
         }
         $res = false;
         if (($fieldError = $address->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $address->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
             if ($address->id and $address->addressExists($address->id)) {
                 $res = $address->update();
             }
             if (!$res) {
                 $res = $address->add();
             }
         }
         if (!$res) {
             $this->_errors[] = $info['alias'] . (isset($info['id']) ? ' (ID ' . $info['id'] . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
             $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
         }
     }
     $this->closeCsvFile($handle);
 }
Exemple #20
0
 protected function _getAddr(Address $address)
 {
     return array("first_name" => $address->firstname, "last_name" => $address->lastname, "phone" => $address->phone, "alt_phone" => $address->phone_mobile, "street" => $address->address1, "address_addition" => $address->address2, "city" => $address->city, "state" => State::getNameById($address->id_state), "country" => CountryCore::getIsoById($address->id_country), "zip" => $address->postcode);
 }
Exemple #21
0
 /**
  * Return useful informations for cart
  *
  * @return array Cart details
  */
 public function getSummaryDetails($id_lang = null, $refresh = false)
 {
     $context = Context::getContext();
     if (!$id_lang) {
         $id_lang = $context->language->id;
     }
     $delivery = new Address((int) $this->id_address_delivery);
     $invoice = new Address((int) $this->id_address_invoice);
     // New layout system with personalization fields
     $formatted_addresses = array('delivery' => AddressFormat::getFormattedLayoutData($delivery), 'invoice' => AddressFormat::getFormattedLayoutData($invoice));
     $base_total_tax_inc = $this->getOrderTotal(true);
     $base_total_tax_exc = $this->getOrderTotal(false);
     $total_tax = $base_total_tax_inc - $base_total_tax_exc;
     if ($total_tax < 0) {
         $total_tax = 0;
     }
     $currency = new Currency($this->id_currency);
     $products = $this->getProducts($refresh);
     $gift_products = array();
     $cart_rules = $this->getCartRules();
     $total_shipping = $this->getTotalShippingCost();
     $total_shipping_tax_exc = $this->getTotalShippingCost(null, false);
     $total_products_wt = $this->getOrderTotal(true, Cart::ONLY_PRODUCTS);
     $total_products = $this->getOrderTotal(false, Cart::ONLY_PRODUCTS);
     $total_discounts = $this->getOrderTotal(true, Cart::ONLY_DISCOUNTS);
     $total_discounts_tax_exc = $this->getOrderTotal(false, Cart::ONLY_DISCOUNTS);
     // The cart content is altered for display
     foreach ($cart_rules as &$cart_rule) {
         // If the cart rule is automatic (wihtout any code) and include free shipping, it should not be displayed as a cart rule but only set the shipping cost to 0
         if ($cart_rule['free_shipping'] && (empty($cart_rule['code']) || preg_match('/^' . CartRule::BO_ORDER_CODE_PREFIX . '[0-9]+/', $cart_rule['code']))) {
             $cart_rule['value_real'] -= $total_shipping;
             $cart_rule['value_tax_exc'] -= $total_shipping_tax_exc;
             $cart_rule['value_real'] = Tools::ps_round($cart_rule['value_real'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
             $cart_rule['value_tax_exc'] = Tools::ps_round($cart_rule['value_tax_exc'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
             if ($total_discounts > $cart_rule['value_real']) {
                 $total_discounts -= $total_shipping;
             }
             if ($total_discounts_tax_exc > $cart_rule['value_tax_exc']) {
                 $total_discounts_tax_exc -= $total_shipping_tax_exc;
             }
             // Update total shipping
             $total_shipping = 0;
             $total_shipping_tax_exc = 0;
         }
         if ($cart_rule['gift_product']) {
             foreach ($products as $key => &$product) {
                 if (empty($product['gift']) && $product['id_product'] == $cart_rule['gift_product'] && $product['id_product_attribute'] == $cart_rule['gift_product_attribute']) {
                     // Update total products
                     $total_products_wt = Tools::ps_round($total_products_wt - $product['price_wt'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $total_products = Tools::ps_round($total_products - $product['price'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     // Update total discounts
                     $total_discounts = Tools::ps_round($total_discounts - $product['price_wt'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $total_discounts_tax_exc = Tools::ps_round($total_discounts_tax_exc - $product['price'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     // Update cart rule value
                     $cart_rule['value_real'] = Tools::ps_round($cart_rule['value_real'] - $product['price_wt'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $cart_rule['value_tax_exc'] = Tools::ps_round($cart_rule['value_tax_exc'] - $product['price'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     // Update product quantity
                     $product['total_wt'] = Tools::ps_round($product['total_wt'] - $product['price_wt'], (int) $currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $product['total'] = Tools::ps_round($product['total'] - $product['price'], (int) $currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $product['cart_quantity']--;
                     if (!$product['cart_quantity']) {
                         unset($products[$key]);
                     }
                     // Add a new product line
                     $gift_product = $product;
                     $gift_product['cart_quantity'] = 1;
                     $gift_product['price'] = 0;
                     $gift_product['price_wt'] = 0;
                     $gift_product['total_wt'] = 0;
                     $gift_product['total'] = 0;
                     $gift_product['gift'] = true;
                     $gift_products[] = $gift_product;
                     break;
                     // One gift product per cart rule
                 }
             }
         }
     }
     foreach ($cart_rules as $key => &$cart_rule) {
         if ($cart_rule['value_real'] == 0) {
             unset($cart_rules[$key]);
         }
     }
     return array('delivery' => $delivery, 'delivery_state' => State::getNameById($delivery->id_state), 'invoice' => $invoice, 'invoice_state' => State::getNameById($invoice->id_state), 'formattedAddresses' => $formatted_addresses, 'products' => array_values($products), 'gift_products' => $gift_products, 'discounts' => $cart_rules, 'is_virtual_cart' => (int) $this->isVirtualCart(), 'total_discounts' => $total_discounts, 'total_discounts_tax_exc' => $total_discounts_tax_exc, 'total_wrapping' => $this->getOrderTotal(true, Cart::ONLY_WRAPPING), 'total_wrapping_tax_exc' => $this->getOrderTotal(false, Cart::ONLY_WRAPPING), 'total_shipping' => $total_shipping, 'total_shipping_tax_exc' => $total_shipping_tax_exc, 'total_products_wt' => $total_products_wt, 'total_products' => $total_products, 'total_price' => $base_total_tax_inc, 'total_tax' => $total_tax, 'total_price_without_tax' => $base_total_tax_exc, 'is_multi_address_delivery' => $this->isMultiAddressDelivery() || (int) Tools::getValue('multi-shipping') == 1, 'free_ship' => $total_shipping ? 0 : 1, 'carrier' => new Carrier($this->id_carrier, $id_lang));
 }
 /**
  * Process a payment, where the magic happens
  *
  * @param string $token CONEKTA Transaction ID (token)
  */
 public function processPayment($token, $type, $monthly_installments)
 {
     /* If 1.4 and no backward, then leave */
     if (!$this->backward) {
         return;
     }
     if (!$token && $type == "card") {
         if (version_compare(_PS_VERSION_, '1.4.0.3', '>') && class_exists('Logger')) {
             Logger::addLog($this->l('Conekta - Payment transaction failed.') . ' Message: A valid Conekta token was not provided', 3, null, 'Cart', (int) $this->context->cart->id, true);
         }
         $controller = Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc.php' : 'order.php';
         $location = $this->context->link->getPageLink($controller, true) . (strpos($controller, '?') !== false ? '&' : '?') . 'step=3&message_to_purchaser=token&conekta_error=1#conekta_error';
         Tools::redirectLink($location);
     }
     require_once dirname(__FILE__) . '/lib/conekta-php/lib/Conekta.php';
     Conekta::setApiKey(Configuration::get('CONEKTA_MODE') ? Configuration::get('CONEKTA_PRIVATE_KEY_LIVE') : Configuration::get('CONEKTA_PRIVATE_KEY_TEST'));
     $cart = $this->context->cart;
     $customer = new Customer((int) $cart->id_customer);
     $address_delivery = new Address((int) $cart->id_address_delivery);
     $address_fiscal = new Address((int) $cart->id_address_invoice);
     // get shipping info
     $carrier = new Carrier((int) $cart->id_carrier);
     $shipping_price = $cart->getTotalShippingCost() * 100;
     $shipping_carrier = "other";
     $shipping_service = "other";
     if (isset($carrier)) {
         $shipping_carrier = $carrier->name;
         $shipping_service = implode(",", $carrier->delay);
     }
     // build line items
     $items = $cart->getProducts();
     $line_items = array();
     foreach ($items as $item) {
         $line_items = array_merge($line_items, array(array('name' => $item['name'], 'unit_price' => (double) $item['price'] * 100, 'description' => $item['description_short'], 'quantity' => $item['cart_quantity'], 'sku' => $item['reference'], 'type' => "producto")));
     }
     $details = array("email" => $customer->email, "phone" => $address_delivery->phone, "name" => $customer->firstname . " " . $customer->lastname, "line_items" => $line_items, "shipment" => array("price" => $shipping_price, "carrier" => $shipping_carrier, "service" => $shipping_service, "address" => array("street1" => $address_delivery->address1, "city" => $address_delivery->city, "state" => State::getNameById($address_delivery->id_state), "country" => $address_delivery->country, "zip" => $address_delivery->postcode)), "billing_address" => array("street1" => $address_fiscal->address1, "zip" => $address_fiscal->postcode, "company_name" => $address_fiscal->company, "phone" => $address_fiscal->phone, "state" => State::getNameById($address_fiscal->id_state), "city" => $address_fiscal->city, "country" => $address_fiscal->country));
     try {
         if ($type == "cash") {
             $charge_details = array('amount' => $this->context->cart->getOrderTotal() * 100, 'reference_id' => (int) $this->context->cart->id, 'cash' => array('type' => 'oxxo'), 'details' => $details, 'currency' => $this->context->currency->iso_code, 'description' => $this->l('PrestaShop Customer ID:') . ' ' . (int) $this->context->cookie->id_customer . ' - ' . $this->l('PrestaShop Cart ID:') . ' ' . (int) $this->context->cart->id);
             $charge_response = Conekta_Charge::create($charge_details);
             $barcode_url = $charge_response->payment_method->barcode_url;
             $reference = $charge_response->payment_method->barcode;
             $order_status = (int) Configuration::get('waiting_cash_payment');
             $message = $this->l('Conekta Transaction Details:') . "\n\n" . $this->l('Reference:') . ' ' . $reference . "\n" . $this->l('Barcode:') . ' ' . $barcode_url . "\n" . $this->l('Amount:') . ' ' . $charge_response->amount * 0.01 . "\n" . $this->l('Processed on:') . ' ' . strftime('%Y-%m-%d %H:%M:%S', $charge_response->created_at) . "\n" . $this->l('Currency:') . ' ' . Tools::strtoupper($charge_response->currency) . "\n" . $this->l('Mode:') . ' ' . ($charge_response->livemode == 'true' ? $this->l('Live') : $this->l('Test')) . "\n";
             $checkout = Module::getInstanceByName('conektaprestashop');
             $checkout->extra_mail_vars = array('{barcode_url}' => (string) $barcode_url, '{barcode}' => (string) $reference);
         } elseif ($type == "spei") {
             $charge_details = array('amount' => $this->context->cart->getOrderTotal() * 100, 'reference_id' => (int) $this->context->cart->id, 'bank' => array('type' => 'spei'), 'details' => $details, 'currency' => $this->context->currency->iso_code, 'description' => $this->l('PrestaShop Customer ID:') . ' ' . (int) $this->context->cookie->id_customer . ' - ' . $this->l('PrestaShop Cart ID:') . ' ' . (int) $this->context->cart->id);
             $charge_response = Conekta_Charge::create($charge_details);
             $reference = $charge_response->payment_method->receiving_account_number;
             $order_status = (int) Configuration::get('waiting_spei_payment');
             $message = $this->l('Conekta Transaction Details:') . "\n\n" . $this->l('Amount:') . ' ' . $charge_response->amount * 0.01 . "\n" . $this->l('Processed on:') . ' ' . strftime('%Y-%m-%d %H:%M:%S', $charge_response->created_at) . "\n" . $this->l('Currency:') . ' ' . Tools::strtoupper($charge_response->currency) . "\n" . $this->l('Mode:') . ' ' . ($charge_response->livemode == 'true' ? $this->l('Live') : $this->l('Test')) . "\n";
             $checkout = Module::getInstanceByName('conektaprestashop');
             $checkout->extra_mail_vars = array('{receiving_account_number}' => (string) $reference);
         } elseif ($type == "banorte") {
             $charge_details = array('amount' => $this->context->cart->getOrderTotal() * 100, 'reference_id' => (int) $this->context->cart->id, 'bank' => array('type' => 'banorte'), 'details' => $details, 'currency' => $this->context->currency->iso_code, 'description' => $this->l('PrestaShop Customer ID:') . ' ' . (int) $this->context->cookie->id_customer . ' - ' . $this->l('PrestaShop Cart ID:') . ' ' . (int) $this->context->cart->id);
             $charge_response = Conekta_Charge::create($charge_details);
             $reference = $charge_response->payment_method->reference;
             $service_name = $charge_response->payment_method->service_name;
             $service_number = $charge_response->payment_method->service_number;
             $order_status = (int) Configuration::get('waiting_banorte_payment');
             $message = $this->l('Conekta Transaction Details:') . "\n\n" . $this->l('Amount:') . ' ' . $charge_response->amount * 0.01 . "\n" . $this->l('Processed on:') . ' ' . strftime('%Y-%m-%d %H:%M:%S', $charge_response->created_at) . "\n" . $this->l('Currency:') . ' ' . Tools::strtoupper($charge_response->currency) . "\n" . $this->l('Mode:') . ' ' . ($charge_response->livemode == 'true' ? $this->l('Live') : $this->l('Test')) . "\n";
             $checkout = Module::getInstanceByName('conektaprestashop');
             $checkout->extra_mail_vars = array('{reference}' => (string) $reference);
             $checkout->extra_mail_vars = array('{service_name}' => (string) $service_name);
             $checkout->extra_mail_vars = array('{service_number}' => (string) $service_number);
         } else {
             $charge_details = array('amount' => $this->context->cart->getOrderTotal() * 100, 'reference_id' => (int) $this->context->cart->id, 'card' => $token, 'monthly_installments' => $monthly_installments > 1 ? $monthly_installments : null, 'details' => $details, 'currency' => $this->context->currency->iso_code, 'description' => $this->l('PrestaShop Customer ID:') . ' ' . (int) $this->context->cookie->id_customer . ' - ' . $this->l('PrestaShop Cart ID:') . ' ' . (int) $this->context->cart->id);
             $charge_mode = true;
             $charge_details['capture'] = $charge_mode;
             $charge_response = Conekta_Charge::create($charge_details);
             $order_status = (int) Configuration::get('PS_OS_PAYMENT');
             $message = $this->l('Conekta Transaction Details:') . "\n\n" . $this->l('Amount:') . ' ' . $charge_response->amount * 0.01 . "\n" . $this->l('Status:') . ' ' . ($charge_response->status == 'paid' ? $this->l('Paid') : $this->l('Unpaid')) . "\n" . $this->l('Processed on:') . ' ' . strftime('%Y-%m-%d %H:%M:%S', $charge_response->created_at) . "\n" . $this->l('Currency:') . ' ' . Tools::strtoupper($charge_response->currency) . "\n" . $this->l('Mode:') . ' ' . ($charge_response->livemode == 'true' ? $this->l('Live') : $this->l('Test')) . "\n";
         }
         $this->validateOrder((int) $this->context->cart->id, (int) $order_status, $this->context->cart->getOrderTotal(), $this->displayName, $message, array(), null, false, $this->context->customer->secure_key);
         if (version_compare(_PS_VERSION_, '1.5', '>=')) {
             $new_order = new Order((int) $this->currentOrder);
             if (Validate::isLoadedObject($new_order)) {
                 $payment = $new_order->getOrderPaymentCollection();
                 if (isset($payment[0])) {
                     $payment[0]->transaction_id = pSQL($charge_response->id);
                     $payment[0]->save();
                 }
             }
         }
         if (isset($charge_response->id) && $type == "cash") {
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'conekta_transaction (type, id_cart, id_order, id_transaction, amount, status, currency, mode, date_add, reference, barcode, captured) VALUES (\'payment\', ' . pSQL((int) $this->context->cart->id) . ', ' . pSQL((int) $this->currentOrder) . ', \'' . pSQL($charge_response->id) . '\',\'' . $charge_response->amount * 0.01 . '\', \'' . ($charge_response->status == 'paid' ? 'paid' : 'unpaid') . '\', \'' . pSQL($charge_response->currency) . '\', \'' . ($charge_response->livemode == 'true' ? 'live' : 'test') . '\', NOW(),\'' . $reference . '\',\'' . $barcode_url . '\',\'' . ($charge_response->livemode == 'true' ? '1' : '0') . '\' )');
         } elseif (isset($charge_response->id) && $type == "spei") {
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'conekta_transaction (type, id_cart, id_order, id_transaction, amount, status, currency, mode, date_add, reference, captured) VALUES (\'payment\', ' . (int) $this->context->cart->id . ', ' . (int) $this->currentOrder . ', \'' . pSQL($charge_response->id) . '\', \'' . $charge_response->amount * 0.01 . '\', \'' . ($charge_response->status == 'paid' ? 'paid' : 'unpaid') . '\', \'' . pSQL($charge_response->currency) . '\', \'' . ($charge_response->livemode == 'true' ? 'live' : 'test') . '\', NOW(),\'' . $reference . '\', \'' . ($charge_response->livemode == 'true' ? '1' : '0') . '\' )');
         } elseif (isset($charge_response->id) && $type == "banorte") {
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'conekta_transaction (type, id_cart, id_order, id_transaction, amount, status, currency, mode, date_add, reference, captured) VALUES (\'payment\', ' . (int) $this->context->cart->id . ', ' . (int) $this->currentOrder . ', \'' . pSQL($charge_response->id) . '\', \'' . $charge_response->amount * 0.01 . '\', \'' . ($charge_response->status == 'paid' ? 'paid' : 'unpaid') . '\', \'' . pSQL($charge_response->currency) . '\', \'' . ($charge_response->livemode == 'true' ? 'live' : 'test') . '\', NOW(),\'' . $reference . '\', \'' . ($charge_response->livemode == 'true' ? '1' : '0') . '\' )');
         } elseif (isset($charge_response->id)) {
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'conekta_transaction (type, id_cart, id_order, id_transaction, amount, status, currency, mode, date_add, captured) VALUES (\'payment\', ' . (int) $this->context->cart->id . ', ' . (int) $this->currentOrder . ', \'' . pSQL($charge_response->id) . '\',\'' . $charge_response->amount * 0.01 . '\', \'' . ($charge_response->status == 'paid' ? 'paid' : 'unpaid') . '\', \'' . pSQL($charge_response->currency) . '\', \'' . ($charge_response->livemode == 'true' ? 'live' : 'test') . '\', NOW(), \'1\')');
         }
         if (version_compare(_PS_VERSION_, '1.5', '<')) {
             $redirect = 'order-confirmation.php?id_cart=' . (int) $this->context->cart->id . '&id_module=' . (int) $this->id . '&id_order=' . (int) $this->currentOrder . '&key=' . $this->context->customer->secure_key;
         } else {
             $redirect = $this->context->link->getPageLink('order-confirmation', true, null, array('id_order' => (int) $this->currentOrder, 'id_cart' => (int) $this->context->cart->id, 'key' => $this->context->customer->secure_key, 'id_module' => (int) $this->id));
         }
         Tools::redirect($redirect);
     } catch (Conekta_Error $e) {
         $message = $e->message_to_purchaser;
         if (version_compare(_PS_VERSION_, '1.4.0.3', '>') && class_exists('Logger')) {
             Logger::addLog($this->l('Payment transaction failed') . ' ' . $message, 2, null, 'Cart', (int) $this->context->cart->id, true);
         }
         $controller = Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc.php' : 'order.php';
         $location = $this->context->link->getPageLink($controller, true) . (strpos($controller, '?') !== false ? '&' : '?') . 'step=3&conekta_error=1&message=' . $message . '#conekta_error';
         Tools::redirectLink($location);
     }
 }