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; $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 (true) {