LOPT_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;