URLOPT_MAXREDIRS => 10, CURLOPT_FOLLOWLOCATION => true, )); $content = curl_exec($curl); curl_close($curl); return $content; } elseif (in_array(ini_get('allow_url_fopen'), array('On', 'on', '1')) || !preg_match('/^https?:\/\//', $url)) { return Tools::file_get_contents($url, $use_include_path, $stream_context); } else { return false; } } public function renderAdminBodyHtml() { $this->renderPaymentMethodForm(); return $this->_html; } public function renderPaymentMethodForm() { if(Tools::isSubmit('addnewPayment') || Tools::isSubmit('editpayment')) return $this->renderFormPayment(); $order_states = OrderState::getOrderStates($this->context->language->id); $fields_list = array( 'id_ets_paymentmethod' => array( 'title' => $this->l('Id'), 'width' => 40, 'type' => 'text', 'filter' => true, 'sort' => 'p.id_ets_paymentmethod', ), 'logo_payment' => array( 'title' => $this->l('Logo'), 'width' => 57, 'type' => 'text', ), 'method_name' => array( 'title' => $this->l('Payment method name'), 'type' => 'text', 'filter' => true, 'sort' => 'pl.method_name', ), 'fee' => array( 'title' => $this->l('Fee'), 'width' => 140, 'type' => 'text', ), 'fee_tax' => array( 'title' => $this->l('Fee tax'), 'width' => 140, 'type' => 'text', ), 'order_status' => array( 'title' => $this->l('Order status'), 'strip_tag' => false, 'filter' => true, 'type' => 'select', 'filter_list' => array( 'id_option' => 'id_order_state', 'value' => 'name', 'list' => $order_states, ) ), 'position' => array( 'title' => $this->l('Position'), 'type' => 'text', 'sort' => 'position', 'update_position' => true, ), 'active' => array( 'title' => $this->l('Enabled'), 'width' => 50, 'type' => 'active', 'strip_tag' => false, 'filter' => true, 'sort' => 'p.active', 'filter_list' => array( 'id_option' => 'enabled', 'value' => 'title', 'list' => array( 0 => array( 'enabled' => 1, 'title' => $this->l('Yes') ), 1 => array( 'enabled' => 0, 'title' => $this->l('No') ) ) ) ) ); $payments = $this->getPaymentsWithFilter(); if ($payments) { foreach ($payments as &$payment) { if ($payment['logo_payment']) $payment['logo_payment'] = array( 'image_field' => true, 'img_url' => _PS_ETS_PAYMENT_FEE_IMG_ . $payment['logo_payment'], 'width' => 57 ); else $payment['logo_payment'] ='--'; if ($payment['fee_type'] == 'fixed_fee') $payment['fee'] = $payment['fee_amount'] == 0 ? $this->l('Free') : self::displayPrice($payment['fee_amount'] * $this->context->currency->conversion_rate) . ($payment['free_for_order_over'] ? '(Free for order over: ' . self::displayPrice((float)$payment['free_for_order_over'] * $this->context->currency->conversion_rate) . ')' : ''); elseif ($payment['fee_type'] == 'percentage' || $payment['fee_type']=='percentage_fixed') { $html_extra = ''; if ($payment['min_fee']) $html_extra .= 'Minimum fee: ' . self::displayPrice((float)$payment['min_fee'] * $this->context->currency->conversion_rate) . ', '; if ($payment['max_fee']) $html_extra .= 'Maximum fee: ' . self::displayPrice((float)$payment['max_fee'] * $this->context->currency->conversion_rate) . ', '; if ($payment['free_for_order_over']) $html_extra .= 'Free for order over: ' . self::displayPrice((float)$payment['free_for_order_over'] * $this->context->currency->conversion_rate); $payment['fee'] = $payment['percentage'] . '%' .($payment['fee_type']=='percentage_fixed' && $payment['fee_amount'] ? ' + '. self::displayPrice($payment['fee_amount'] * $this->context->currency->conversion_rate):'') . ($payment['max_fee'] || $payment['min_fee'] || $payment['free_for_order_over'] ? ' (' . trim($html_extra, ', ') . ')' : ''); } else $payment['fee'] = $this->l('Free'); $payment['fee_tax'] = $payment['fee_type'] == 'free' || !$payment['fee_type'] ? '--' : ($payment['fee_tax'] ?: $this->l('No tax')); $payment['order_status'] = $this->displayOrderStatus($payment['order_status']); } } $order_status = trim(Tools::getValue('order_status')); $id_ets_paymentmethod = Tools::getValue('id_ets_paymentmethod'); $method_name = Tools::getValue('method_name'); $active = Tools::getValue('active'); $sort_type = Tools::getValue('sort_type', 'asc'); if(!in_array($sort_type,array('desc','asc'))) $sort_type = 'desc'; $sort = Tools::getValue('sort', 'position'); if(!in_array($sort,array('position','order_status','id_ets_paymentmethod','method_name','active'))) $sort ='position'; $listData = array( 'name' => 'payment', 'actions' => array('edit', 'delete', 'view'), 'currentIndex' => $this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name . '&control=payment_method', 'identifier' => 'id_ets_paymentmethod', 'show_action' => true, 'title' => $this->l('Custom payment methods'), 'fields_list' => $fields_list, 'field_values' => $payments, 'show_toolbar' => true, 'sort' => $sort, 'sort_type' => $sort_type, 'filter_params' => $this->getFilterParams($fields_list), 'show_reset' => ($order_status != '' && Validate::isCleanHtml($order_status)) || (trim($id_ets_paymentmethod) != '' && Validate::isCleanHtml($id_ets_paymentmethod) && !Tools::isSubmit('del')) || (trim($method_name) != '' && Validate::isCleanHtml($method_name)) || (trim($active) != '' && Validate::isCleanHtml($active)) ? true : false, 'show_add_new' => true, ); $this->_html .= $this->renderList($listData); $this->renderFormConfig(); } public function renderFormPayment() { $order_status_default = array( array( 'id_order_state' => '', 'name' => '--', 'color' => '#ffffff', ) ); $order_status = OrderState::getOrderStates($this->context->language->id); $order_status = array_merge($order_status_default, $order_status); if ($id_ets_paymentmethod = (int)Tools::getValue('id_ets_paymentmethod')) { if(Ets_paymentmethod_class::checkExists($id_ets_paymentmethod)) $paymentmethod = new Ets_paymentmethod_class($id_ets_paymentmethod, $this->context->language->id); else return $this->_html .= $this->display(__FILE__,'no_payment.tpl'); } else $paymentmethod = new Ets_paymentmethod_class(); $fields_form = array( 'form' => array( 'legend' => array( 'title' => ($id_ets_paymentmethod ? $this->l('Edit') : $this->l('Add new')) . ' ' . $this->l('payment method') . ($id_ets_paymentmethod ? ' #' . $id_ets_paymentmethod : ''), 'icon' => 'icon-cogs' ), 'input' => array( array( 'name' => 'method_name', 'type' => 'text', 'label' => $this->l('Payment method name'), 'required' => true, 'lang' => true, ), array( 'name' => 'description', 'type' => 'textarea', 'label' => $this->l('Description'), 'lang' => true, 'desc' => $this->l('This text will be displayed below payment method name on checkout page. Custom variable: ') . $this->display(__FILE__, 'varible_description.tpl'), ), array( 'name' => 'confirmation_message', 'label' => $this->l('Confirmation message'), 'type' => 'textarea', 'lang' => true, 'desc' => $this->l('This message appears on order confirmation page (the page that customer is redirected to when they complete their order). Custom variable: ') . $this->display(__FILE__, 'varible_confirmation_message.tpl'), ), array( 'name' => 'return_message', 'label' => $this->l('Return message'), 'type' => 'textarea', 'lang' => true, 'autoload_rte' => true, 'desc' => $this->l('This message appears on order confirmation page (the page that customer is redirected to when they complete their order). Custom variable: ') . $this->display(__FILE__, 'varible_return_message.tpl'), ), array( 'name' => 'logo_payment', 'type' => 'file', 'label' => $this->l('Payment logo'), 'desc' => sprintf($this->l('Accepted formats: jpg, png, gif. Limit: %sMb Recommended size: 57X57 (px)'), Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE')), 'image' => $paymentmethod->logo_payment ? Ets_payment_utils::html([ 'tag' => 'img', 'atts' => [ 'width' => 86, 'height' => 49, 'src' => _PS_ETS_PAYMENT_FEE_IMG_ . $paymentmethod->logo_payment, 'alt' => $paymentmethod->method_name, 'title' => $paymentmethod->method_name ] ]) : null, 'delete_url' => defined('PS_ADMIN_DIR') ? 'index.php?controller=AdminModules&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name . '&delete_payment_logo=1&control=payment_method&id_ets_paymentmethod=' . (int)$paymentmethod->id . '&token=' . Tools::getAdminToken('AdminModules' . (int)(self::getIdFromClassName('AdminModules')) . (int)$this->context->employee->id) : '', ), array( 'name' => 'order_status', 'type' => 'select', 'label' => $this->l('Order status'), 'required' => true, 'options' => array( 'query' => $order_status, 'id' => 'id_order_state', 'name' => 'name', ), 'desc' => $this->l('Order status to be set when customer selects this payment method '), ), array( 'name' => 'fee_type', 'type' => 'select', 'label' => $this->l('Fee type'), 'options' => array( 'query' => array( array( 'id' => 'free', 'name' => $this->l('Free (no payment fee)') ), array( 'id' => 'fixed_fee', 'name' => $this->l('Fixed amount'), ), array( 'name' => $this->l('Percentage'), 'id' => 'percentage' ), array( 'name' => $this->l('Percentage + Fixed amount'), 'id' => 'percentage_fixed', ), ), 'id' => 'id', 'name' => 'name', ), ), array( 'name' => 'fee_amount', 'label' => $this->l('Fee amount'), 'type' => 'text', 'required' => true, 'form_group_class' => 'custom fixed_fee percentage_fixed', 'suffix' => $this->context->currency->iso_code, ), array( 'name' => 'percentage', 'label' => $this->l('Percentage'), 'type' => 'text', 'required' => true, 'form_group_class' => 'custom percentage percentage_fixed', 'suffix' => '%', 'desc' => $this->l('Tax and shipping cost included before calculating payment fee'), ), array( 'name' => 'fee_based_on', 'type' => 'radio', 'label' => $this->l('Calculate fee based on'), 'values' => array( array( 'label' => $this->l('Total (tax include)'), 'id' => 'fee_based_on_1', 'value' => '1' ), array( 'label' => $this->l('Total (tax exclude)'), 'id' => 'fee_based_on_0', 'value' => '0' ), ), 'form_group_class' => 'custom percentage percentage_fixed', 'default' => '0', ), array( 'name' => 'id_tax_rules_group', 'type' => 'select', 'label' => $this->l('Fee tax'), 'options' => array( 'query' => TaxRulesGroup::getTaxRulesGroupsForOptions(), 'id' => 'id_tax_rules_group', 'name' => 'name' ), 'form_group_class' => 'custom percentage fixed_fee percentage_fixed', 'default' => '0', ), array( 'name' => 'max_fee', 'label' => $this->l('Maximum fee'), 'type' => 'text', 'form_group_class' => 'custom percentage percentage_fixed', 'suffix' => $this->context->currency->iso_code, 'desc' => $this->l('Leave blank to ignore this limit'), ), array( 'name' => 'min_fee', 'label' => $this->l('Minimum fee'), 'type' => 'text', 'form_group_class' => 'custom percentage percentage_fixed', 'suffix' => $this->context->currency->iso_code, 'desc' => $this->l('Leave blank to ignore this limit'), ), array( 'name' => 'free_for_order_over', 'label' => $this->l('Free for order over'), 'type' => 'text', 'form_group_class' => 'custom percentage fixed_fee percentage_fixed', 'suffix' => $this->context->currency->iso_code, 'desc' => $this->l('Tax and shipping cost included. Leave blank to apply payment fee for all orders'), ), array( 'label' => $this->l('Minimum total order value'), 'type' => 'text', 'name' => 'minimum_order', 'suffix' => $this->context->currency->iso_code, 'desc' => $this->l('This payment fee is only available if total order value satisfies this condition. Leave blank to ignore this condition.'), ), array( 'label' => $this->l('Maximum total order value'), 'type' => 'text', 'name' => 'maximum_order', 'suffix' => $this->context->currency->iso_code, 'desc' => $this->l('This payment fee is only available if total order value satisfies this condition. Leave blank to ignore this condition.'), ), array( 'label' => $this->l('Customer groups'), 'type' => 'select', 'name' => 'customer_group', 'id' => 'customer_group', 'multiple' => true, 'options' => array( 'query' => array_merge(array(array('id_group' => '0', 'name' => $this->l('All'))), Group::getGroups($this->context->language->id) ), 'id' => 'id_group', 'name' => 'name' ), 'desc' => $this->l('This payment method is available for these customer groups'),), array( 'label' => $this->l('Countries'), 'type' => 'select', 'name' => 'countries', 'id' => 'countries', 'multiple' => true, 'options' => array( 'query' => array_merge(array(array('id_country' => '0', 'name' => $this->l('All'))), Country::getCountries($this->context->language->id, true)), 'id' => 'id_country', 'name' => 'name' ), 'desc' => $this->l('This payment method is available for these countries'), ), array( 'label' => $this->l('Carriers'), 'type' => 'select', 'name' => 'carriers', 'multiple' => true, 'id' => 'carriers', 'options' => array( 'query' => array_merge(array(array('id_reference' => '0', 'name' => $this->l('All'))), $this->getcarriers()), 'id' => 'id_reference', 'name' => 'name' ), 'desc' => $this->l('This payment method is available for these carriers'), ), array( 'name' => 'active', 'label' => $this->l('Active'), 'type' => 'switch', 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Yes') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('No') ) ), ), ), 'submit' => array( 'title' => $this->l('Save'), ), 'buttons' => array( array( 'href' => $this->context->link->getAdminLink('AdminModules', true) . '&configure=ets_payment_with_fee&tab_module=payments_gateways&module_name=ets_payment_with_fee&list=true', 'icon' => 'process-icon-cancel', 'title' => $this->l('Back'), ) ) ), ); if ($id_ets_paymentmethod) $fields_form['form']['input'][] = array('type' => 'hidden', 'name' => 'id_ets_paymentmethod'); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $this->fields_form = array(); $helper->module = $this; $helper->identifier = $this->identifier; $helper->submit_action = 'savePaymentMethod'; $helper->currentIndex =''; $helper->token = Tools::getAdminTokenLite('AdminModules'); $language = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->override_folder = '/'; $helper->tpl_vars = array( 'base_url' => $this->context->shop->getBaseURL(), 'language' => array( 'id_lang' => $language->id, 'iso_code' => $language->iso_code ), 'fields_value' => $this->getFiledPaymentMethod(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, 'cancel_url' => $this->baseAdminPath . '&control=payment_method&list=true', 'currencies' => Currency::getCurrencies(), 'defaultFormCurrency' => (int)Configuration::get('PS_CURRENCY_DEFAULT'), 'add_new' => $id_ets_paymentmethod ? true : false, 'image_baseurl' => _PS_ETS_PAYMENT_FEE_IMG_, ); $this->_html .= $helper->generateForm(array($fields_form)); } public function renderListModules() { $id_module = (int)Tools::getValue('id_module'); if ($id_module && !Tools::isSubmit('ets_payment_submit_module')) { $modules = $this->getModuleWithFilter(' AND pm.id_shop ="'.(int)$this->context->shop->id.'" AND m.id_module=' . (int)$id_module); if(!$modules) $modules = $this->getModuleWithFilter(' AND m.id_module=' . (int)$id_module); if ($modules) { $module = $modules[0]; $paypalFeePolicyNoticeInputs = array(); if ($this->isPayPalFeePolicyModuleName($module['name'])) { $paypalFeePolicyNoticeInputs[] = array( 'type' => 'html', 'name' => 'paypal_fee_policy_notice', 'html_content' => $this->getPayPalFeePolicyNoticeHtml(), 'col' => 9, ); } $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Edit payment fee: ') . $module['name'], 'icon' => 'icon-cogs' ), 'input' => array_merge($paypalFeePolicyNoticeInputs, array( array( 'name' => 'fee_type', 'type' => 'select', 'label' => $this->l('Fee type'), 'options' => array( 'query' => array( array( 'id' => 'free', 'name' => $this->l('Free (no payment fee)') ), array( 'id' => 'fixed_fee', 'name' => $this->l('Fixed amount '), ), array( 'name' => $this->l('Percentage'), 'id' => 'percentage' ), array( 'name' => $this->l('Percentage + Fixed amount'), 'id' => 'percentage_fixed' ) ), 'id' => 'id', 'name' => 'name', ), ), array( 'name' => 'fee_amount', 'label' => $this->l('Fee amount'), 'type' => 'text', 'required' => true, 'form_group_class' => 'custom fixed_fee percentage_fixed', 'suffix' => $this->context->currency->iso_code, ), array( 'name' => 'percentage', 'label' => $this->l('Percentage'), 'type' => 'text', 'required' => true, 'form_group_class' => 'custom percentage percentage_fixed', 'suffix' => '%', 'desc' => $this->l('Tax and shipping cost included before calculating payment fee'), ), array( 'name' => 'fee_based_on', 'type' => 'radio', 'label' => $this->l('Calculate fee based on'), 'values' => array( array( 'label' => $this->l('Total (tax include)'), 'id' => 'fee_based_on_1', 'value' => '1' ), array( 'label' => $this->l('Total (tax exclude)'), 'id' => 'fee_based_on_0', 'value' => '0' ), ), 'form_group_class' => 'custom percentage percentage_fixed', 'default' => '0', ), array( 'name' => 'id_tax_rules_group', 'type' => 'select', 'label' => $this->l('Fee tax'), 'options' => array( 'query' => TaxRulesGroup::getTaxRulesGroupsForOptions(), 'id' => 'id_tax_rules_group', 'name' => 'name' ), 'form_group_class' => 'custom percentage fixed_fee percentage_fixed', 'default' => '0', ), array( 'name' => 'max_fee', 'label' => $this->l('Maximum fee'), 'type' => 'text', 'form_group_class' => 'custom percentage percentage_fixed', 'suffix' => $this->context->currency->iso_code, 'desc' => $this->l('Leave blank to ignore this limit'), ), array( 'name' => 'min_fee', 'label' => $this->l('Minimum fee'), 'type' => 'text', 'form_group_class' => 'custom percentage percentage_fixed', 'suffix' => $this->context->currency->iso_code, 'desc' => $this->l('Leave blank to ignore this limit'), ), array( 'name' => 'free_for_order_over', 'label' => $this->l('Free for order over'), 'type' => 'text', 'form_group_class' => 'custom percentage fixed_fee', 'suffix' => $this->context->currency->iso_code, 'desc' => $this->l('Tax and shipping cost included. Leave blank to apply payment fee for all orders'), ), array( 'label' => $this->l('Minimum total order value'), 'type' => 'text', 'name' => 'minimum_order', 'suffix' => $this->context->currency->iso_code, 'desc' => $this->l('This payment fee is only available if total order value satisfies this condition. Leave blank to ignore this condition.'), ), array( 'label' => $this->l('Maximum total order value'), 'type' => 'text', 'name' => 'maximum_order', 'suffix' => $this->context->currency->iso_code, 'desc' => $this->l('This payment fee is only available if total order value satisfies this condition. Leave blank to ignore this condition.'), ), )), 'submit' => array( 'title' => $this->l('Save'), ), 'buttons' => array( array( 'href' => $this->context->link->getAdminLink('AdminPaymentFee', true), 'icon' => 'process-icon-cancel', 'title' => $this->l('Back'), ) ) ), ); $fields_form['form']['input'][] = array('type' => 'hidden', 'name' => 'id_module'); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; oup']) { $payment_method['fee'] = $this->getPriceIncl($payment_method['fee'], $payment_method['id_tax_rules_group']);return 90; } } return $payment_method['fee']; } } } public function hookDisplayOverrideTemplate($params) { $id_order = (int)Tools::getValue('id_order'); if (isset($params['template_file']) && $params['template_file'] == 'checkout/order-confirmation' && ($order_method = Ets_paymentmethod_class::getPaymentMethodByIdOrder($id_order)) && $order_method['id_paymentmethod']) { if ($order_method['fee']) $fee = self::displayPrice($order_method['fee']); else $fee = $this->l('Free'); $paymentMothod = new Ets_paymentmethod_class($order_method['id_paymentmethod'], $this->context->language->id); $message = $paymentMothod->confirmation_message; $message = str_replace(array('[payment_method]', '[fee]', '[email]'), array($order_method['method_name'], $fee, $this->context->customer->email), $message); $this->context->smarty->assign('message', $message); return $this->getTemplatePath('checkout/order-confirmation.tpl'); } } public function updatePositionPayment() { $page = (int)Tools::getValue('page',1); $payments = Tools::getValue('payment'); if ($payments && Ets_payment_with_fee::validateArray($payments,'isInt')) { Ets_paymentmethod_class::updatePosition($payments); } die(json_encode( array( 'page' => $page, 'success' => $this->l('Updated successfully') ) )); } public function renderViewOrder(&$tpl_view_vars) { $id_order = (int) Tools::getValue('id_order'); if (!$id_order && isset($tpl_view_vars['order'])) { $id_order = (int) $tpl_view_vars['order']->id; } if ($id_order && ($method_order = Ets_paymentmethod_class::getPaymentMethodByIdOrder($id_order))) { $order = new Order($id_order); $useTaxExclColumn = Validate::isLoadedObject($order) && (int) $order->getTaxCalculationMethod() === (int) PS_TAX_EXC; $fee_payment = $useTaxExclColumn ? (float) $method_order['fee'] : (float) $method_order['fee_incl']; } $tpl_view_vars['fee_payment'] = isset($fee_payment) && $fee_payment ? $fee_payment : false; $tpl_view_vars['custom_payment'] = isset($fee_payment) && $fee_payment ? $fee_payment : false; } public function initContentOrderConfirmation($id_cart, $order_presenter) { $order = new Order(Order::getIdByCartId((int)$id_cart)); $tax = Validate::isLoadedObject($order) && (int) $order->getTaxCalculationMethod() === (int) PS_TAX_INC; $presentedOrder = $order_presenter ? $order_presenter->present($order): (new PrestaShop\PrestaShop\Adapter\Presenter\Order\OrderPresenter())->present($order); if ($method_order = Ets_paymentmethod_class::getPaymentMethodByIdOrder($order->id)) { $price = $tax ? (float)$method_order['fee_incl'] : (float)$method_order['fee']; if ($price <= 0) return ''; $priceFormatter = new PrestaShop\PrestaShop\Adapter\Product\PriceFormatter(); $presentedOrder['subtotals']['fee_payment'] = array( 'type' => 'fee_payment', 'label' => $tax ? sprintf($this->l('%s (tax incl.)'),$this->payment_fee_text) : sprintf($this->l('%s (tax excl.)'),$this->payment_fee_text), 'amount' => $price, 'value' => $price ? $priceFormatter->format($price, Currency::getCurrencyInstance((int)$order->id_currency)) : $this->l('Free'), ); } $this->context->smarty->assign( array( 'order' => $presentedOrder, ) ); } public function initContentOrderDetail(&$order_to_display) { $id_order = (int)Tools::getValue('id_order'); $order = new Order($id_order); $tax = Validate::isLoadedObject($order) && (int) $order->getTaxCalculationMethod() === (int) PS_TAX_INC; if ($method_order = Ets_paymentmethod_class::getPaymentMethodByIdOrder($order->id)) { $price = $tax ? (float)$method_order['fee_incl'] : (float)$method_order['fee']; if ($price > 0) { $priceFormatter = new PrestaShop\PrestaShop\Adapter\Product\PriceFormatter(); $order_to_display['subtotals']['fee_payment'] = array( 'type' => 'fee_payment', 'label' => $tax ? sprintf($this->l('%s (tax incl.)'),$this->payment_fee_text) : sprintf($this->l('%s (tax excl.)'),$this->payment_fee_text), 'amount' => $price, 'value' => $price ? $priceFormatter->format($price, Currency::getCurrencyInstance((int)$order->id_currency)) : $this->l('Free'), ); } } } public function initContentHTMLTemplateInvoice($id_order, $smarty) { $order = new Order($id_order); $tax = Validate::isLoadedObject($order) && (int) $order->getTaxCalculationMethod() === (int) PS_TAX_INC; if ($method_order = Ets_paymentmethod_class::getPaymentMethodByIdOrder($order->id)) { $fee_payment = $tax ? $method_order['fee_incl'] : $method_order['fee']; if ($fee_payment) { $this->payment_fee_text = Configuration::get('ETS_PMF_TEXT_PAYMENT_FEE',$this->context->language->id) ? : $this->l('Payment fee'); $smarty->assign( array( 'fee_payment' => $fee_payment, 'custom_payment' => true, 'display_tax' => $tax, 'text_payment_fee_incl' => sprintf($this->l('%s (tax incl.)'),$this->payment_fee_text), 'text_payment_fee_excl' => sprintf($this->l('%s (tax excl.)'),$this->payment_fee_text), 'Total_Products_text' => $this->l('Total Products'), 'Total_Discounts_text' => $this->l('Total Discounts'), 'Shipping_Costs_text' => $this->l('Shipping Costs'), 'Free_Shipping_text' => $this->l('Free Shipping'), 'Free_text' => $this->l('Free'), 'Wrapping_Costs_text' => $this->l('Wrapping Costs'), 'Total_tax_excl_text' => $this->l('Total (Tax excl.)'), 'Total_tax_text' => $this->l('Total Tax'), 'Total_text' => $this->l('Total'), ) ); $smarty->assign( array( 'total_tab' => $smarty->fetch(_PS_MODULE_DIR_ . 'ets_payment_with_fee/views/templates/hook/invoice.total-tab.tpl'), ) ); } } } public function hookActionOrderStatusPostUpdate($params) { if (isset($params['id_order']) && $params['id_order']) { $order = new Order($params['id_order']); $id_order_payment = Ets_paymentmethod_class::getInvoicePaymentByIdOrder($order->id); if ($id_order_payment && $order->module == 'ets_payment_with_fee' && $order->total_paid != 0) { $order_payment = new OrderPayment($id_order_payment); $order_payment->payment_method = $order->payment; $order_payment->update(); } } } public function copy_directory($src, $dst,$sup_folder = true) { $dir = opendir($src); @mkdir($dst); while (false !== ($file = readdir($dir))) { if (($file != '.') && ($file != '..')) { if (is_dir($src . '/' . $file)) { { if($sup_folder) $this->copy_directory($src . '/' . $file, $dst . '/' . $file); } } else { if (file_exists($dst . '/' . $file) && $file != 'index.php' && ($content = Tools::file_get_contents($dst . '/' . $file)) && Tools::strpos($content, 'overried_custom_payment by chung_ets') === false && Tools::strpos($content, 'overried by chung_ets') === false) copy($dst . '/' . $file, $dst . '/backup_' . $file); if (!file_exists($dst . '/' . $file) || (($content = Tools::file_get_contents($dst . '/' . $file)) && Tools::strpos($content, 'overried by chung_ets') === false)) copy($src . '/' . $file, $dst . '/' . $file); } } } closedir($dir); } public function delete_directory($directory) { $dir = opendir($directory); while (false !== ($file = readdir($dir))) { if (($file != '.') && ($file != '..')) { if (is_dir($directory . '/' . $file)) { $this->delete_directory($directory . '/' . $file); } else { if (file_exists($directory . '/' . $file) && $file != 'index.php' && ($content = Tools::file_get_contents($directory . '/' . $file)) && Tools::strpos($content, 'overried_custom_payment by chung_ets') !== false) { @unlink($directory . '/' . $file); if (file_exists($directory . '/backup_' . $file)) copy($directory . '/backup_' . $file, $directory . '/' . $file); } } } } closedir($dir); } public function hookActionEmailSendBefore($params) { if (isset($this->context->cart->id)) { $id_order = Order::getIdByCartId($this->context->cart->id); if ($id_order && Validate::isLoadedObject($order = new Order($id_order)) && ($params['template'] == 'order_conf' || $params['template'] == 'new_order') ) { $paymentMethod = Ets_paymentmethod_class::getPaymentMethodByIdOrder($order->id); if ($paymentMethod && $paymentMethod['fee'] > 0) { $tax = $this->checkDisplayTax($order->id_customer); $template = array( '{fee_payment}' => $paymentMethod['fee'] ? self::displayPrice($tax ? $paymentMethod['fee_incl'] : $paymentMethod['fee'], new Currency($order->id_currency)) : $this->l('Free'), '{fee_payment_text}' => $tax ? sprintf($this->l('%s (tax incl.)'),$this->payment_fee_text) : sprintf($this->l('%s (tax excl.)'),$this->payment_fee_text), ); $params['templateVars'] = array_merge($params['templateVars'], $template); $params['templatePath'] = dirname(__FILE__) . '/mails/'; } } } } public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null , string $order_reference = null) { if ($id_ets_paymentmethod = (int)Tools::getValue('id_ets_paymentmethod_admin')) { $payment_method = new Ets_paymentmethod_class($id_ets_paymentmethod, $this->context->language->id); return parent::validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method->method_name, $message, $extra_vars, $currency_special, $dont_touch_amount, $secure_key, $shop,$order_reference); } else return parent::validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method, $message, $extra_vars, $currency_special, $dont_touch_amount, $secure_key, $shop,$order_reference); } public function hookActionValidateOrder($params) { if (Tools::isSubmit('payment_fee_order') && Tools::isSubmit('id_ets_paymentmethod_admin')) { if ($payment_fee = (float)Tools::getValue('payment_fee_order')) { $id_ets_paymentmethod = (int)Tools::getValue('id_ets_paymentmethod_admin'); $order = $params['order']; $tax = ($order->total_paid_tax_incl - $order->total_paid_tax_excl) / $order->total_paid_tax_excl; $payment_fee_incl = Tools::ps_round($payment_fee + $payment_fee * $tax, 2); Ets_paymentmethod_class::addPaymentOrder($id_ets_paymentmethod,$order->id,$payment_fee,$payment_fee_incl,$order->payment); $order->total_paid_tax_incl = $order->total_paid_tax_incl + $payment_fee_incl; $order->total_paid_tax_excl = $order->total_paid_tax_excl + $payment_fee; $order->total_paid = $order->total_paid_tax_incl; $order->update(); } } else { $paymentCart = new Ets_payment_cart_class($params['cart']->id); if ($paymentCart->ets_payment_module_name) { $order = $params['order']; $cart = $params['cart']; if (($id_payment_method = (int)Tools::getValue('id_payment_method')) && $order->module == $this->name) { $total_fee_payment_incl = $this->getFeePayment($id_payment_method, null, true); $total_fee_payment_excl = $this->getFeePayment($id_payment_method, null, false); $total_order_fee_payment_incl = $this->getFeePayment($id_payment_method, $order->product_list, true); $total_order_fee_payment_excl = $this->getFeePayment($id_payment_method, $order->product_list, false); } else { $total_order_fee_payment_incl = $cart->getOrderTotal(true, Cart::BOTH, $order->product_list, null,false, false, true); $total_order_fee_payment_excl = $cart->getOrderTotal(false, Cart::BOTH, $order->product_list, null,false, false, true); $total_fee_payment_incl = $cart->getOrderTotal(true, Cart::BOTH, null, null, false,false, true); $total_fee_payment_excl = $cart->getOrderTotal(false, Cart::BOTH, null, null, false,false, true); } if (!Ets_paymentmethod_class::getPaymentMethodByIdOrder($order->id)) { Ets_paymentmethod_class::addPaymentOrder($id_payment_method,$order->id,$total_fee_payment_excl,$total_fee_payment_incl,$order->payment); $total_paid_tax_incl = $order->total_paid_tax_incl - $total_order_fee_payment_incl + $total_fee_payment_incl; $total_paid_tax_excl = $order->total_paid_tax_excl - $total_order_fee_payment_excl + $total_fee_payment_excl; } else { $total_paid_tax_incl = $order->total_paid_tax_incl - $total_order_fee_payment_incl; $total_paid_tax_excl = $order->total_paid_tax_excl - $total_order_fee_payment_excl; } if ($order->total_paid_tax_incl != $total_paid_tax_incl || $order->total_paid_tax_excl != $total_paid_tax_excl) { $order->total_paid_tax_incl = $total_paid_tax_incl; $order->total_paid = $total_fee_payment_incl; $order->total_paid_tax_excl = $total_paid_tax_excl; Ets_paymentmethod_class::updateFeePaymentOrder($order->id,$total_paid_tax_excl,$total_paid_tax_incl); } if ($paymentCart->ets_payment_module_name != $order->module) { $order_state = new OrderState((int)Configuration::get('PS_OS_ERROR')); if (Validate::isLoadedObject($order_state)) { $current_order_state = $order->getCurrentOrderState(); if (!$current_order_state || $current_order_state->id != $order_state->id) { //Create new OrderHistory $history = new OrderHistory(); $history->id_order = $order->id; $history->id_employee = 0; $use_existings_payment = false; if (!$order->hasInvoice()) { $use_existings_payment = true; } $history->changeIdOrderState((int)$order_state->id, $order, $use_existings_payment); $carrier = new Carrier($order->id_carrier, $order->id_lang); $templateVars = array(); if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $order->shipping_number) { $templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url)); } if ($history->addWithemail(true, $templateVars)) { if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && version_compare(_PS_VERSION_, '9.0.0', '<')) { foreach ($order->getProducts() as $product) { /* @phpstan-ignore-next-line */ if (StockAvailable::dependsOnStock($product['product_id'])) { call_user_func([StockAvailable::class, 'synchronize'], $product['product_id'], (int)$product['id_shop']); } } } } } } } } } } public function getFeePayOrderTotal($products = null, $withTaxes = true) { if(isset($this->context->cart->id)) { $paymentCart = new Ets_payment_cart_class($this->context->cart->id); $module_name = isset($paymentCart->ets_payment_module_name) ? $paymentCart->ets_payment_module_name : false; $id_payment_method = isset($paymentCart->id_payment_method) ? $paymentCart->id_payment_method : 0; if ($module_name == $this->name && $id_payment_method) { return $this->getFeePayment($id_payment_method, $products, $withTaxes); } if ($module_name) { return $this->getFeePaymentModule($module_name, $products, $withTaxes); } } return 0; } public function assignGeneralPurposeVariables($presented_cart) { $id_customer = ($this->context->customer->id) ? (int)($this->context->customer->id) : 0; $tax = $this->checkDisplayTax($id_customer); /* @phpstan-ignore-next-line */ $price = (float)$this->context->cart->getOrderTotal($tax, Cart::BOTH, null, null, false, false, true); if ($price > 0) { $cartArray = (array)$presented_cart; $priceFormatter = new PrestaShop\PrestaShop\Adapter\Product\PriceFormatter(); $cartArray['subtotals']['fee_payment'] = array( 'type' => 'fee_payment', 'label' => $tax ? sprintf($this->l('%s (tax incl.)'), $this->payment_fee_text) : sprintf($this->l('%s (tax excl.)'), $this->payment_fee_text), 'amount' => $price, 'value' => $price ? $priceFormatter->format($price, $this->context->currency) : $this->l('Free'), ); } } protected function isPayPalFeePolicyModuleName($moduleName) { if (!is_string($moduleName) || $moduleName === '') { return false; } $name = Tools::strtolower($moduleName); return $name =='paypal'; } protected function isModulePaymentFeeConfigured(array $module) { $type = isset($module['fee_type']) ? $module['fee_type'] : null; if ($type === null || $type === '') { return false; } return Tools::strtolower((string) $type) !== 'free'; } protected function getPayPalFeePolicyNoticeHtml() { $this->context->smarty->assign(array( 'paypal_fee_policy_url' => 'https://www.paypal.com/us/legalhub/paypal/useragreement-full#accepting-payment', 'paypal_fee_policy_message' => $this->l('We do not recommend adding an extra payment fee for PayPal. PayPal policies prohibit charging customers additional fees for using PayPal.'), 'paypal_fee_policy_read_more' => $this->l('Learn more in PayPal User Agreement'), )); return $this->fetch('module:ets_payment_with_fee/views/templates/admin/paypal_fee_policy_notice.tpl'); } public function getModuleWithFilter($filter = false) { $sort = Tools::getValue('sort', 'm.id_module'); if(!Validate::isCleanHtml($sort)) $sort = 'm.id_module'; $sort_type = Tools::getValue('sort_type','asc'); if(!in_array($sort_type,array('asc','desc'))) $sort_type = 'asc'; $hook_payment = $this->is17 ? 'paymentOptions' : 'payment'; $filter .=' AND m.id_module !="' . (int)$this->id . '" AND h.name = "' . pSQL($hook_payment) . '"'; return Ets_paymentmethod_class::getModulesByFilter($filter,$sort,$sort_type); } public function genSecure($size) { $chars = md5((string)time()); $code = ''; for ($i = 1; $i <= $size; ++$i) { $char = Tools::substr($chars, rand(0, Tools::strlen($chars) - 1), 1); if ($char == 'e') $char = 'a'; $code .= $char; } return $code; } public function displayOrderStatus($id_state) { $this->context->smarty->assign( array( 'order_state' => new OrderState($id_state, $this->context->language->id), ) ); return $this->display(__FILE__, 'order_state.tpl'); } public function renderPaymentOptions(&$paymentOptions) { if ($paymentOptions) { foreach ($paymentOptions as $key => &$paymentOption) { if ($paymentOption) { foreach ($paymentOption as &$payment) { if (!$payment['module_name']) $payment['module_name'] = $key; } } } } return $paymentOptions; } public function getProductsPaypal(&$products) { $fc = Tools::getValue('fc'); $module = Tools::getValue('module'); $controller = Tools::getValue('controller'); $backs = debug_backtrace(~1); if ($fc == 'module' && (($module == 'paypal' && isset($backs[2]) && $backs[2]['function'] =='getProductItems') || $module=='ps_checkout') && $products && !$this->add_product_to_paypal && Validate::isControllerName($controller) && !in_array($controller,array('ecValidation','mbValidation','pppValidation'))) { if($module != 'paypal') $this->add_product_to_paypal = true; $idCart = (int)$this->context->cart->id; if ($idCart) { $ets_cart_module = new Ets_payment_cart_class($idCart); $ets_cart_module->id_cart = $idCart; $ets_cart_module->ets_payment_module_name = 'paypal'; $ets_cart_module->id_payment_method = 0; $ets_cart_module->save(); } /* @phpstan-ignore-next-line */ $fee_payment = (float)$this->context->cart->getOrderTotal(false, Cart::BOTH, null, null, false,false, true); /* @phpstan-ignore-next-line */ $fee_payment_wt = (float)$this->context->cart->getOrderTotal(true, Cart::BOTH, null, null, false,false, true); if ($fee_payment > 0) { $product = $products[0]; $product['price'] = $fee_payment; $product['reference'] = ''; $product['id_product'] = $this->context->cart->id; $product['price_wt'] = $fee_payment_wt; $product['quantity'] = 1; $product['name'] = Configuration::get('ETS_PMF_TEXT_PAYMENT_FEE',$this->context->language->id); $product['specific_prices'] = array(); $product['total'] = $fee_payment; $product['total_wt'] = $fee_payment_wt; $product['cart_quantity'] = 1; $product['attributes'] = ''; $product['attributes_small'] = ''; $product['features'] = array(); $product['ets_product'] = true; $products[] = $product; } } if ($fc == 'module' && $module == 'klarnaofficial' && $products && !$this->add_product_to_klarna && Validate::isControllerName($controller)) { $this->add_product_to_klarna = true; /* @phpstan-ignore-next-line */ $fee_payment = (float)$this->context->cart->getOrderTotal(false, Cart::BOTH, null, null, false,false, true); /* @phpstan-ignore-next-line */ $fee_payment_wt = (float)$this->context->cart->getOrderTotal(true, Cart::BOTH, null, null, false,false, true); if ($fee_payment > 0) { $product = $products[0]; $product['price'] = $fee_payment; $product['price_wt'] = $fee_payment_wt; $product['quantity'] = 1; $product['name'] = Configuration::get('ETS_PMF_TEXT_PAYMENT_FEE',$this->context->language->id); $product['specific_prices'] = array(); $product['total'] = $fee_payment; $product['total_wt'] = $fee_payment_wt; $product['cart_quantity'] = 1; $product['attributes'] = ''; $product['attributes_small'] = ''; $product['features'] = array(); $product['ets_product'] = true; $products[] = $product; } } return $products; } public function getTextLang($text, $lang,$file_name='') { if(is_array($lang)) $iso_code = $lang['iso_code']; elseif(is_object($lang)) $iso_code = $lang->iso_code; else { $language = new Language($lang); $iso_code = $language->iso_code; } $modulePath = rtrim(_PS_MODULE_DIR_, '/').'/'.$this->name; $fileTransDir = $modulePath.'/translations/'.$iso_code.'.'.'php'; if(!@file_exists($fileTransDir)){ return $text; } $fileContent = Tools::file_get_contents($fileTransDir); $text_tras = preg_replace("/\\\*'/", "\'", $text); $strMd5 = md5($text_tras); $keyMd5 = '<{' . $this->name . '}prestashop>' . ($file_name ? : $this->name) . '_' . $strMd5; preg_match('/(\$_MODULE\[\'' . preg_quote($keyMd5, null) . '\'\]\s*=\s*\')(.*)(\';)/', $fileContent, $matches); if($matches && isset($matches[2])){ return $matches[2]; } return $text; } public static function validateArray($array,$validate='isCleanHtml') { if(!is_array($array)) return false; if(method_exists('Validate',$validate)) { if($array) { $ok= true; foreach($array as $val) { if(!is_array($val)) { if($val && !Validate::$validate($val)) { $ok= false; break; } } else $ok = self::validateArray($val,$validate); } return $ok; } } return true; } public function renderFormConfig() { if(Tools::isSubmit('btnSubmit')) { $errors =array(); $id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT'); $languages = Language::getLanguages(false); $ETS_PMF_TEXT_PAYMENT_FEE_default = Tools::getValue('ETS_PMF_TEXT_PAYMENT_FEE_'.$id_lang_default); if(!$ETS_PMF_TEXT_PAYMENT_FEE_default) $errors[] = $this->l('"Payment fee" text is required'); $ETS_PMF_TEXT_PAYMENT_FEEs = array(); foreach($languages as $language) { $ETS_PMF_TEXT_PAYMENT_FEEs[$language['id_lang']] = Tools::getValue('ETS_PMF_TEXT_PAYMENT_FEE_'.$language['id_lang']); if($ETS_PMF_TEXT_PAYMENT_FEEs[$language['id_lang']] && !Validate::isCleanHtml($ETS_PMF_TEXT_PAYMENT_FEEs[$language['id_lang']])) $errors[] = sprintf($this->l('"Payment fee" text is not valid in language %s'),$language['iso_code']); if(!$ETS_PMF_TEXT_PAYMENT_FEEs[$language['id_lang']]) $ETS_PMF_TEXT_PAYMENT_FEEs[$language['id_lang']] = $ETS_PMF_TEXT_PAYMENT_FEE_default; } if($errors) $this->_html .= $this->displayError($errors); else { Configuration::updateValue('ETS_PMF_TEXT_PAYMENT_FEE',$ETS_PMF_TEXT_PAYMENT_FEEs); $this->_html .= $this->displayConfirmation($this->l('Updated successfully')); } } $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Global configuration'), 'icon' => '' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('"Payment fee" text'), 'name' => 'ETS_PMF_TEXT_PAYMENT_FEE', 'required' => true, 'lang' => true, ), ), 'submit' => array( 'title' => $this->l('Save'), ) ), ); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? : 0; $this->fields_form = array(); $helper->id = (int)$this->id; $helper->identifier = $this->identifier; $helper->submit_action = 'btnSubmit'; $controller = Tools::getValue('controller'); $helper->currentIndex = $this->context->link->getAdminLink($controller, false).'&configure=' .$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name.'&list=true'; $helper->token = Tools::getAdminTokenLite($controller); $helper->tpl_vars = array( 'fields_value' => $this->getConfigFieldsValues(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id ); return $this->_html .=$helper->generateForm(array($fields_form)); } public function getConfigFieldsValues() { $fields = array(); $languages = Language::getLanguages(false); foreach($languages as $language) { $fields['ETS_PMF_TEXT_PAYMENT_FEE'][$language['id_lang']] = Tools::getValue('ETS_PMF_TEXT_PAYMENT_FEE_'.$language['id_lang'],Configuration::get('ETS_PMF_TEXT_PAYMENT_FEE',$language['id_lang'])); } return $fields; } public function hookDisplayPaymentFeeOrder($params) { if(isset($params['orderId']) && ($id_order = (int)$params['orderId']) && Validate::isLoadedObject($order = new Order($id_order))) { if ($method_order = Ets_paymentmethod_class::getPaymentMethodByIdOrder($order->id)) { $fee_payment = $method_order['fee_incl']; if($fee_payment) { $this->context->smarty->assign( array( 'fee_payment' => self::displayPrice($fee_payment,new Currency($order->id_cu