public function loadLocalisationPack($file, $selection, $install_mode = false) { if (!($xml = simplexml_load_string($file))) { return false; } $mainAttributes = $xml->attributes(); $this->name = strval($mainAttributes['name']); $this->version = strval($mainAttributes['version']); if (empty($selection)) { $res = true; $res &= $this->_installStates($xml); $res &= $this->_installTaxes($xml); $res &= $this->_installCurrencies($xml, $install_mode); $res &= $this->_installUnits($xml); if (!defined('_PS_MODE_DEV_') or !_PS_MODE_DEV_) { $res &= $this->_installLanguages($xml, $install_mode); } if ($res and isset($this->iso_code_lang)) { Configuration::updateValue('PS_LANG_DEFAULT', (int) Language::getIdByIso($this->iso_code_lang)); } if ($install_mode and $res and isset($this->iso_currency)) { $res &= Configuration::updateValue('PS_CURRENCY_DEFAULT', (int) Currency::getIdByIsoCode($this->iso_currency)); Currency::refreshCurrencies(); } return $res; } foreach ($selection as $selected) { if (!Validate::isLocalizationPackSelection($selected) or !$this->{'_install' . ucfirst($selected)}($xml)) { return false; } } return true; }
/** * Callback function for initialization by plugin implementations. * * This method gets called on instantiation of a ShopgatePlugin child class and serves as __construct() replacement. * * Important: Initialize $this->config here if you have your own config class. * * @see http://wiki.shopgate.com/Shopgate_Library#startup.28.29 */ public function startup() { include_once dirname(__FILE__) . '/../backward_compatibility/backward.php'; $this->config = new ShopgateConfigPrestashop(); // Without this explicit setting of the currency, the system could choose the wrong one e.g. EUR instead of PLN $this->getContext()->currency = new Currency(Currency::getIdByIsoCode($this->config->getCurrency())); }
/** * @see FrontController::postProcess() */ public function postProcess() { $cart = $this->context->cart; if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) { Tools::redirect('index.php?controller=order&step=1'); } // Check that this payment option is still available in case the customer changed his address just before the end of the checkout process $authorized = false; foreach (Module::getPaymentModules() as $module) { if ($module['name'] == 'swipp') { $authorized = true; break; } } if (!$authorized) { die($this->module->l('This payment method is not available.', 'validation')); } $customer = new Customer($cart->id_customer); if (!Validate::isLoadedObject($customer)) { Tools::redirect('index.php?controller=order&step=1'); } $currency = $this->context->currency; $total = (double) $cart->getOrderTotal(true, Cart::BOTH); $mailVars = array('{swipp_phone}' => Configuration::get('SWIPP_PHONE'), '{swipp_owner}' => Configuration::get('SWIPP_OWNER'), '{swipp_payment_dkk}' => Tools::displayPrice($this->module->__getPriceDkk($cart), (int) Currency::getIdByIsoCode('DKK'))); $this->module->validateOrder($cart->id, Configuration::get('SWIPP_PAYMENT_STATE'), $total, $this->module->displayName, NULL, $mailVars, (int) $currency->id, false, $customer->secure_key); Tools::redirect('index.php?controller=order-confirmation&id_cart=' . $cart->id . '&id_module=' . $this->module->id . '&id_order=' . $this->module->currentOrder . '&key=' . $customer->secure_key); }
public static function refreshCurrencies() { parent::refreshCurrencies(); if (!($feed = Tools::simplexml_load_file(_GOINTERPAY_RATES_URL_ . Configuration::get('GOINTERPAY_MERCHANT_ID')))) { return Tools::displayError('Cannot parse Interpay feed.'); } foreach ($feed->rateOffer as $currency) { if ($currency->buyCurrency != 'USD') { continue; } $currency_to_update_id = Currency::getIdByIsoCode($currency->sellCurrency); if ($currency_to_update_id) { $currency_to_update = new Currency((int) $currency_to_update_id); if (Validate::isLoadedObject($currency_to_update)) { $currency_to_update->conversion_rate = (double) $currency->rate; $currency_to_update->update(); Db::getInstance()->Execute(' UPDATE ' . _DB_PREFIX_ . 'currency SET rateoffer_id = \'' . pSQL($currency->id) . '\', expiry = \'' . pSQL($currency->expiry) . '\' WHERE id_currency = ' . (int) $currency_to_update_id); } } } Configuration::updateValue('GOINTERPAY_CURRENCY_UPDATE', time()); }
public function initContent() { if ($id_cart = Tools::getValue('id_cart')) { $myCart = new Cart($id_cart); if (!Validate::isLoadedObject($myCart)) { $myCart = $this->context->cart; } } else { $myCart = $this->context->cart; } $total_to_pay = $myCart->getOrderTotal(true, Cart::BOTH); $currency_rub = new Currency(Currency::getIdByIsoCode('RUB')); if ($myCart->id_currency != $currency_rub->id) { $currency = new Currency($myCart->id_currency); $total_to_pay = $total_to_pay / $currency->conversion_rate * $currency_rub->conversion_rate; } $total_to_pay = number_format($total_to_pay, 2, '.', ''); if ($postvalidate = Configuration::get('robokassa_postvalidate')) { $order_number = $myCart->id; } else { if (!($order_number = Order::getOrderByCartId($myCart->id))) { $this->module->validateOrder((int) $myCart->id, Configuration::get('PL_OS_WAITPAYMENT'), $myCart->getOrderTotal(true, Cart::BOTH), $this->module->displayName, NULL, array(), NULL, false, $myCart->secure_key); $order_number = $this->module->currentOrder; } } $customer = new Customer($myCart->id_customer); $signature = md5(Configuration::get('robokassa_login') . ':' . $total_to_pay . ':' . $order_number . ':' . Configuration::get('robokassa_password1')); $this->context->smarty->assign(array('robokassa_login' => Configuration::get('robokassa_login'), 'robokassa_demo' => Configuration::get('robokassa_demo'), 'signature' => strtoupper($signature), 'email' => $customer->email, 'postvalidate' => $postvalidate, 'order_number' => $order_number, 'total_to_pay' => $total_to_pay, 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/')); return $this->setTemplate('redirect.tpl'); }
public function loadLocalisationPack($file, $selection, $install_mode = false, $iso_localization_pack = null) { if (!($xml = @simplexml_load_string($file))) { return false; } libxml_clear_errors(); $main_attributes = $xml->attributes(); $this->name = (string) $main_attributes['name']; $this->version = (string) $main_attributes['version']; if ($iso_localization_pack) { $id_country = (int) Country::getByIso($iso_localization_pack); if ($id_country) { $country = new Country($id_country); } if (!$id_country || !Validate::isLoadedObject($country)) { $this->_errors[] = Tools::displayError(sprintf('Cannot load country : %1d', $id_country)); return false; } if (!$country->active) { $country->active = 1; if (!$country->update()) { $this->_errors[] = Tools::displayError(sprintf('Cannot enable the associated country: %1s', $country->name)); } } } $res = true; if (empty($selection)) { $res &= $this->_installStates($xml); $res &= $this->_installTaxes($xml); $res &= $this->_installCurrencies($xml, $install_mode); $res &= $this->installConfiguration($xml); $res &= $this->installModules($xml); $res &= $this->updateDefaultGroupDisplayMethod($xml); if (($res || $install_mode) && isset($this->iso_code_lang)) { if (!($id_lang = (int) Language::getIdByIso($this->iso_code_lang, true))) { $id_lang = 1; } if (!$install_mode) { Configuration::updateValue('PS_LANG_DEFAULT', $id_lang); } } elseif (!isset($this->iso_code_lang) && $install_mode) { $id_lang = 1; } if (!Language::isInstalled(Language::getIsoById($id_lang))) { $res &= $this->_installLanguages($xml, $install_mode); $res &= $this->_installUnits($xml); } if ($install_mode && $res && isset($this->iso_currency)) { Cache::clean('Currency::getIdByIsoCode_*'); $res &= Configuration::updateValue('PS_CURRENCY_DEFAULT', (int) Currency::getIdByIsoCode($this->iso_currency)); Currency::refreshCurrencies(); } } else { foreach ($selection as $selected) { // No need to specify the install_mode because if the selection mode is used, then it's not the install $res &= Validate::isLocalizationPackSelection($selected) ? $this->{'_install' . $selected}($xml) : false; } } return $res; }
public function initContent() { $cart = $this->context->cart; $payments = array(); $payments['message'] = $this->module->l('The order status is not paid! Go to my account and then reorder'); if ($cart) { $total_to_pay = $cart->getOrderTotal(true); $rub_currency_id = Currency::getIdByIsoCode('RUB'); if ($cart->id_currency != $rub_currency_id) { $from_currency = new Currency($cart->id_curre1ncy); $to_currency = new Currency($rub_currency_id); $total_to_pay = Tools::convertPriceFull($total_to_pay, $from_currency, $to_currency); } $display = ''; if (Configuration::get('YA_P2P_ACTIVE')) { $vars_p2p = Configuration::getMultiple(array('YA_P2P_NUMBER', 'YA_P2P_ACTIVE')); $this->context->smarty->assign(array('DATA_P2P' => $vars_p2p, 'price' => number_format($total_to_pay, 2, '.', ''), 'cart' => $this->context->cart)); $display .= $this->display(__FILE__, 'payment.tpl'); } if (Configuration::get('YA_ORG_ACTIVE')) { $vars_org = Configuration::getMultiple(array('YA_ORG_SHOPID', 'YA_ORG_SCID', 'YA_ORG_ACTIVE', 'YA_ORG_TYPE')); $this->context->smarty->assign(array('DATA_ORG' => $vars_org, 'id_cart' => $cart->id, 'customer' => new Customer($cart->id_customer), 'address' => new Address($this->context->cart->id_address_delivery), 'total_to_pay' => number_format($total_to_pay, 2, '.', ''), 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->module->name . '/', 'shop_name' => Configuration::get('PS_SHOP_NAME'))); $payments = Configuration::getMultiple(array('YA_ORG_PAYMENT_YANDEX', 'YA_ORG_PAYMENT_CARD', 'YA_ORG_PAYMENT_MOBILE', 'YA_ORG_PAYMENT_WEBMONEY', 'YA_ORG_PAYMENT_TERMINAL', 'YA_ORG_PAYMENT_SBER', 'YA_ORG_PAYMENT_PB', 'YA_ORG_PAYMENT_MA', 'YA_ORG_PAYMENT_ALFA')); if (Configuration::get('YA_ORG_INSIDE')) { $payments['pt'] = Tools::getValue('type'); } else { $payments['pt'] = ''; } } } $this->context->smarty->assign($payments); return $this->setTemplate('redirectk.tpl'); }
public function exportCsv() { header("Content-Type: text/csv"); header("Content-Disposition: attachment; filename=\"export-" . date("Ymd-His") . ".csv\""); $db = Db::getInstance(); $is_cods = is_array(Tools::getValue('packetery_order_is_cod')) ? Tools::getValue('packetery_order_is_cod') : array(); foreach ($is_cods as $id => $is_cod) { $db->execute('update `' . _DB_PREFIX_ . 'packetery_order` set is_cod=' . (int) $is_cod . ' where id_order=' . (int) $id); } $ids = array_map('floor', is_array(Tools::getValue('packetery_order_id')) && count(Tools::getValue('packetery_order_id')) > 0 ? Tools::getValue('packetery_order_id') : array(0)); $data = $db->executeS('select o.id_order, a.firstname, a.lastname, a.phone, a.phone_mobile, c.email, o.total_paid total, po.id_branch, po.is_cod, o.id_currency, po.currency_branch, a.company, a.address1, a.address2, a.postcode, a.city from `' . _DB_PREFIX_ . 'orders` o join `' . _DB_PREFIX_ . 'packetery_order` po on(po.id_order=o.id_order) join `' . _DB_PREFIX_ . 'customer` c on(c.id_customer=o.id_customer) join `' . _DB_PREFIX_ . 'address` a on(a.id_address=o.id_address_delivery) where o.id_order in (' . implode(',', $ids) . ')'); $cnb_rates = null; foreach ($data as $order) { $phone = ""; foreach (array('phone', 'phone_mobile') as $field) { if (preg_match('/^(((?:\\+|00)?420)?[67][0-9]{8}|((?:\\+|00)?421|0)?9[0-9]{8})$/', preg_replace('/\\s+/', '', $order[$field]))) { $phone = trim($order[$field]); } } $currency = new Currency($order['id_currency']); $total = $order['total']; if ($currency->iso_code != $order['currency_branch']) { $target_currency = Currency::getIdByIsoCode($order['currency_branch']); if ($target_currency) { $target_currency = new Currency($target_currency); $total = round($total * $target_currency->conversion_rate / $currency->conversion_rate, 2); } else { if (!$cnb_rates) { if ($data = @Tools::file_get_contents('http://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.txt')) { $cnb_rates = array(); foreach (array_slice(explode("\n", $data), 2) as $rate) { $rate = explode('|', $rate); $cnb_rates[$rate[3]] = (double) preg_replace('/[^0-9.]*/', '', str_replace(',', '.', $rate[4])); } $cnb_rates['CZK'] = 1; } } if ($cnb_rates) { $total = round($total * $cnb_rates[$currency->iso_code] / $cnb_rates[$order['currency_branch']], 2); } } } $cod_total = $total; if ($order['currency_branch'] == 'CZK') { $cod_total = round($total); } echo ';"' . $this->csvEscape($order['id_order']) . '";"' . $this->csvEscape($order['firstname']) . '";"' . $this->csvEscape($order['lastname']) . '";"' . $this->csvEscape($order['company']) . '";"' . $this->csvEscape($order['email']) . '";"' . $this->csvEscape($phone) . '";"' . ($order['is_cod'] == 1 ? $this->csvEscape($cod_total) : "0") . '";"' . $this->csvEscape($total) . '";"' . $this->csvEscape($order['id_branch']) . '";"' . Configuration::get('PACKETERY_ESHOP_DOMAIN') . '";"' . $this->csvEscape($order['address1'] . ($order['address2'] ? ", " . $order['address2'] : "")) . '";;"' . $this->csvEscape($order['city']) . '";"' . $this->csvEscape($order['postcode']) . '"' . "\r\n"; } $db->execute('update `' . _DB_PREFIX_ . 'packetery_order` set exported=1 where id_order in(' . implode(',', $ids) . ')'); exit; }
public function initContent() { $cart = $this->context->cart; $payments = array(); $payments['message'] = $this->module->l('Заказ в статусе не оплачен! Перейдите в личный кабинет и нажмите перезаказ'); if ($cart) { $total_to_pay = $cart->getOrderTotal(true); $rub_currency_id = Currency::getIdByIsoCode('RUB'); if ($cart->id_currency != $rub_currency_id) { $from_currency = new Currency($cart->id_curre1ncy); $to_currency = new Currency($rub_currency_id); $total_to_pay = Tools::convertPriceFull($total_to_pay, $from_currency, $to_currency); } $display = ''; if (Configuration::get('YA_P2P_ACTIVE')) { $vars_p2p = Configuration::getMultiple(array('YA_P2P_NUMBER', 'YA_P2P_ACTIVE')); $this->context->smarty->assign(array('DATA_P2P' => $vars_p2p, 'price' => number_format($total_to_pay, 2, '.', ''), 'cart' => $this->context->cart)); $display .= $this->display(__FILE__, 'payment.tpl'); } if (Configuration::get('YA_ORG_ACTIVE')) { $vars_org = Configuration::getMultiple(array('YA_ORG_SHOPID', 'YA_ORG_SCID', 'YA_ORG_ACTIVE', 'YA_ORG_TYPE')); $this->context->smarty->assign(array('DATA_ORG' => $vars_org, 'id_cart' => $cart->id, 'customer' => new Customer($cart->id_customer), 'address' => new Address($this->context->cart->id_address_delivery), 'total_to_pay' => number_format($total_to_pay, 2, '.', ''), 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->module->name . '/', 'shop_name' => Configuration::get('PS_SHOP_NAME'))); $payments = Configuration::getMultiple(array('YA_ORG_PAYMENT_YANDEX', 'YA_ORG_PAYMENT_CARD', 'YA_ORG_PAYMENT_MOBILE', 'YA_ORG_PAYMENT_WEBMONEY', 'YA_ORG_PAYMENT_TERMINAL', 'YA_ORG_PAYMENT_SBER', 'YA_ORG_PAYMENT_PB', 'YA_ORG_PAYMENT_MA', 'YA_ORG_PAYMENT_ALFA')); $payments['pt'] = Tools::getValue('type'); } //$this->module->validateOrder((int)$cart->id, _PS_OS_PREPARATION_, $cart->getOrderTotal(true, Cart::BOTH), $this->module->displayName, NULL, array(), NULL, false, $cart->secure_key); } $this->context->smarty->assign($payments); return $this->setTemplate('redirectk.tpl'); }
public function addData($data, $add, $type) { $delivery = array(); $cart = new Cart(); if ($data->{$type}->currency == 'RUR') { $currency_id = Currency::getIdByIsoCode('RUB'); } else { $currency_id = Currency::getIdByIsoCode($data->cart->currency); } $def_currency = Configuration::get('PS_CURRENCY_DEFAULT'); $this->context->cookie->id_currency = $def_currency != $currency_id ? $currency_id : $def_currency; $this->context->cookie->write(); $this->context->currency = new Currency($this->context->cookie->id_currency); $cart->id_lang = (int) $this->context->cookie->id_lang; $cart->id_currency = (int) $this->context->cookie->id_currency; $cart->id_guest = (int) $this->context->cookie->id_guest; $cart->add(); $this->context->cookie->id_cart = (int) $cart->id; $this->context->cookie->write(); $buyer = isset($data->{$type}->buyer) ? $data->{$type}->buyer : ''; $b = array(); if ($add) { $delivery = isset($data->{$type}->delivery->address) ? $data->{$type}->delivery->address : new stdClass(); $street = isset($delivery->street) ? ' Улица: ' . $delivery->street : 'Самовывоз'; $subway = isset($delivery->subway) ? ' Метро: ' . $delivery->subway : ''; $block = isset($delivery->block) ? ' Корпус/Строение: ' . $delivery->block : ''; $floor = isset($delivery->floor) ? ' Этаж: ' . $delivery->floor : ''; $house = isset($delivery->house) ? ' Дом: ' . $delivery->house : ''; $address1 = $street . $subway . $block . $floor . $house; $customer = new Customer(Configuration::get('YA_POKUPKI_CUSTOMER')); $address = new Address(); $address->firstname = $customer->firstname; $address->lastname = $customer->lastname; $address->phone_mobile = isset($buyer->phone) ? $buyer->phone : 999999; $address->postcode = isset($delivery->postcode) ? $delivery->postcode : 00; $address->address1 = $address1; $address->city = isset($delivery->city) ? $delivery->city : 'Город'; $address->alias = 'pokupki_' . substr(md5(time() . _COOKIE_KEY_), 0, 7); $address->id_customer = $customer->id; $address->id_country = Configuration::get('PS_COUNTRY_DEFAULT'); $address->save(); $cart->id_address_invoice = (int) $address->id; $cart->id_address_delivery = (int) $address->id; $id_address = (int) $address->id; $cart->update(); $cart->id_customer = (int) $customer->id; $this->context->cookie->id_customer = (int) $customer->id; $this->context->cookie->write(); $b = array('address' => $address, 'customer' => $customer); } CartRule::autoRemoveFromCart($this->context); CartRule::autoAddToCart($this->context); $a = array('cart' => $cart); $dd = array_merge($a, $b); return $dd; }
public function postProcess() { parent::postProcess(); //ИД заказа $ordernumber = Tools::getValue('InvId'); //Сумма заказа $amount = Tools::getValue('OutSum'); $signature = md5($amount . ':' . $ordernumber . ':' . Configuration::get('robokassa_password2')); //Проверка подписи if (strtoupper($signature) != Tools::getValue('SignatureValue')) { robokassa::validateAnsver($this->module->l('Invalid signature')); } if (Configuration::get('robokassa_postvalidate')) { $cart = new Cart((int) $ordernumber); //Проверка существования заказа if (!Validate::isLoadedObject($cart)) { robokassa::validateAnsver($this->module->l('Cart does not exist')); } $total_to_pay = $cart->getOrderTotal(true, Cart::BOTH); $currency_rub = new Currency(Currency::getIdByIsoCode('RUB')); if ($cart->id_currency != $currency_rub->id) { $currency = new Currency($cart->id_currency); $total_to_pay = $total_to_pay / $currency->conversion_rate * $currency_rub->conversion_rate; } $total_to_pay = number_format($total_to_pay, 2, '.', ''); //Проверка суммы заказа if ($amount != $total_to_pay) { robokassa::validateAnsver($this->module->l('Incorrect payment summ')); } $this->module->validateOrder((int) $cart->id, Configuration::get('PS_OS_PAYMENT'), $cart->getOrderTotal(true, Cart::BOTH), $this->module->displayName, NULL, array(), NULL, false, $cart->secure_key); } else { $order = new Order((int) $ordernumber); //Проверка существования заказа if (!Validate::isLoadedObject($order)) { robokassa::validateAnsver($this->module->l('Order does not exist')); } $total_to_pay = $order->total_paid; $currency_rub = new Currency(Currency::getIdByIsoCode('RUB')); if ($order->id_currency != $currency_rub->id) { $currency = new Currency($order->id_currency); $total_to_pay = $total_to_pay / $currency->conversion_rate * $currency_rub->conversion_rate; } $total_to_pay = number_format($total_to_pay, 2, '.', ''); //Проверка суммы заказа if ($amount != $total_to_pay) { robokassa::validateAnsver($this->module->l('Incorrect payment summ')); } //Меняем статус заказа $history = new OrderHistory(); $history->id_order = $ordernumber; $history->changeIdOrderState(Configuration::get('PS_OS_PAYMENT'), $ordernumber); $history->addWithemail(true); } die('OK' . $ordernumber); }
/** * @see FrontController::initContent() */ public function initContent() { parent::initContent(); $cart = $this->context->cart; if (!$this->module->checkCurrency($cart)) { Tools::redirect('index.php?controller=order'); } $dkkC = new Currency(Currency::getIdByIsoCode('DKK')); $this->context->smarty->assign(array('nbProducts' => $cart->nbProducts(), 'cust_currency' => $cart->id_currency, 'name_currency' => $dkkC->name, 'id_currency_accepted' => $dkkC->id, 'id_currency' => $cart->id_currency, 'currencies' => $this->module->getCurrency((int) $cart->id_currency), 'total' => $this->module->__getPriceDkk($cart), 'this_path' => $this->module->getPathUri(), 'this_path_bw' => $this->module->getPathUri(), 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->module->name . '/')); $this->setTemplate('payment_execution.tpl'); }
/** * @see FrontController::postProcess() */ public function postProcess() { // Log requests from Privat API side in Debug mode. if (Configuration::get('PRIVAT24_DEBUG_MODE')) { $logger = new FileLogger(); $logger->setFilename(_PS_ROOT_DIR_ . '/log/' . $this->module->name . '_' . date('Ymd_His') . '_response.log'); $logger->logError($_POST); } $payment = array(); parse_str(Tools::getValue('payment'), $payment); $hash = sha1(md5(Tools::getValue('payment') . $this->module->merchant_password)); if ($payment && $hash === Tools::getValue('signature')) { if ($payment['state'] == 'ok') { $state = Configuration::get('PRIVAT24_WAITINGPAYMENT_OS'); $cart_id = (int) $payment['order']; $order = new Order(Order::getOrderByCartId($cart_id)); if (!Validate::isLoadedObject($order)) { PrestaShopLogger::addLog('Privat24: cannot get order by cart id ' . $cart_id, 3); die; } if ($order->getCurrentState() != $state) { PrestaShopLogger::addLog(sprintf('Privat24: order id %s current state %s !== expected state %s', $order->id, $order->getCurrentState(), $state), 3); die; } // Check paid currency and paid amount. $id_currency = Currency::getIdByIsoCode($payment['ccy']); if (!$id_currency) { PrestaShopLogger::addLog(sprintf('Privat24: order id %s cannot get currency id by iso code: %s', $order->id, $payment['ccy']), 3); die; } if ($order->id_currency != $id_currency) { PrestaShopLogger::addLog(sprintf('Privat 24: order id %s, order currency id %s does not match with %s', $order->id, $order->id_currency, $id_currency), 3); die; } if ((double) $order->total_paid != (double) $payment['amt']) { PrestaShopLogger::addLog(sprintf('Privat 24: order id %s order total paid %s does not match %s', $order->id, $order->total_paid, $payment['amt']), 3); die; } $order_history = new OrderHistory(); $order_history->id_order = $order->id; $order_history->changeIdOrderState(_PS_OS_PAYMENT_, $order->id); $order_history->addWithemail(); $this->setPaymentTransaction($order, $payment); $this->module->paymentNotify($order, $payment); PrestaShopLogger::addLog(sprintf('Privat24 payment accepted: order id: %s, amount: %s, ref: %s', $order->id, $payment['amt'], $payment['ref']), 1); } else { PrestaShopLogger::addLog(sprintf('Privat24 payment failed: state: %s, order: %s, ref: %s', $payment['state'], $payment['order'], $payment['ref']), 3, null, null, null, true); } } else { PrestaShopLogger::addLog('Privat24: Payment callback bad signature.', 3, null, null, null, true); } die; }
/** * Check if a curency already exists. * * @param int|string $iso_code int for iso code number string for iso code * @return boolean */ public static function exists($iso_code) { if (is_int($iso_code)) { $id_currency_exists = Currency::getIdByIsoCodeNum($iso_code); } else { $id_currency_exists = Currency::getIdByIsoCode($iso_code); } if ($id_currency_exists) { return true; } else { return false; } }
public function postProcess() { parent::postProcess(); $log_on = Configuration::get('YA_P2P_LOGGING_ON'); $cart = $this->context->cart; if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) { Tools::redirect('index.php?controller=order&step=1'); } $customer = new Customer($cart->id_customer); if (!Validate::isLoadedObject($customer)) { Tools::redirect('index.php?controller=order&step=1'); } $this->myCart = $this->context->cart; $total_to_pay = $cart->getOrderTotal(true); $rub_currency_id = Currency::getIdByIsoCode('RUB'); if ($cart->id_currency != $rub_currency_id) { $from_currency = new Currency($cart->id_currency); $to_currency = new Currency($rub_currency_id); $total_to_pay = Tools::convertPriceFull($total_to_pay, $from_currency, $to_currency); } if ($total_to_pay > 0 && $total_to_pay < 1) { $total_to_pay_limit = '1.00'; } else { $total_to_pay_limit = number_format($total_to_pay, 2, '.', ''); } $total_to_pay = number_format($total_to_pay, 2, '.', ''); $this->module->payment_status = ''; $code = Tools::getValue('code'); $type = Tools::getValue('type'); if (empty($code)) { $scope = array("payment.to-account(\"" . Configuration::get('YA_P2P_NUMBER') . "\",\"account\").limit(," . $total_to_pay_limit . ")", "money-source(\"wallet\",\"card\")"); if ($type == 'wallet') { if ($log_on) { $this->module->log_save('p2p_redirect: ' . $this->module->l('Type wallet')); } $auth_url = API::buildObtainTokenUrl(Configuration::get('YA_P2P_IDENTIFICATOR'), $this->context->link->getModuleLink('yamodule', 'redirect_wallet', array(), true), $scope); } elseif ($type == 'card') { if ($log_on) { $this->module->log_save('redirect: ' . $this->module->l('Type card')); } Tools::redirect($this->context->link->getModuleLink('yamodule', 'redirect_card', array('code' => true, 'cnf' => true), true), ''); } if ($log_on) { $this->module->log_save('p2p_redirect: url = ' . $auth_url); } Tools::redirect($auth_url, ''); } }
public function loadLocalisationPack($file, $selection, $install_mode = false) { if (!($xml = simplexml_load_string($file))) { return false; } $main_attributes = $xml->attributes(); $this->name = (string) $main_attributes['name']; $this->version = (string) $main_attributes['version']; if (empty($selection)) { $res = true; $res &= $this->_installStates($xml); $res &= $this->_installTaxes($xml); $res &= $this->_installCurrencies($xml, $install_mode); $res &= $this->_installUnits($xml); $res &= $this->installConfiguration($xml); $res &= $this->installModules($xml); $res &= $this->_installLanguages($xml, $install_mode); if ($res && isset($this->iso_code_lang)) { if (!($id_lang = (int) Language::getIdByIso($this->iso_code_lang))) { $id_lang = 1; } if (!$install_mode) { Configuration::updateValue('PS_LANG_DEFAULT', $id_lang); } } if ($install_mode && $res && isset($this->iso_currency)) { Cache::clean('Currency::getIdByIsoCode_*'); $res &= Configuration::updateValue('PS_CURRENCY_DEFAULT', (int) Currency::getIdByIsoCode($this->iso_currency)); Currency::refreshCurrencies(); } return $res; } foreach ($selection as $selected) { if (strtolower((string) $selected) == 'currencies') { if (!Validate::isLocalizationPackSelection($selected) || !$this->{'_install' . ucfirst($selected)}($xml, true)) { return false; } } else { if (!Validate::isLocalizationPackSelection($selected) || !$this->{'_install' . ucfirst($selected)}($xml)) { return false; } } } return true; }
/** * This method get useful payment details and assign them into the Order back-office template * @param bool|true $response * @param bool|true $params * @return int */ public function processResponse($response = true, $params = true) { $alipay = new Alipay(); if (!$response) { $this->errors[] = $alipay->l('Impossible to retrieve transaction information'); return -1; } $xmlObj = new SimpleXMLElement($response); if ($xmlObj && $xmlObj->is_success == 'T') { $this->tplVars = get_object_vars($xmlObj->response->trade); $this->tplVars['currency'] = Currency::getIdByIsoCode($params['currency']); $this->tplVars['iso_code'] = $params['currency']; $this->tplVars['amount_in_currency'] = $params['total_fee']; } else { $this->errors[] = $alipay->l('Impossible to retrieve transaction information'); return -1; } }
public function __construct(SimpleXMLElement $order_xml = null) { if (!$order_xml) { return; } /** Backward compatibility */ require dirname(__FILE__) . '/../backward_compatibility/backward.php'; list($this->firstname, $this->familyname) = $this->_formatShippingAddressName($order_xml->ShippingAddress->Name); $this->id_order_ref = (string) $order_xml->OrderID; $this->amount = (string) $order_xml->AmountPaid; $this->status = (string) $order_xml->CheckoutStatus->Status; $this->name = (string) $order_xml->ShippingAddress->Name; $this->address1 = (string) $order_xml->ShippingAddress->Street1; $this->address2 = (string) $order_xml->ShippingAddress->Street2; $this->city = (string) $order_xml->ShippingAddress->CityName; $this->state = (string) $order_xml->ShippingAddress->StateOrProvince; $this->country_iso_code = (string) $order_xml->ShippingAddress->Country; $this->country_name = (string) $order_xml->ShippingAddress->CountryName; $this->postalcode = (string) $order_xml->ShippingAddress->PostalCode; $this->shippingService = (string) $order_xml->ShippingServiceSelected->ShippingService; $this->shippingServiceCost = (string) $order_xml->ShippingServiceSelected->ShippingServiceCost; $this->payment_method = (string) $order_xml->CheckoutStatus->PaymentMethod; $this->id_order_seller = (string) $order_xml->ShippingDetails->SellingManagerSalesRecordNumber; $amount_paid_attr = $order_xml->AmountPaid->attributes(); $this->id_currency = Currency::getIdByIsoCode($amount_paid_attr['currencyID']); if (count($order_xml->TransactionArray->Transaction)) { $this->email = (string) $order_xml->TransactionArray->Transaction[0]->Buyer->Email; } $phone = (string) $order_xml->ShippingAddress->Phone; if (!$phone || !Validate::isPhoneNumber($phone)) { $this->phone = '0100000000'; } else { $this->phone = $phone; } $this->id_orders = array(); $date = Tools::substr((string) $order_xml->CreatedTime, 0, 10) . ' ' . Tools::substr((string) $order_xml->CreatedTime, 11, 8); $this->date = $date; $this->date_add = $date; if ($order_xml->TransactionArray->Transaction) { $this->product_list = $this->_getProductsFromTransactions($order_xml->TransactionArray->Transaction); } $this->write_logs = (bool) Configuration::get('EBAY_ACTIVATE_LOGS'); }
public function loadLocalisationPack($file, $selection, $install_mode = false) { if (!($xml = simplexml_load_string($file))) { return false; } $main_attributes = $xml->attributes(); $this->name = (string) $main_attributes['name']; $this->version = (string) $main_attributes['version']; $res = true; if (empty($selection)) { $res &= $this->_installStates($xml); $res &= $this->_installTaxes($xml); $res &= $this->_installCurrencies($xml, $install_mode); $res &= $this->_installUnits($xml); $res &= $this->installConfiguration($xml); $res &= $this->installModules($xml); $res &= $this->_installLanguages($xml, $install_mode); $res &= $this->updateDefaultGroupDisplayMethod($xml); if ($res && isset($this->iso_code_lang)) { if (!($id_lang = (int) Language::getIdByIso($this->iso_code_lang))) { $id_lang = 1; } if (!$install_mode) { Configuration::updateValue('PS_LANG_DEFAULT', $id_lang); } } if ($install_mode && $res && isset($this->iso_currency)) { Cache::clean('Currency::getIdByIsoCode_*'); $res &= Configuration::updateValue('PS_CURRENCY_DEFAULT', (int) Currency::getIdByIsoCode($this->iso_currency)); Currency::refreshCurrencies(); } } else { foreach ($selection as $selected) { // No need to specify the install_mode because if the selection mode is used, then it's not the install $res &= Validate::isLocalizationPackSelection($selected) ? $this->{'_install' . $selected}($xml) : false; } } return $res; }
private function _getCart($id_customer, $id_address_billing, $id_address_shipping, $productsNode, $currency, $shipping_method) { $cart = new Cart(); $cart->id_customer = $id_customer; $cart->id_address_invoice = $id_address_billing; $cart->id_address_delivery = $id_address_shipping; $cart->id_currency = Currency::getIdByIsoCode((string) $currency == '' ? 'EUR' : (string) $currency); $cart->id_lang = Configuration::get('PS_LANG_DEFAULT'); $cart->recyclable = 0; $cart->secure_key = md5(uniqid(rand(), true)); $actual_configuration = unserialize(Configuration::get('SHOPPING_FLUX_SHIPPING_MATCHING')); $carrier_to_load = isset($actual_configuration[base64_encode(Tools::safeOutput($shipping_method))]) ? (int) $actual_configuration[base64_encode(Tools::safeOutput($shipping_method))] : (int) Configuration::get('SHOPPING_FLUX_CARRIER'); $carrier = Carrier::getCarrierByReference($carrier_to_load); //manage case PS_CARRIER_DEFAULT is deleted $carrier = is_object($carrier) ? $carrier : new Carrier($carrier_to_load); $cart->id_carrier = $carrier->id; $cart->add(); foreach ($productsNode->Product as $product) { $skus = explode('_', $product->SKU); $added = $cart->updateQty((int) $product->Quantity, (int) $skus[0], isset($skus[1]) ? $skus[1] : null); if ($added < 0 || $added === false) { return false; } } $cart->update(); return $cart; }
public function execValidation($cart) { global $cookie; if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->active) { Tools::redirect('index.php?controller=order&step=1'); } // Check that this payment option is still available in case the customer changed his address just before the end of the checkout process $authorized = false; foreach (Module::getPaymentModules() as $module) { if ($module['name'] == 'veritranspay') { $authorized = true; break; } } if (!$authorized) { die($this->module->l('This payment method is not available.', 'validation')); } $customer = new Customer($cart->id_customer); if (!Validate::isLoadedObject($customer)) { Tools::redirect('index.php?controller=order&step=1'); } $usd = Configuration::get('VT_KURS'); $cf = Configuration::get('VT_CONVENIENCE_FEE') * 0.01; $list_enable_payments = array(); if (Configuration::get('ENABLED_CREDIT_CARD')) { $list_enable_payments[] = "credit_card"; } if (Configuration::get('ENABLED_CIMB')) { $list_enable_payments[] = "cimb_clicks"; } if (Configuration::get('ENABLED_MANDIRI')) { $list_enable_payments[] = "mandiri_clickpay"; } if (Configuration::get('ENABLED_PERMATAVA')) { $list_enable_payments[] = "bank_transfer"; } if (Configuration::get('ENABLED_BRIEPAY')) { $list_enable_payments[] = "bri_epay"; } if (Configuration::get('ENABLED_TELKOMSEL_CASH')) { $list_enable_payments[] = "telkomsel_cash"; } if (Configuration::get('ENABLED_XL_TUNAI')) { $list_enable_payments[] = "xl_tunai"; } if (Configuration::get('ENABLED_MANDIRI_BILL')) { $list_enable_payments[] = "echannel"; } if (Configuration::get('ENABLED_BBM_MONEY')) { $list_enable_payments[] = "bbm_money"; } if (Configuration::get('ENABLED_INDOMARET')) { $list_enable_payments[] = "cstore"; } if (Configuration::get('ENABLED_INDOSAT_DOMPETKU')) { $list_enable_payments[] = "indosat_dompetku"; } if (Configuration::get('ENABLED_MANDIRI_ECASH')) { $list_enable_payments[] = "mandiri_ecash"; } //error_log(print_r($list_enable_payments,TRUE)); $veritrans = new Veritrans_Config(); //SETUP Veritrans_Config::$serverKey = Configuration::get('VT_SERVER_KEY'); Veritrans_Config::$isProduction = Configuration::get('VT_ENVIRONMENT') == 'production' ? true : false; $url = Veritrans_Config::getBaseUrl(); if (version_compare(Configuration::get('PS_VERSION_DB'), '1.5') == -1) { $shipping_cost = $cart->getOrderShippingCost(); } else { $shipping_cost = $cart->getTotalShippingCost(); } $currency = new Currency($cookie->id_currency); $total = $cart->getOrderTotal(true, Cart::BOTH); $mailVars = array(); $billing_address = new Address($cart->id_address_invoice); $delivery_address = new Address($cart->id_address_delivery); if (Configuration::get('VT_3D_SECURE') == 'on' || Configuration::get('VT_3D_SECURE') == 1) { Veritrans_Config::$is3ds = true; } if (Configuration::get('VT_SANITIZED') == 'on' || Configuration::get('VT_SANITIZED') == 1) { Veritrans_Config::$isSanitized = true; } //error_log('sanitized '.Configuration::get('VT_SANITIZED')); // Billing Address $params_billing_address = array('first_name' => $billing_address->firstname, 'last_name' => $billing_address->lastname, 'address' => $billing_address->address1, 'city' => $billing_address->city, 'postal_code' => $billing_address->postcode, 'phone' => $this->determineValidPhone($billing_address->phone, $billing_address->phone_mobile), 'country_code' => 'IDN'); if ($cart->isVirtualCart()) { } else { if ($cart->id_address_delivery != $cart->id_address_invoice) { $params_shipping_address = array('first_name' => $delivery_address->firstname, 'last_name' => $delivery_address->lastname, 'address' => $delivery_address->address1, 'city' => $delivery_address->city, 'postal_code' => $delivery_address->postcode, 'phone' => $this->determineValidPhone($delivery_address->phone, $delivery_address->phone_mobile), 'country_code' => 'IDN'); } else { $params_shipping_address = $params_billing_address; } } $params_customer_details = array('first_name' => $billing_address->firstname, 'last_name' => $billing_address->lastname, 'email' => $customer->email, 'phone' => $this->determineValidPhone($billing_address->phone, $billing_address->phone_mobile), 'billing_address' => $params_billing_address, 'shipping_address' => $params_shipping_address); $items = $this->addCommodities($cart, $shipping_cost, $usd); // convert the currency $cart_currency = new Currency($cart->id_currency); if ($cart_currency->iso_code != 'IDR') { // check whether if the IDR is installed or not if (Currency::exists('IDR', null)) { // use default rate if (version_compare(Configuration::get('PS_VERSION_DB'), '1.5') == -1) { $conversion_func = function ($input) use($cart_currency) { return Tools::convertPrice($input, new Currency(Currency::getIdByIsoCode('IDR')), true); }; } else { $conversion_func = function ($input) use($cart_currency) { return Tools::convertPriceFull($input, $cart_currency, new Currency(Currency::getIdByIsoCode('IDR'))); }; } } else { // use rate $conversion_func = function ($input) { return $input * intval(Configuration::get('VT_KURS')); }; } foreach ($items as &$item) { $item['price'] = intval(round(call_user_func($conversion_func, $item['price']))); } } else { if ($cart_currency->iso_code == 'IDR') { foreach ($items as &$item) { $item['price'] = intval(round($item['price'])); } } } $this->validateOrder($cart->id, Configuration::get('VT_ORDER_STATE_ID'), $cart->getOrderTotal(true, Cart::BOTH), $this->displayName, NULL, $mailVars, (int) $currency->id, false, $customer->secure_key); $gross_amount = 0; unset($item); foreach ($items as $item) { $gross_amount += $item['price'] * $item['quantity']; } $isBniInstallment = Configuration::get('ENABLED_BNI_INSTALLMENT') == 1; $isMandiriInstallment = Configuration::get('ENABLED_MANDIRI_INSTALLMENT') == 1; $warning_redirect = false; $fullPayment = true; $installment_type_val = Configuration::get('VT_ENABLE_INSTALLMENT'); $param_required; switch ($installment_type_val) { case 'all_product': if ($isBniInstallment) { //$bni_term2 = $this->getTermInstallment('BNI'); $a = Configuration::get('VT_INSTALLMENTS_BNI'); $term = explode(',', $a); $bni_term = $term; //error_log(print_r($bni_term,true)); //error_log($bni_term,true); } if ($isMandiriInstallment) { $mandiri_term = $this->getTermInstallment('MANDIRI'); $a = Configuration::get('VT_INSTALLMENTS_MANDIRI'); $term = explode(',', $a); $mandiri_term = $term; //error_log($mandiri_term,true); //error_log(print_r($mandiri_term,true)); } $param_installment = array(); if ($isBniInstallment) { $param_installment['bni'] = $bni_term; } if ($isMandiriInstallment) { $param_installment['mandiri'] = $mandiri_term; } $param_required = "false"; $fullPayment = false; break; case 'certain_product': $param_installment = null; $products_cart = $cart->getProducts(); $num_product = count($products_cart); if ($num_product == 1) { $attr_product = explode(',', $products_cart[0]['attributes_small']); foreach ($attr_product as $att) { $att_trim = ltrim($att); $att_arr = explode(' ', $att_trim); //error_log(print_r($att_arr,true)); if (strtolower($att_arr[0]) == 'installment') { $fullPayment = false; $param_installment = array(); $param_installment[strtolower($att_arr[1])] = array($att_arr[2]); } } } else { $warning_redirect = true; $keys['message'] = 1; } $param_required = "true"; break; case 'off': $param_installment = null; break; } //error_log($param_installment,true); // $param_payment_option = array( // 'installment' => array( // 'required' => $param_required, // 'installment_terms' => $param_installment // ) // ); $params_all = array('payment_type' => Configuration::get('VT_PAYMENT_TYPE'), 'vtweb' => array('enabled_payments' => $list_enable_payments), 'transaction_details' => array('order_id' => $this->currentOrder, 'gross_amount' => $gross_amount), 'item_details' => $items, 'customer_details' => $params_customer_details); if ($gross_amount < 500000) { $warning_redirect = true; $keys['message'] = 2; } if (!$warning_redirect && ($isBniInstallment || $isMandiriInstallment) && !$fullPayment) { $params_all['vtweb']['payment_options'] = $param_payment_option; } if (Configuration::get('VT_API_VERSION') == 2 && Configuration::get('VT_PAYMENT_TYPE') != 'vtdirect') { try { // Redirect to Veritrans VTWeb page if ($this->isInstallmentCart($cart->getProducts()) || $installment_type_val == 'all_product') { $keys['isWarning'] = $warning_redirect; } else { $keys['isWarning'] = false; } $keys['redirect_url'] = Veritrans_Vtweb::getRedirectionUrl($params_all); } catch (Exception $e) { $keys['errors'] = $e->getMessage(); echo $e->getMessage(); } return $keys; } else { if (Configuration::get('VT_API_VERSION') == 2 && Configuration::get('VT_PAYMENT_TYPE') == 'vtdirect') { echo 'not yet implementation.'; exit; } else { echo 'The Veritrans API versions and the payment type is not valid.'; exit; } } }
public function addOrder(ShopgateOrder $order) { $this->log("PS start add_order", ShopgateLogger::LOGTYPE_DEBUG); $shopgateOrder = PSShopgateOrder::instanceByOrderNumber($order->getOrderNumber()); if ($shopgateOrder->id) { throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_DUPLICATE_ORDER, 'external_order_id: ' . $shopgateOrder->id_order, true); } $comments = array(); // generate products array $products = $this->insertOrderItems($order); //Get or create customer $id_customer = Customer::customerExists($order->getMail(), true, false); $customer = new Customer($id_customer ? $id_customer : (int) $order->getExternalCustomerId()); if (!$customer->id) { $customer = $this->createCustomer($customer, $order); } // prepare addresses: company has to be shorten. add mobile phone / telephone $this->prepareAddresses($order); //Get invoice and delivery addresses $invoiceAddress = $this->getPSAddress($customer, $order->getInvoiceAddress()); $deliveryAddress = $order->getInvoiceAddress() == $order->getDeliveryAddress() ? $invoiceAddress : $this->getPSAddress($customer, $order->getDeliveryAddress()); //Creating currency $this->log("PS setting currency", ShopgateLogger::LOGTYPE_DEBUG); $id_currency = $order->getCurrency() ? Currency::getIdByIsoCode($order->getCurrency()) : $this->id_currency; $currency = new Currency($id_currency ? $id_currency : $this->id_currency); //Creating new cart $this->log("PS set cart variables", ShopgateLogger::LOGTYPE_DEBUG); $cart = new Cart(); $cart->id_lang = $this->id_lang; $cart->id_currency = $currency->id; $cart->id_address_delivery = $deliveryAddress->id; $cart->id_address_invoice = $invoiceAddress->id; $cart->id_customer = $customer->id; if (version_compare(_PS_VERSION_, '1.4.1.0', '>=')) { // id_guest is a connection to a ps_guest entry which includes screen width etc. // is_guest field only exists in Prestashop 1.4.1.0 and higher $cart->id_guest = $customer->is_guest; } $cart->recyclable = 0; $cart->gift = 0; $cart->id_carrier = (int) Configuration::get('SHOPGATE_CARRIER_ID'); $cart->secure_key = $customer->secure_key; $this->log("PS try to create cart", ShopgateLogger::LOGTYPE_DEBUG); if (!$cart->add()) { throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_DATABASE_ERROR, 'Unable to create cart', true); } //Adding items to cart $this->log("PS adding items to cart", ShopgateLogger::LOGTYPE_DEBUG); foreach ($products as $p) { $this->log("PS cart updateQty product id: " . $p['id_product'], ShopgateLogger::LOGTYPE_DEBUG); $this->log("PS cart updateQty product quantity: " . $p['quantity'], ShopgateLogger::LOGTYPE_DEBUG); $this->log("PS cart updateQty product quantity_difference: " . $p['quantity_difference'], ShopgateLogger::LOGTYPE_DEBUG); $this->log("PS cart updateQty product id_product_attribute: " . $p['id_product_attribute'], ShopgateLogger::LOGTYPE_DEBUG); $this->log("PS cart updateQty product delivery address: " . $deliveryAddress->id, ShopgateLogger::LOGTYPE_DEBUG); //TODO deal with customizations $id_customization = false; if ($p['quantity'] - $p['quantity_difference'] > 0) { // only if the result of $p['quantity'] - $p['quantity_difference'] is higher then 0 $cart->updateQty($p['quantity'] - $p['quantity_difference'], $p['id_product'], $p['id_product_attribute'], $id_customization, 'up', $deliveryAddress->id); } if ($p['quantity_difference'] > 0) { $this->log("PS try to add cart message ", ShopgateLogger::LOGTYPE_DEBUG); $message = new Message(); $message->id_cart = $cart->id; $message->private = 1; $message->message = 'Warning, wanted quantity for product "' . $p['name'] . '" was ' . $p['quantity'] . ' unit(s), however, the amount in stock is ' . $p['quantity_in_stock'] . ' unit(s). Only ' . $p['quantity_in_stock'] . ' unit(s) were added to the order'; $message->save(); } } $id_order_state = 0; $shopgate = new Shopgate(); $payment_name = $shopgate->getTranslation('Mobile Payment'); $this->log("PS map payment method", ShopgateLogger::LOGTYPE_DEBUG); if (!$order->getIsShippingBlocked()) { $id_order_state = $this->getOrderStateId('PS_OS_PREPARATION'); switch ($order->getPaymentMethod()) { case 'SHOPGATE': $payment_name = $shopgate->getTranslation('Shopgate'); break; case 'PREPAY': $payment_name = $shopgate->getTranslation('Bankwire'); $id_order_state = $this->getOrderStateId('PS_OS_BANKWIRE'); break; case 'COD': $payment_name = $shopgate->getTranslation('Cash on Delivery'); break; case 'PAYPAL': $payment_name = $shopgate->getTranslation('PayPal'); break; default: break; } } else { $id_order_state = $this->getOrderStateId('PS_OS_SHOPGATE'); switch ($order->getPaymentMethod()) { case 'SHOPGATE': $payment_name = $shopgate->getTranslation('Shopgate'); break; case 'PREPAY': $payment_name = $shopgate->getTranslation('Bankwire'); break; case 'COD': $payment_name = $shopgate->getTranslation('Cash on Delivery'); break; case 'PAYPAL': $id_order_state = $this->getOrderStateId('PS_OS_PAYPAL'); $payment_name = $shopgate->getTranslation('PayPal'); break; default: $id_order_state = $this->getOrderStateId('PS_OS_SHOPGATE'); break; } } $shippingCosts = $order->getAmountShipping() + $order->getAmountShopPayment(); //Creates shopgate order record and save shipping cost for future use $this->log("PS set PSShopgateOrder object variables", ShopgateLogger::LOGTYPE_DEBUG); $shopgateOrder = new PSShopgateOrder(); $shopgateOrder->order_number = $order->getOrderNumber(); $shopgateOrder->shipping_cost = $shippingCosts; $shopgateOrder->shipping_service = Configuration::get('SHOPGATE_SHIPPING_SERVICE'); $shopgateOrder->id_cart = $cart->id; $shopgateOrder->shop_number = $this->config->getShopNumber(); $shopgateOrder->comments = $this->jsonEncode($comments); if (version_compare(_PS_VERSION_, '1.4.0.2', '<')) { $this->log("PS lower 1.4.0.2: ", ShopgateLogger::LOGTYPE_DEBUG); // Fix: sets in database ps_delivery all zones of passed shippingCosts $this->setShippingCosts(0); } $this->log("PS try creating PSShopgateOrder object", ShopgateLogger::LOGTYPE_DEBUG); if (!$shopgateOrder->add()) { throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_DATABASE_ERROR, 'Unable to create shopgate order', true); } //PS 1.5 compatibility if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { $this->log("PS 1.5.x.x: set cart context", ShopgateLogger::LOGTYPE_DEBUG); $this->context = Context::getContext(); $this->context->cart = $cart; $this->log("PS 1.5.x.x: \$cart->setDeliveryOption(array(\$cart->id_address_delivery => \$cart->id_carrier.','))\n\n==============", ShopgateLogger::LOGTYPE_DEBUG); $cart->setDeliveryOption(array($cart->id_address_delivery => $cart->id_carrier . ',')); $this->log("PS 1.5.x.x: \$cart->update()", ShopgateLogger::LOGTYPE_DEBUG); $cart->update(); $cart->id_carrier = (int) Configuration::get('SHOPGATE_CARRIER_ID'); } $amountPaid = $order->getAmountComplete(); if (version_compare(_PS_VERSION_, '1.4.0.2', '<')) { // substract the shipping costs. $amountPaid -= $shippingCosts; } $this->log("\$shopgate->validateOrder(\$cart->id, \$id_order_state, \$amountPaid, \$payment_name, NULL, array(), NULL, false, \$cart->secure_key", ShopgateLogger::LOGTYPE_DEBUG); $this->log("\$cart->id = " . var_export($cart->id, true) . "\n\$id_order_state = " . var_export($id_order_state, true) . "\n\$amountPaid = " . var_export($amountPaid, true) . "\n\$payment_name = " . var_export($payment_name, true) . "\n\$cart->secure_key" . var_export($cart->secure_key, true) . "\n==============", ShopgateLogger::LOGTYPE_DEBUG); try { $shopgate->validateOrder($cart->id, $id_order_state, $amountPaid, $payment_name, NULL, array(), NULL, false, $cart->secure_key); } catch (Swift_Message_MimeException $ex) { $this->log("\$shopgate->validateOrder(\$cart->id, \$id_order_state, \$amountPaid, \$payment_name, NULL, array(), NULL, false, \$cart->secure_key) FAILED with Swift_Message_MimeException", ShopgateLogger::LOGTYPE_ERROR); // catch Exception if there is a problem with sending mails } if (version_compare(_PS_VERSION_, '1.4.0.2', '<') && (int) $shopgate->currentOrder > 0) { $this->log("PS < 1.4.0.2: update shipping and payment cost", ShopgateLogger::LOGTYPE_DEBUG); // in versions below 1.4.0.2 the shipping and payment costs must be updated after the order $updateShopgateOrder = new Order($shopgate->currentOrder); $updateShopgateOrder->total_paid = $order->getAmountComplete(); $updateShopgateOrder->total_paid_real = $order->getAmountComplete(); $updateShopgateOrder->total_products_wt = $order->getAmountItems(); $updateShopgateOrder->total_shipping = $order->getAmountShipping() + $order->getAmountShopPayment(); $updateShopgateOrder->update(); } if ((int) $shopgate->currentOrder > 0) { $this->log("\$shopgateOrder->update()", ShopgateLogger::LOGTYPE_DEBUG); $shopgateOrder->id_order = $shopgate->currentOrder; $shopgateOrder->update(); return array('external_order_id' => $shopgate->currentOrder, 'external_order_number' => $shopgate->currentOrder); } else { $this->log("\$shopgateOrder->delete()", ShopgateLogger::LOGTYPE_DEBUG); $shopgateOrder->delete(); throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_DATABASE_ERROR, 'Unable to create order', true); } }
public function postProcess() { parent::postProcess(); $this->log_on = Configuration::get('YA_P2P_LOGGING_ON'); $cart = $this->context->cart; if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) { Tools::redirect('index.php?controller=order&step=1'); } $customer = new Customer($cart->id_customer); if (!Validate::isLoadedObject($customer)) { Tools::redirect('index.php?controller=order&step=1'); } $this->myCart = $this->context->cart; $total_to_pay = $cart->getOrderTotal(true); $rub_currency_id = Currency::getIdByIsoCode('RUB'); if ($cart->id_currency != $rub_currency_id) { $from_currency = new Currency($cart->id_currency); $to_currency = new Currency($rub_currency_id); $total_to_pay = Tools::convertPriceFull($total_to_pay, $from_currency, $to_currency); } if ($total_to_pay > 0 && $total_to_pay < 1) { $total_to_pay_limit = '1.00'; } else { $total_to_pay_limit = number_format($total_to_pay, 2, '.', ''); } $total_to_pay = number_format($total_to_pay, 2, '.', ''); $this->module->payment_status = false; $code = Tools::getValue('code'); $cnf = Tools::getValue('cnf'); if (empty($code)) { Tools::redirect('index.php?controller=order&step=3'); } elseif (!empty($code) && $cnf) { $comment = $message = $this->module->l('total:') . $total_to_pay . $this->module->l(' rub'); $response = ExternalPayment::getInstanceId(Configuration::get('YA_P2P_IDENTIFICATOR')); if ($response->status == "success") { if ($this->log_on) { $this->module->log_save('card_redirect: ' . $this->module->l('get instance success')); } $instance_id = $response->instance_id; $external_payment = new ExternalPayment($instance_id); $payment_options = array("pattern_id" => "p2p", "to" => Configuration::get('YA_P2P_NUMBER'), "amount_due" => $total_to_pay, "comment" => trim($comment), "message" => trim($message), "label" => $this->context->cart->id); $response = $external_payment->request($payment_options); if ($response->status == "success") { if ($this->log_on) { $this->module->log_save('card_redirect: ' . $this->module->l('request success')); } $request_id = $response->request_id; $this->context->cookie->ya_encrypt_CRequestId = urlencode(base64_encode($request_id)); $this->context->cookie->write(); do { $process_options = array("request_id" => $request_id, 'ext_auth_success_uri' => $this->context->link->getModuleLink('yamodule', 'payment_card', array(), true), 'ext_auth_fail_uri' => $this->context->link->getModuleLink('yamodule', 'payment_card', array(), true)); $result = $external_payment->process($process_options); if ($result->status == "in_progress") { sleep(1); } } while ($result->status == "in_progress"); if ($result->status == 'success') { $this->updateStatus($res); $this->error = false; } elseif ($result->status == 'ext_auth_required') { $url = sprintf("%s?%s", $result->acs_uri, http_build_query($result->acs_params)); if ($this->log_on) { $this->module->log_save('card_redirect: ' . $this->module->l('redirect to') . ' ' . $url); } Tools::redirect($url, ''); exit; } elseif ($result->status == 'refused') { $this->errors[] = $this->module->descriptionError($resp->error) ? $this->module->descriptionError($resp->error) : $result->error; if ($this->log_on) { $this->module->log_save('card_redirect:refused ' . $this->module->descriptionError($resp->error) ? $this->module->descriptionError($resp->error) : $result->error); } $this->module->payment_status = 102; } } } } }
/** * Get currency object by iso_code * @param string $iso_code ISO code * @return Currency Currency Object */ protected function getCurrencyByIsoCode($iso_code) { $idCurrency = (int) Currency::getIdByIsoCode($iso_code); $currency = new Currency($idCurrency); if (!PowaTagValidate::currencyEnable($currency)) { $this->addError(sprintf($this->module->l('Currency not found : %s'), $iso_code), PowaTagErrorType::$CURRENCY_NOT_SUPPORTED); return false; } return $currency; }
/** * Check if a curency already exists. * * @param int|string $iso_code int for iso code number string for iso code * @return boolean */ public static function exists($iso_code, $iso_code_num, $id_shop = 0) { if (is_int($iso_code)) { $id_currency_exists = Currency::getIdByIsoCodeNum((int) $iso_code_num, (int) $id_shop); } else { $id_currency_exists = Currency::getIdByIsoCode($iso_code, (int) $id_shop); } if ($id_currency_exists) { return true; } else { return false; } }
public function hookPayment($params) { global $smarty; // check currency $currency = new Currency((int) $params['cart']->id_currency); if (!$this->isCurrencyActive($currency->iso_code)) { return false; } // check max amount $amount = (double) $params['cart']->getOrderTotal(true, Cart::BOTH); $id_currency_max = Currency::getIdByIsoCode($this->max_amount_currency); if ($currency->id != $id_currency_max) { $amount = $amount / $currency->conversion_rate; $amount = Tools::convertPrice($amount, new Currency((int) $id_currency_max)); } if ($amount > $this->max_amount) { return false; } $smarty->assign(array('pic_url' => _MODULE_DIR_ . '/' . $this->name . '/img/payment-logo.png', 'payment_name' => $this->displayName, 'module_name' => $this->name)); return $this->display(dirname(__FILE__), 'payment.tpl'); }
public function postProcess() { parent::postProcess(); $dd = serialize($_REQUEST); $this->log_on = Configuration::get('YA_ORG_LOGGING_ON'); if ($this->log_on) { $this->module->log_save('payment_kassa ' . $dd); } Tools::getValue('label') ? $data = explode('_', Tools::getValue('label')) : ($data = explode('_', Tools::getValue('customerNumber'))); if (!empty($data) && $data[0] == 'KASSA') { $cart = new Cart($data[1]); if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) { Tools::redirect('index.php?controller=order&step=1'); } $customer = new Customer($cart->id_customer); if (!Validate::isLoadedObject($customer)) { Tools::redirect('index.php?controller=order&step=1'); } $total_to_pay = $cart->getOrderTotal(true); $rub_currency_id = Currency::getIdByIsoCode('RUB'); if ($cart->id_currency != $rub_currency_id) { $from_currency = new Currency($cart->id_currency); $to_currency = new Currency($rub_currency_id); $total_to_pay = Tools::convertPriceFull($total_to_pay, $from_currency, $to_currency); } $total_to_pay = number_format($total_to_pay, 2, '.', ''); $amount = Tools::getValue('orderSumAmount'); $action = Tools::getValue('action'); $shopId = Tools::getValue('shopId'); $invoiceId = Tools::getValue('invoiceId'); $signature = md5($action . ';' . $amount . ';' . Tools::getValue('orderSumCurrencyPaycash') . ';' . Tools::getValue('orderSumBankPaycash') . ';' . $shopId . ';' . $invoiceId . ';' . Tools::getValue('customerNumber') . ';' . trim(Configuration::get('YA_ORG_MD5_PASSWORD'))); $ord = $cart->orderExists() ? new Order((int) Order::getOrderByCartId($cart->id)) : $this->module->validateOrder($cart->id, _PS_OS_PREPARATION_, $cart->getOrderTotal(true, Cart::BOTH), $this->module->displayName, NULL, array(), NULL, false, $cart->secure_key); if (!$ord) { $this->module->validateResponse($this->module->l('Invalid order number'), 1, $action, $shopId, $invoiceId, true); } if (Tools::strtoupper($signature) != Tools::strtoupper(Tools::getValue('md5'))) { $this->module->validateResponse($this->module->l('Invalid signature'), 1, $action, $shopId, $invoiceId, true); } if ($amount != $total_to_pay) { $this->module->validateResponse($this->module->l('Incorrect payment amount'), $action == 'checkOrder' ? 100 : 200, $action, $shopId, $invoiceId, true); } if ($action == 'checkOrder') { if ($this->log_on) { $this->module->log_save('payment_kassa: checkOrder invoiceId="' . $invoiceId . '" shopId="' . $shopId . '" ' . $this->module->l('check order')); } $this->module->validateResponse('', 0, $action, $shopId, $invoiceId, true); } if ($action == 'paymentAviso') { $history = new OrderHistory(); $history->id_order = $ord->id; $history->changeIdOrderState(Configuration::get('PS_OS_PAYMENT'), $ord->id); $history->addWithemail(true); if ($this->log_on) { $this->module->log_save('payment_kassa: paymentAviso invoiceId="' . $invoiceId . '" shopId="' . $shopId . '" #' . $ord->id . ' ' . $this->module->l('Order success')); } $this->module->validateResponse('', 0, $action, $shopId, $invoiceId, true); } } else { Tools::redirect('index.php?controller=order&step=3'); } }
/** * Save in special database each buyer protection product for a certificate, * Each Trusted Shops particular characteristics is saved. * Create a product in Prestashop database to allow added each of them in cart. * * @param array|stdClass $protection_items * @param string $ts_id */ private function _saveProtectionItems($protection_items, $ts_id) { $sql = ' DELETE ts, p, pl FROM `' . _DB_PREFIX_ . TSBuyerProtection::DB_ITEMS . '` AS ts LEFT JOIN `' . _DB_PREFIX_ . 'product` AS p ON ts.`id_product` = p.`id_product` LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` AS pl ON ts.`id_product` = pl.`id_product` WHERE ts.`ts_id`="' . $ts_id . '"'; Db::getInstance()->Execute($sql); foreach ($protection_items as $key => $item) { //add hidden product $product = new Product(); foreach ($this->available_languages as $iso => $lang) { $language = Language::getIdByIso(strtolower($iso)); if ((int) $language !== 0) { $product->name[$language] = 'TrustedShops guarantee'; $product->link_rewrite[$language] = 'trustedshops_guarantee'; } } // If the default lang is different than available languages : // (Bug occurred otherwise) if (!array_key_exists(Language::getIsoById((int) Configuration::get('PS_LANG_DEFAULT')), $this->available_languages)) { $product->name[(int) Configuration::get('PS_LANG_DEFAULT')] = 'Trustedshops'; $product->link_rewrite[(int) Configuration::get('PS_LANG_DEFAULT')] = 'trustedshops'; } // Add specifics translations $id_lang = Language::getIdByIso('de'); if ((int) $id_lang > 0) { $product->name[$id_lang] = 'Trusted Shops Käuferschutz'; } $id_lang = Language::getIdByIso('en'); if ((int) $id_lang > 0) { $product->name[$id_lang] = 'Trusted Shops buyer protection'; } $id_lang = Language::getIdByIso('fr'); if ((int) $id_lang > 0) { $product->name[$id_lang] = 'Trusted Shops protection acheteur'; } $product->quantity = 1000; $product->price = ToolsCore::convertPrice($item->grossFee, Currency::getIdByIsoCode($item->currency)); $product->id_category_default = TSBuyerProtection::$CAT_ID; $product->active = true; $product->id_tax = 0; $product->add(); if ($product->id) { $sql = ' INSERT INTO `' . _DB_PREFIX_ . TSBuyerProtection::DB_ITEMS . '` ( `creation_date`, `id_product`, `ts_id`, `id`, `currency`, `gross_fee`, `net_fee`, `protected_amount_decimal`, `protection_duration_int`, `ts_product_id` ) VALUES ( "' . pSQL($item->creationDate) . '", "' . pSQL($product->id) . '", "' . pSQL($ts_id) . '", "' . (int) $item->id . '", "' . pSQL($item->currency) . '", "' . pSQL($item->grossFee) . '", "' . pSQL($item->netFee) . '", "' . pSQL($item->protectedAmountDecimal) . '", "' . pSQL($item->protectionDurationInt) . '", "' . pSQL($item->tsProductID) . '" )'; Db::getInstance()->Execute($sql); } else { $this->errors['products'] = $this->l('Product wasn\'t saved.'); } } }
public function genericImportWS($className, $fields, $save = false) { $return = ''; $json = array(); $errors = array(); $json['hasError'] = false; $json['datas'] = array_values($fields); $languages = array(); $defaultLanguage = ''; $table = $this->supportedImports[strtolower($className)]['table']; $object = new $className(); $rules = call_user_func(array($className, 'getValidationRules'), $className); if (sizeof($rules['requiredLang']) || sizeof($rules['sizeLang']) || sizeof($rules['validateLang']) || Tools::isSubmit('syncLangWS') || Tools::isSubmit('syncCurrency')) { $moduleName = Tools::getValue('moduleName'); if (Validate::isModuleName($moduleName) && file_exists('../../modules/' . $moduleName . '/' . $moduleName . '.php')) { require_once '../../modules/' . $moduleName . '/' . $moduleName . '.php'; $importModule = new $moduleName(); $defaultLanguage = new Language((int) Configuration::get('PS_LANG_DEFAULT')); $languages = $importModule->getLangagues(); if (Tools::isSubmit('syncLangWS')) { $defaultIdLand = $importModule->getDefaultIdLang(); $defaultLanguageImport = new Language(Language::getIdByIso($languages[$defaultIdLand]['iso_code'])); if ($defaultLanguage->iso_code != $defaultLanguageImport->iso_code) { $errors[] = $this->l('Default language doesn\'t match : ') . '<br>' . Configuration::get('PS_SHOP_NAME') . ' : ' . $defaultLanguage->name . ' ≠ ' . $importModule->displayName . ' : ' . $defaultLanguageImport->name . '<br>' . $this->l('Please change default language in your configuration'); } } if (Tools::isSubmit('syncCurrency')) { $defaultIdCurrency = $importModule->getDefaultIdCurrency(); $currencies = $importModule->getCurrencies(); if (!empty($currencies[$defaultIdCurrency]['iso_code'])) { $defaultCurrencyImport = new Currency((int) Currency::getIdByIsoCode($currencies[$defaultIdCurrency]['iso_code'])); } else { $defaultCurrencyImport = new Currency((int) Currency::getIdByIsoCodeNum($currencies[$defaultIdCurrency]['iso_code_num'])); } $defaultCurrency = new Currency((int) Configuration::get('PS_CURRENCY_DEFAULT')); if ($defaultCurrency->iso_code != $defaultCurrencyImport->iso_code) { $errors[] = $this->l('Default currency doesn\'t match : ') . '<br>' . Configuration::get('PS_SHOP_NAME') . ' : ' . $defaultCurrency->name . ' ≠ ' . $importModule->displayName . ' : ' . $defaultCurrencyImport->name . '<br>' . $this->l('Please change default currency in your configuration'); } } if (!empty($errors)) { die('{"hasError" : true, "error" : ' . Tools::jsonEncode($errors) . '}'); } } else { die('{"hasError" : true, "error" : ["FATAL ERROR"], "datas" : []}'); } } foreach ($fields as $key => $field) { $id = $this->supportedImports[strtolower($className)]['identifier']; //remove wrong fields (ex : id_toto in Customer) foreach ($field as $name => $value) { if (!array_key_exists($name, get_object_vars($object)) and $name != $id and $name != 'association' and $name != 'images' and strtolower($className) != 'cart') { unset($field[$name]); } } $return = $this->validateRules($rules, $field, $className, $languages, $defaultLanguage); $fields[$key] = $field; if (!empty($return)) { //skip mode if (Tools::getValue('hasErrors') == 1) { unset($fields[$key]); } $errors[] = $return; array_unshift($errors[sizeof($errors) - 1], $field[$id]); } } if (sizeof($errors) > 0) { $json['hasError'] = true; $json['error'] = $errors; } if ($save || Tools::isSubmit('syncLang') || Tools::isSubmit('syncLangWS')) { //add language if not exist in prestashop if ($className == 'Language') { if (Tools::isSubmit('syncLang') || Tools::isSubmit('syncLangWS')) { $add = true; } else { $add = false; } $errors = $this->checkAndAddLang($fields, $add); } elseif ($className == 'Cart') { $this->saveOrders($fields); } else { $return = $this->saveObject($className, $fields); $this->cleanPositions($table); //insert association if (array_key_exists('association', $this->supportedImports[strtolower($className)])) { $this->insertAssociation(strtolower($className), $fields); } if (!empty($return)) { $json['hasError'] = true; $json['error'] = $return; } } if ($className == 'Category' and sizeof($fields) != (int) Tools::getValue('nbr_import')) { $this->updateCat(); } } if (sizeof($errors) > 0 and is_array($errors)) { $json['hasError'] = true; $json['error'] = $errors; } die(Tools::jsonEncode($json)); }
private function _getCart($id_customer, $id_address_billing, $id_address_shipping, $productsNode) { $cart = new Cart(); $cart->id_customer = $id_customer; $cart->id_address_invoice = $id_address_billing; $cart->id_address_delivery = $id_address_shipping; $cart->id_currency = Currency::getIdByIsoCode('EUR'); $cart->id_lang = Configuration::get('PS_LANG_DEFAULT'); $cart->recyclable = 0; $cart->secure_key = md5(uniqid(rand(), true)); $cart->id_carrier = (int) Configuration::get('PS_CARRIER_DEFAULT'); $cart->add(); foreach ($productsNode->Product as $product) { $skus = explode('_', $product->SKU); if (!$cart->updateQty((int) $product->Quantity, (int) $skus[0], isset($skus[1]) ? $skus[1] : NULL)) { return false; } } $cart->update(); return $cart; }