$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 = 'saveModulePaymentFee'; $helper->currentIndex = $this->context->link->getAdminLink('AdminPaymentFee', false); $helper->token = Tools::getAdminTokenLite('AdminPaymentFee'); $language = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->tpl_vars = array( 'base_url' => $this->context->shop->getBaseURL(), 'language' => array( 'id_lang' => $language->id, 'iso_code' => $language->iso_code ), 'fields_value' => $this->getFieldModulePaymentFee($module), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, 'cancel_url' => $this->context->link->getAdminLink('AdminPaymentFee', true), 'currencies' => Currency::getCurrencies(), 'defaultFormCurrency' => (int)Configuration::get('PS_CURRENCY_DEFAULT'), 'add_new' => true, 'image_baseurl' => _PS_ETS_PAYMENT_FEE_IMG_, ); return $helper->generateForm(array($fields_form)); } } $fields_list = array( 'id_module' => array( 'title' => $this->l('ID'), 'width' => 40, 'type' => 'text', 'filter' => true, 'sort' => 'm.id_module', ), 'logo' => array( 'title' => $this->l('Logo'), 'width' => 57, 'type' => 'text', 'image_field' => true, ), 'name' => array( 'title' => $this->l('Payment method'), 'type' => 'text', ), 'fee' => array( 'title' => $this->l('Fee'), 'width' => 140, 'type' => 'text', ), 'fee_tax' => array( 'title' => $this->l('Fee tax'), 'width' => 140, 'type' => 'text', ), ); $filter = ''; $show_reset = false; if (Tools::isSubmit('ets_payment_submit_module')) { if (($id_module = Tools::getValue('id_module')) || $id_module!='') { if(Validate::isInt($id_module)) $filter .= ' AND m.id_module = "' . (int)$id_module . '"'; $show_reset = true; } if (($name= Tools::getValue('name')) || $name!='') { if(Validate::isCleanHtml($name)) $filter .= ' AND m.name like "' . pSQL($name) . '%"'; $show_reset = true; } } $modules = $this->getModuleWithFilter($filter); if ($modules) { foreach ($modules as $key => &$module) { $moduleSystemName = $module['name']; /*if ($this->isPayPalFeePolicyModuleName($moduleSystemName)) { if (!$this->isModulePaymentFeeConfigured($module)) { unset($modules[$key]); continue; } }*/ $module['logo'] = array( 'image_field' => true, 'img_url' => $this->_path . '../' . $moduleSystemName . '/logo.png', 'width' => 57 ); if ($module['fee_type'] == 'fixed_fee') $module['fee'] = $module['fee_amount'] == 0 ? $this->l('Free') : self::displayPrice($module['fee_amount']) . ($module['free_for_order_over'] ? ' (Free for order over: ' . self::displayPrice($module['free_for_order_over'] * $this->context->currency->conversion_rate) . ')' : ''); elseif ($module['fee_type'] == 'percentage' || $module['fee_type']=='percentage_fixed') { $html_extra = ''; if ($module['min_fee']) $html_extra .= 'Minimum fee: ' . self::displayPrice((float)$module['min_fee'] * $this->context->currency->conversion_rate) . ', '; if ($module['max_fee']) $html_extra .= 'Maximum fee: ' . self::displayPrice((float)$module['max_fee'] * $this->context->currency->conversion_rate) . ', '; if ($module['free_for_order_over']) $html_extra .= 'Free for order over: ' . self::displayPrice((float)$module['free_for_order_over'] * $this->context->currency->conversion_rate); $module['fee'] = $module['percentage'] . '%' .($module['fee_type']=='percentage_fixed' && $module['fee_amount'] ? ' + '.self::displayPrice($module['fee_amount']):'' ). ($module['max_fee'] || $module['min_fee'] || $module['free_for_order_over'] ? ' (' . trim($html_extra, ', ') . ')' : ''); } else $module['fee'] = $this->l('Free'); $module['fee_tax'] = $module['fee_type'] == 'free' || !$module['fee_type'] ? '--' : ($module['fee_tax'] ?: $this->l('No tax')); $module_class = Module::getInstanceByName($moduleSystemName); if ($module_class) { $module['name'] = $module_class->displayName; } else unset($modules[$key]); } unset($module); if ($modules) { $modules = array_values($modules); } } $sort = Tools::getValue('sort', 'id_module'); if(!in_array($sort,array('id_module','name'))) $sort = 'id_module'; $sort_type = Tools::getValue('sort_type', 'asc'); if(!in_array($sort_type,array('asc','desc'))) $sort_type ='desc'; $listData = array( 'name' => 'module', 'actions' => array('edit'), 'currentIndex' => $this->context->link->getAdminLink('AdminPaymentFee', true), 'identifier' => 'id_module', 'show_action' => true, 'title' => $this->l('Payment fees'), 'fields_list' => $fields_list, 'field_values' => $modules, 'show_toolbar' => false, 'sort' => $sort, 'sort_type' => $sort_type, 'filter_params' => $this->getFilterParams($fields_list), 'show_reset' => $show_reset, 'show_add_new' => false, ); return $this->displayInformation($this->l('Please review the policies of your payment providers to ensure that adding or modifying payment fees is allowed before configuring any fees or surcharges.')) . $this->renderList($listData) . $this->renderFormConfig(); } public function getcarriers() { $carriers = Carrier::getCarriers($this->context->language->id,true,false,false,null,Carrier::ALL_CARRIERS); if ($carriers) foreach ($carriers as &$carrier) { if ($carrier['name'] == '0') $carrier['name'] = $this->l('Demo shop'); } return $carriers; } public function getFiledPaymentMethod() { if ($id_ets_paymentmethod = (int)Tools::getValue('id_ets_paymentmethod')) $paymentmethod = new Ets_paymentmethod_class($id_ets_paymentmethod); else $paymentmethod = new Ets_paymentmethod_class(); $languages = Language::getLanguages(false); $fields = array(); foreach ($languages as $language) { $fields['method_name'][$language['id_lang']] = Tools::getValue('method_name_' . $language['id_lang'], isset($paymentmethod->method_name[$language['id_lang']]) ? $paymentmethod->method_name[$language['id_lang']] :''); $fields['description'][$language['id_lang']] = Tools::getValue('description_' . $language['id_lang'], isset($paymentmethod->description[$language['id_lang']]) ? $paymentmethod->description[$language['id_lang']] :''); $fields['confirmation_message'][$language['id_lang']] = Tools::getValue('confirmation_message_' . $language['id_lang'], isset($paymentmethod->confirmation_message[$language['id_lang']]) ? $paymentmethod->confirmation_message[$language['id_lang']] :''); $fields['return_message'][$language['id_lang']] = Tools::getValue('return_message_' . $language['id_lang'], isset($paymentmethod->return_message[$language['id_lang']]) ? $paymentmethod->return_message[$language['id_lang']] :''); } $fields['customer_group[]'] = !$paymentmethod->id ? array('0') : (Tools::getValue('customer_group', $paymentmethod->customer_group ? explode(',', $paymentmethod->customer_group) : false) ? Tools::getValue('customer_group', $paymentmethod->customer_group ? explode(',', $paymentmethod->customer_group) : false) : array()); $fields['countries[]'] = !$paymentmethod->id ? array('0') : (Tools::getValue('countries', $paymentmethod->countries ? explode(',', $paymentmethod->countries) : false) ? Tools::getValue('countries', $paymentmethod->countries ? explode(',', $paymentmethod->countries) : false) : array()); $fields['carriers[]'] = !$paymentmethod->id ? array('0') : (Tools::getValue('carriers', $paymentmethod->carriers ? explode(',', $paymentmethod->carriers) : false) ? Tools::getValue('carriers', $paymentmethod->carriers ? explode(',', $paymentmethod->carriers) : false) : array()); $fields['fee_type'] = Tools::getValue('fee_type', $paymentmethod->fee_type); $fields['order_status'] = Tools::getValue('order_status', $paymentmethod->order_status); $fields['active'] = !$paymentmethod->id ? 1 : Tools::getValue('active', $paymentmethod->active); $fields['fee_amount'] = Tools::getValue('fee_amount', $paymentmethod->fee_amount != '' ? $paymentmethod->fee_amount * $this->context->currency->conversion_rate : ''); $fields['minimum_order'] = Tools::getValue('minimum_order', $paymentmethod->minimum_order != '' ? $paymentmethod->minimum_order * $this->context->currency->conversion_rate : ''); $fields['maximum_order'] = Tools::getValue('maximum_order', $paymentmethod->maximum_order != '' ? $paymentmethod->maximum_order * $this->context->currency->conversion_rate : ''); $fields['percentage'] = Tools::getValue('percentage', $paymentmethod->percentage); $fields['max_fee'] = Tools::getValue('max_fee', $paymentmethod->max_fee != '' ? $paymentmethod->max_fee * $this->context->currency->conversion_rate : ''); $fields['min_fee'] = Tools::getValue('min_fee', $paymentmethod->min_fee != '' ? $paymentmethod->min_fee * $this->context->currency->conversion_rate : ''); $fields['free_for_order_over'] = Tools::getValue('free_for_order_over', $paymentmethod->free_for_order_over != '' ? $paymentmethod->free_for_order_over * $this->context->currency->conversion_rate : ''); if ($id_ets_paymentmethod = (int)Tools::getValue('id_ets_paymentmethod')) $fields['id_ets_paymentmethod'] = $id_ets_paymentmethod; $fields['fee_based_on'] = $paymentmethod->id ? (int)$paymentmethod->fee_based_on : 1; $fields['id_tax_rules_group'] = $paymentmethod->id_tax_rules_group; return $fields; } public function getFieldModulePaymentFee($module) { $fields = array(); $fields['fee_type'] = Tools::getValue('fee_type', $module['fee_type']); $fields['fee_amount'] = Tools::getValue('fee_amount', $module['fee_amount'] != '' ? $module['fee_amount'] * $this->context->currency->conversion_rate : ''); $fields['percentage'] = Tools::getValue('percentage', $module['percentage']); $fields['max_fee'] = Tools::getValue('max_fee', $module['max_fee'] != '' ? $module['max_fee'] * $this->context->currency->conversion_rate : ''); $fields['min_fee'] = Tools::getValue('min_fee', $module['min_fee'] != '' ? $module['min_fee'] * $this->context->currency->conversion_rate : ''); $fields['free_for_order_over'] = Tools::getValue('free_for_order_over', $module['free_for_order_over'] != '' ? $module['free_for_order_over'] * $this->context->currency->conversion_rate : ''); $fields['id_module'] = $module['id_module']; $fields['minimum_order'] = Tools::getValue('minimum_order', $module['minimum_order']); $fields['maximum_order'] = Tools::getValue('maximum_order', $module['maximum_order']); $fields['id_tax_rules_group'] = Tools::getValue('id_tax_rules_group', $module['id_tax_rules_group']); $fields['fee_based_on'] = Tools::getValue('fee_based_on', (int)$module['fee_based_on']); return $fields; } public function UploadImage($key, &$errors = array()) { if(!is_dir(_PS_ETS_PAYMENT_FEE_IMG_DIR_)) mkdir(_PS_ETS_PAYMENT_FEE_IMG_DIR_,0755); if (isset($_FILES[$key]['tmp_name']) && isset($_FILES[$key]['name']) && $_FILES[$key]['name']) { if (!Validate::isFileName($_FILES[$key]['name'])) $errors[] = $this->l('File name is not valid'); $type = Tools::strtolower(Tools::substr(strrchr($_FILES[$key]['name'], '.'), 1)); $imageName = str_replace(' ', '-', $_FILES[$key]['name']); $fileName = _PS_ETS_PAYMENT_FEE_IMG_DIR_. $imageName; if (file_exists($fileName)) { $imageName = $this->genSecure(5) . '-' . $imageName; $fileName = _PS_ETS_PAYMENT_FEE_IMG_DIR_ . $imageName; } $imagesize = @getimagesize($_FILES[$key]['tmp_name']); if (!$errors && isset($_FILES[$key]) && !empty($_FILES[$key]['tmp_name']) && !empty($imagesize) && in_array($type, array('jpg', 'gif', 'jpeg', 'png')) ) { $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); if ($error = ImageManager::validateUpload($_FILES[$key], Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024)) $errors[] = $error; elseif (!$temp_name || !move_uploaded_file($_FILES[$key]['tmp_name'], $temp_name)) $errors[] = $this->l('Can not upload the file'); elseif (!ImageManager::resize($temp_name, $fileName, null, null, $type)) $errors[] = $this->displayError($this->l('An error occurred during the image upload process.')); if (file_exists($temp_name)) @unlink($temp_name); if (!$errors) { return $imageName; } } elseif (!in_array($type, array('jpg', 'gif', 'jpeg', 'png'))) $errors[] = $this->l('Logo is not valid'); } return ''; } public function getPaymentsWithFilter() { $filter = ''; if (Tools::isSubmit('ets_payment_submit_payment')) { if ((($id_ets_paymentmethod = Tools::getValue('id_ets_paymentmethod')) || $id_ets_paymentmethod!='') && Validate::isInt($id_ets_paymentmethod)) $filter .= ' AND p.id_ets_paymentmethod="' . (int)$id_ets_paymentmethod . '"'; if ((($method_name = trim(Tools::getValue('method_name'))) || $method_name!= '') && Validate::isCleanHtml($method_name)) $filter .= ' AND pl.method_name like "%' . pSQL($method_name) . '%"'; if ((($active= Tools::getValue('active')) || $active != '') && Validate::isInt($active)) $filter .= ' AND p.active ="' . (int)$active . '"'; if ((($order_status = Tools::getValue('order_status')) || $order_status != '') && Validate::isInt($order_status)) $filter .= ' AND p.order_status="' . (int)$order_status . '"'; } $sort = Tools::getValue('sort', 'position'); if(!Validate::isCleanHtml($sort) || !in_array($sort,array('position','id_ets_paymentmethod','method_name','active','order_status'))) $sort= 'position'; $sort_type = Tools::getValue('sort_type', 'asc'); if(!in_array($sort_type,array('desc','asc'))) $sort_type = 'asc'; return Ets_paymentmethod_class::getPayments($filter,$sort,$sort_type); } public function getUrlExtra($field_list) { $params = ''; $sort = trim(Tools::getValue('sort')); $sort_type = Tools::getValue('sort_type','desc'); if(!in_array($sort_type,array('desc','asc'))) $sort_type='desc'; if ($sort && isset($field_list[$sort])) { $params .= '&sort=' . $sort . '&sort_type=' . $sort_type; } if ($field_list) { foreach ($field_list as $key => $val) { $value = Tools::getValue($key); if ($value != '' && Validate::isCleanHtml($value)) { $params .= '&' . $key . '=' . urlencode($value); } } unset($val); } return $params; } public function renderList($listData) { if (isset($listData['fields_list']) && $listData['fields_list']) { foreach ($listData['fields_list'] as $key => &$val) { $value = Tools::getValue($key); $val['active'] = Validate::isCleanHtml($value) ? trim($value):''; } } $this->context->smarty->assign($listData); return $this->display(__FILE__, 'list_helper.tpl'); } public function getFilterParams($field_list) { $params = ''; if ($field_list) { foreach ($field_list as $key => $val) { $value = Tools::getValue($key); if ($value != '' && Validate::isCleanHtml($value)) { $params .= '&' . $key . '=' . urlencode($value); } } unset($val); } return $params; } public static function displayPaymentMethodCustom() { $context = Ets_payment_with_fee::getInstanceContext(); $context->smarty->assign( array( 'paymentmethods' => Ets_paymentmethod_class::getPayments(' AND p.active=1','position','ASC'), ) ); return $context->smarty->fetch(_PS_MODULE_DIR_ . 'ets_payment_with_fee/views/templates/hook/admin_payments.tpl'); } public function hookPaymentOptions($params) { if (!$this->active) { return; } $type_checkout_options = Tools::getValue('type_checkout_options','create'); $id_customer = ($this->context->customer->id) ? (int)($this->context->customer->id) : 0; if ($id_customer) { $id_group = Customer::getDefaultGroupId((int)$id_customer); } elseif($type_checkout_options=='guest' || $type_checkout_options=='create') { if($type_checkout_options=='guest') { $id_group = (int)Configuration::get('PS_GUEST_GROUP'); } elseif($type_checkout_options=='create') { $id_group = (int)Configuration::get('PS_CUSTOMER_GROUP'); } } if (!isset($id_group)) { $id_group = (int)Group::getCurrent()->id; } $tax = $this->checkDisplayTax($id_customer); $this->context->smarty->assign('tax_incl', $tax); $id_carrier = (int)$this->context->cart->id_carrier; $id_address_delivery = (int)$this->context->cart->id_address_delivery; $address_type = Tools::getValue('address_type'); if($address_type=='shipping_address') $id_address_delivery = (int)Tools::getValue('id_address',$id_address_delivery); /* @phpstan-ignore-next-line */ $totalorder = $this->context->cart->getOrderTotal(true,Cart::BOTH,null,null,false,false,false,true); $this->context->smarty->assign('totalOrder', self::displayPrice($totalorder)); if ($paymentmethods = Ets_paymentmethod_class::getPayments(' AND p.active=1','position','ASC')) { $priceFormatter = new PrestaShop\PrestaShop\Adapter\Product\PriceFormatter(); foreach ($paymentmethods as $key => &$paymentmethod) { if ($this->checkPaymentMethod($paymentmethod, $id_group, $id_carrier, $id_address_delivery, $totalorder)) { if ($paymentmethod['fee_type'] == 'free' || ($totalorder > $paymentmethod['free_for_order_over'] && $paymentmethod['free_for_order_over'] != 0)) { $payment_fee = 0; } else { if ($paymentmethod['fee_type'] == 'fixed_fee') { $payment_fee = $paymentmethod['fee_amount']; $payment_fee = $payment_fee * $this->context->currency->conversion_rate; } else { if ($paymentmethod['fee_based_on'] == 1) $total = $totalorder; else { /* @phpstan-ignore-next-line */ $total = $this->context->cart->getOrderTotal(false,Cart::BOTH,null,null,false,false,false,true); } $payment_fee = $paymentmethod['percentage'] * $total / 100; if ($payment_fee > $paymentmethod['max_fee'] && $paymentmethod['max_fee']) { $payment_fee = $paymentmethod['max_fee']; } else if ($payment_fee < $paymentmethod['min_fee'] && $paymentmethod['min_fee']) { $payment_fee = $paymentmethod['min_fee']; } if($paymentmethod['fee_type']=='percentage_fixed') { $payment_fee += $paymentmethod['fee_amount']; } $payment_fee = $payment_fee * $this->context->currency->conversion_rate; } if ($tax && $paymentmethod['id_tax_rules_group']) $payment_fee = $this->getPriceIncl($payment_fee, $paymentmethod['id_tax_rules_group']); } $paymentmethod['fee_price'] = $payment_fee ? $priceFormatter->format($payment_fee) : $this->l('Free'); $paymentmethod['fee'] = $payment_fee; $paymentmethod['description'] = str_replace('[fee]', $paymentmethod['fee_price'], $paymentmethod['description']); } else unset($paymentmethods[$key]); } } if (!$paymentmethods) return; unset($paymentmethod); $payment_options = array(); $module = Tools::getValue('module'); foreach ($paymentmethods as $paymentmethod) { $this->context->smarty->assign( array( 'paymentMethod' => $paymentmethod, 'link_module' => $this->_path, ) ); $newOption = new PaymentOption(); $newOption->setModuleName($module =='ets_onepagecheckout' ? $this->name.'_'.$paymentmethod['id_ets_paymentmethod']: $this->name) ->setCallToActionText($paymentmethod['method_name']) ->setAction($this->context->link->getModuleLink($this->name, 'validation', array('id_payment_method' => $paymentmethod['id_ets_paymentmethod']), true)) ->setAdditionalInformation($this->fetch('module:ets_payment_with_fee/views/templates/hook/ets_custom_payment_intro.tpl')) ->setInputs(array(array('type' => 'hidden', 'name' => 'id_payment_method', 'value' => $paymentmethod['id_ets_paymentmethod']))); $payment_options[] = $newOption; } return $payment_options; } public function hookPaymentReturn($params) { if (!$this->active) { return; } $id_order = (int)Tools::getValue('id_order'); if (Validate::isLoadedObject($order = new Order($id_order)) && ($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->return_message; $currency = new Currency($order->id_currency); $search = array( '[payment_method]' => $order_method['method_name'], '[fee]' => $fee, '[email]' =>$this->context->customer->email, '[shop_name]' => Configuration::get('PS_SHOP_NAME'), '[order_reference]' => $order->reference, '[amount]' => self::displayPrice($order->total_paid, Validate::isLoadedObject($currency) ? $currency:null), ); $message = str_replace(array_keys($search), $search, $message); return $message; } } public function checkPaymentMethod($paymentmethod, $id_group, $id_carrier, $id_address_delivery, $totalorder) { if (!is_array($paymentmethod)) $paymentmethod = Ets_paymentmethod_class::getPaymentMethodByIdMethod($paymentmethod); if (!$paymentmethod) return false; $groups = explode(',', $paymentmethod['customer_group']); $countries = explode(',', $paymentmethod['countries']); $carriers = explode(',', $paymentmethod['carriers']); $address = new Address($id_address_delivery); $id_country = Tools::getValue('id_country',$address->id_country); if(!$id_country) $id_country = (int)$this->context->country->id; $carrier = new Carrier($id_carrier); $id_reference = $carrier->id_reference; if (($groups[0] && !in_array($id_group, $groups)) || ($countries[0] && !in_array($id_country, $countries)) || ($carriers[0] && !in_array($id_reference, $carriers)) || ($paymentmethod['minimum_order'] != '' && $paymentmethod['minimum_order'] > $totalorder) || ($paymentmethod['maximum_order'] != '' && $paymentmethod['maximum_order'] < $totalorder)) return false; else return true; } public function getPriceIncl($price, $id_tax_group) { if ($id_tax_group) { $context = $this->context; if (is_object($context->cart) && $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} != null) { $id_address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; $address = new Address($id_address); } else { $address = new Address(); } $address = Address::initialize($address->id, true); $tax_manager = TaxManagerFactory::getManager($address, $id_tax_group); $product_tax_calculator = $tax_manager->getTaxCalculator(); $priceTax = $product_tax_calculator->addTaxes($price); return $priceTax; } return $price; } public function getFeePayment($id_payment_method, $products, $withTax = true) { if ($payment_method = Ets_paymentmethod_class::getPaymentMethodByIdMethod($id_payment_method)) { /* @phpstan-ignore-next-line */ $totalorder = $this->context->cart->getOrderTotal(true, Cart::BOTH, $products, null, null, false,false, true); if ($payment_method['fee_type'] == 'free' || ($totalorder > $payment_method['free_for_order_over'] && $payment_method['free_for_order_over'] != 0)) $payment_method['fee'] = 0; else { if ($payment_method['fee_type'] == 'fixed_fee') { $payment_method['fee'] = $payment_method['fee_amount']; $payment_method['fee'] = $payment_method['fee'] * $this->context->currency->conversion_rate; } else { if ($payment_method['fee_based_on'] == 1) $total = $totalorder; else { /* @phpstan-ignore-next-line */ $total = $this->context->cart->getOrderTotal(false, Cart::BOTH, $products, null, null,false, false, true); } $payment_method['fee'] = $payment_method['percentage'] * $total / 100; $payment_method['fee'] = (float)$payment_method['fee'] / $this->context->currency->conversion_rate; if($payment_method['fee_type']=='percentage_fixed') { $payment_method['fee'] += $payment_method['fee_amount']; } if ($payment_method['fee'] > $payment_method['max_fee'] && (float)$payment_method['max_fee']) $payment_method['fee'] = $payment_method['max_fee']; else if ($payment_method['fee'] < $payment_method['min_fee'] && (float)$payment_method['min_fee']) $payment_method['fee'] = $payment_method['min_fee']; $payment_method['fee'] = $payment_method['fee'] * $this->context->currency->conversion_rate; } if ($withTax && $payment_method['id_tax_rules_group']) { $payment_method['fee'] = $this->getPriceIncl($payment_method['fee'], $payment_method['id_tax_rules_group']); } } return $payment_method['fee']; } return 0; } public function getFeePaymentModule($module_name, $products, $withTax) { $module = Module::getInstanceByName($module_name); if($module && Validate::isLoadedObject($module)) { /* @phpstan-ignore-next-line */ $totalorder = $this->context->cart->getOrderTotal(true, Cart::BOTH, $products, null, null,false, false, true); $payment_method = Ets_paymentmethod_class::getPaymentMethodByIdModule($module->id); if ($payment_method) { if ($payment_method['fee_type'] == 'free' || ($totalorder > $payment_method['free_for_order_over'] && $payment_method['free_for_order_over'] != 0) || (($minOrder = $payment_method['minimum_order']) && (float)$minOrder > (float)$totalorder) || (($maxOrder = $payment_method['maximum_order']) && (float)$maxOrder < (float)$totalorder)) $payment_method['fee'] = 0; else { if ($payment_method['fee_type'] == 'fixed_fee') { $payment_method['fee'] = $payment_method['fee_amount']; $payment_method['fee'] = $payment_method['fee'] * $this->context->currency->conversion_rate; } else { if ($payment_method['fee_based_on'] == 1) $total = $totalorder; else { /* @phpstan-ignore-next-line */ $total = $this->context->cart->getOrderTotal(false, Cart::BOTH, $products, null, null,false, false, true); } $payment_method['fee'] = $payment_method['percentage'] * $total / 100; $payment_method['fee'] = (float)$payment_method['fee'] / $this->context->currency->conversion_rate; if($payment_method['fee_type']=='percentage_fixed') { $payment_method['fee'] += $payment_method['fee_amount']; } if ($payment_method['fee'] > $payment_method['max_fee'] && (float)$payment_method['max_fee']) $payment_method['fee'] = $payment_method['max_fee']; else if ($payment_method['fee'] < $payment_method['min_fee'] && (float)$payment_method['min_fee']) $payment_method['fee'] = $payment_method['min_fee']; $payment_method['fee'] = $payment_method['fee'] * $this->context->currency->conversion_rate; } if ($withTax) {