diff --git a/src/lemonway/lemonway.php b/src/lemonway/lemonway.php
index d664e0b..7733b95 100644
--- a/src/lemonway/lemonway.php
+++ b/src/lemonway/lemonway.php
@@ -66,7 +66,7 @@ class Lemonway extends PaymentModule
protected $local_path = null;
/** @var bool */
- public static $is_active = 1;
+ public static $is_active = 1;
public static $statuesLabel = array(
1 => "Document uniquement reçu",
@@ -87,7 +87,7 @@ public function __construct()
{
$this->name = 'lemonway';
$this->tab = 'payments_gateways';
- $this->version = '1.3.0';
+ $this->version = '1.3.1';
$this->author = 'SIRATECK';
$this->need_instance = 0;
@@ -240,10 +240,7 @@ public function install()
Configuration::updateValue('LEMONWAY_API_LOGIN', '');
Configuration::updateValue('LEMONWAY_API_PASSWORD', '');
Configuration::updateValue('LEMONWAY_MERCHANT_ID', '');
- Configuration::updateValue('LEMONWAY_DIRECTKIT_URL', '');
- Configuration::updateValue('LEMONWAY_WEBKIT_URL', '');
- Configuration::updateValue('LEMONWAY_DIRECTKIT_URL_TEST', '');
- Configuration::updateValue('LEMONWAY_WEBKIT_URL_TEST', '');
+ Configuration::updateValue('CUSTOM_ENVIRONMENT_NAME', '');
Configuration::updateValue('LEMONWAY_IS_TEST_MODE', false);
//METHOD CONFIGURATION
@@ -259,12 +256,9 @@ public function install()
Configuration::updateValue('LEMONWAY_' . strtoupper($method['code']) . '_TITLE', $method['title']);
}
-
//CREDIT CARD X TIMES (split)
Configuration::updateValue('LEMONWAY_CC_XTIMES_SPLITPAYMENTS',null);
-
-
//Prepare status values
$key = self::LEMONWAY_PENDING_OS;
@@ -286,7 +280,7 @@ public function install()
);
$adminLemonwayId = Db::getInstance()->getValue(
- "SELECT `id_tab` FROM " . _DB_PREFIX_ . "tab WHERE `class_name`='AdminLemonway'"
+ "SELECT `id_tab` FROM " . _DB_PREFIX_ . "tab WHERE `class_name` = 'AdminLemonway'"
);
include(dirname(__FILE__) . '/sql/install.php');
@@ -307,10 +301,7 @@ public function uninstall()
Configuration::deleteByName('LEMONWAY_API_LOGIN');
Configuration::deleteByName('LEMONWAY_API_PASSWORD');
Configuration::deleteByName('LEMONWAY_MERCHANT_ID');
- Configuration::deleteByName('LEMONWAY_DIRECTKIT_URL');
- Configuration::deleteByName('LEMONWAY_WEBKIT_URL');
- Configuration::deleteByName('LEMONWAY_DIRECTKIT_URL_TEST');
- Configuration::deleteByName('LEMONWAY_WEBKIT_URL_TEST');
+ Configuration::deleteByName('CUSTOM_ENVIRONMENT_NAME');
Configuration::deleteByName('LEMONWAY_IS_TEST_MODE');
Configuration::deleteByName('LEMONWAY_CSS_URL');
@@ -318,7 +309,7 @@ public function uninstall()
Configuration::deleteByName('LEMONWAY_ONECLIC_ENABLED'); //Keeped for old module versions
//COMMON CREDIT CARD Configuration
- foreach (self::$subMethods as $method){
+ foreach (self::$subMethods as $method) {
Configuration::deleteByName('LEMONWAY_' . strtoupper($method['code']) . '_ONECLIC_ENABLED');
Configuration::deleteByName('LEMONWAY_' . strtoupper($method['code']) . '_ENABLED');
Configuration::deleteByName('LEMONWAY_' . strtoupper($method['code']) . '_TITLE');
@@ -349,20 +340,19 @@ public function uninstall()
protected function getConfigFormValues($formCode)
{
$formCode = strtoupper($formCode);
- switch ($formCode){
+
+ switch ($formCode) {
case 'API':
return array(
'LEMONWAY_API_LOGIN' => Configuration::get('LEMONWAY_API_LOGIN', null),
'LEMONWAY_API_PASSWORD' => Configuration::get('LEMONWAY_API_PASSWORD', null),
'LEMONWAY_MERCHANT_ID' => Configuration::get('LEMONWAY_MERCHANT_ID', null),
- 'LEMONWAY_DIRECTKIT_URL' => Configuration::get('LEMONWAY_DIRECTKIT_URL', null),
- 'LEMONWAY_WEBKIT_URL' => Configuration::get('LEMONWAY_WEBKIT_URL', null),
- 'LEMONWAY_DIRECTKIT_URL_TEST' => Configuration::get('LEMONWAY_DIRECTKIT_URL_TEST', null),
- 'LEMONWAY_WEBKIT_URL_TEST' => Configuration::get('LEMONWAY_WEBKIT_URL_TEST', null),
+ 'CUSTOM_ENVIRONMENT_NAME' => Configuration::get('CUSTOM_ENVIRONMENT_NAME', null),
'LEMONWAY_IS_TEST_MODE' => Configuration::get('LEMONWAY_IS_TEST_MODE', null),
'LEMONWAY_CSS_URL' => Configuration::get('LEMONWAY_CSS_URL', null)
);
break;
+
case 'CC_XTIMES':
//Manage checkboxes splitpayment profiles
$splitpaymentIds = explode(',',Configuration::get('LEMONWAY_' . $formCode . '_SPLITPAYMENTS',''));
@@ -429,14 +419,12 @@ protected function postProcess($formCode)
foreach ($this->getSplitpaymentProfiles() as $profile){
$value = Tools::getValue($key . '_' . $profile['id_profile']);
//die('value: '. $value);
- if($value == 'on' && !in_array($profile['id_profile'],$values)){//Add new profile
+ if ($value == 'on' && !in_array($profile['id_profile'],$values)) { //Add new profile
$values[] = $profile['id_profile'];
- }
- else if ($value != 'on' && in_array($profile['id_profile'],$values)){ //remove profile
+ } else if ($value != 'on' && in_array($profile['id_profile'],$values)) { //remove profile
$index = array_search($profile['id_profile'], $values);
unset($values[$index]);
}
-
}
$value = implode(',', $values);
@@ -478,12 +466,11 @@ public function getContent()
}
}
-
-
+ $this->context->smarty->assign('module_version', $this->version);
$this->context->smarty->assign('module_dir', $this->_path);
$this->context->smarty->assign('api_configuration_form', $this->renderForm('API'));
- $methodForms =array();
+ $methodForms = array();
foreach (self::$subMethods as $methodCode=>$method){
$configurationKey = $methodCode;
$methodForms[$methodCode] = array('form'=> $this->renderForm($configurationKey),'title'=>$this->l($method['title']));
@@ -524,7 +511,7 @@ protected function renderForm($type)
$form = '';
- switch ($type){
+ switch ($type) {
case 'API':
$form = $helper->generateForm(
$this->getApiConfigForm()
@@ -588,7 +575,7 @@ protected function renderForm($type)
}
- protected function getBaseMethodCcConfigForm($methodCode){
+ protected function getBaseMethodCcConfigForm($methodCode) {
$methodCode = strtoupper($methodCode);
$container = $this->getBaseMethodConfigForm($methodCode);
@@ -640,10 +627,7 @@ protected function getBaseMethodCcConfigForm($methodCode){
);
}
-
-
$container['form']['input'][] = $switch;
-
return $container;
}
@@ -669,8 +653,6 @@ protected function getBaseMethodConfigForm($methodCode)
),
);
-
-
$switchEnabled = array(
'type' => 'switch',
'label' => $this->l('Enabled'),
@@ -842,37 +824,13 @@ protected function getApiConfigForm()
'desc' => $this->l('Customise the stylesheet of the payment page (Notice: If your website is in https, the CSS URL has to be in https too)'),
),
array(
- 'col' => 6,
- 'type' => 'text',
- 'prefix' => '',
- 'desc' => $this->l('Leave empty, if this information has not been sent to you by Lemonway'),
- 'name' => 'LEMONWAY_DIRECTKIT_URL',
- 'label' => $this->l('DIRECTKIT XML URL'),
- ),
- array(
- 'col' => 6,
- 'type' => 'text',
- 'prefix' => '',
- 'desc' => $this->l('Leave empty, if this information has not been sent to you by Lemonway'),
- 'name' => 'LEMONWAY_WEBKIT_URL',
- 'label' => $this->l('WEBKIT URL'),
- ),
- array(
- 'col' => 6,
- 'type' => 'text',
- 'prefix' => '',
- 'desc' => $this->l('Leave empty, if this information has not been sent to you by Lemonway'),
- 'name' => 'LEMONWAY_DIRECTKIT_URL_TEST',
- 'label' => $this->l('DIRECTKIT XML URL TEST'),
- ),
- array(
- 'col' => 6,
+ 'col' => 3,
'type' => 'text',
- 'prefix' => '',
- 'desc' => $this->l('Leave empty, if this information has not been sent to you by Lemonway'),
- 'name' => 'LEMONWAY_WEBKIT_URL_TEST',
- 'label' => $this->l('WEBKIT URL TEST'),
- ),
+ 'prefix' => '',
+ 'desc' => $this->l('If you have a specific environment with Lemon Way'),
+ 'name' => 'CUSTOM_ENVIRONMENT_NAME',
+ 'label' => $this->l('Custom environment name'),
+ )
),
'submit' => array(
'title' => $this->l('Save'),
@@ -902,21 +860,16 @@ public static function methodInstanceFactory($methodCode){
return new $methodClassName();
}
-
-
/**
* Add the CSS & JavaScript files you want to be loaded in the BO.
*/
public function hookBackOfficeHeader()
{
if (Tools::getValue('module_name') == $this->name) {
-
-
if ($this->isVersion17() && method_exists($this->context->controller, 'setMedia')) {
$this->context->controller->setMedia(true);
}
$this->context->controller->addJS($this->_path . 'views/js/back.js');
-
}
$this->context->controller->addCSS($this->_path . 'views/css/back.css');
@@ -938,16 +891,15 @@ public function hookHeader()
public function hookPayment($params)
{
$methodsEnabled = array();
- foreach (self::$subMethods as $method){
-
+
+ foreach (self::$subMethods as $method) {
//Create method instance
$methodInstance = $this->methodFactory($method['code']);
//Check if method is enbaled
- if($methodInstance->isValid()){
+ if ($methodInstance->isValid()) {
$methodsEnabled[$method['code']] = $methodInstance;
}
-
}
$this->smarty->assign(array(
@@ -967,15 +919,13 @@ public function hookPaymentOptions($params)
$options = array();
- foreach (self::$subMethods as $method){
-
+ foreach (self::$subMethods as $method) {
//Create method instance
$methodInstance = $this->methodFactory($method['code']);
//Check if method is enbaled
- if($methodInstance->isValid()){
+ if ($methodInstance->isValid()) {
-
$this->context->smarty->assign(array(
'module_dir' => $this->_path,
'method'=>$methodInstance,
@@ -997,14 +947,10 @@ public function hookPaymentOptions($params)
->setModuleName($this->name)
->setForm($this->context->smarty->fetch($methodInstance->getTemplate()));
-
$options[] = $newOption;
-
}
-
}
-
return $options;
}
@@ -1035,7 +981,8 @@ public function hookPaymentReturn($params)
return $this->getHookPaymentReturnOutput();
}
- public function getHookPaymentReturnOutput(){
+ public function getHookPaymentReturnOutput()
+ {
if($this->isVersion17())
return $this->fetch('module:' . $this->name . '/views/templates/hook/confirmation.tpl');
@@ -1046,8 +993,8 @@ public function getHookPaymentReturnOutput(){
* This hook is used to add color to splitpayment deadlines results.
* @param array $params
*/
- public function hookActionAdminSplitpaymentDeadlineListingResultsModifier($params){
-
+ public function hookActionAdminSplitpaymentDeadlineListingResultsModifier($params)
+ {
$list = &$params['list'];
foreach ($list as $index=>$tr){
@@ -1063,7 +1010,6 @@ public function hookActionAdminSplitpaymentDeadlineListingResultsModifier($param
break;
}
}
-
}
public function getCustomerCard($id_customer)
@@ -1244,7 +1190,8 @@ public function ajaxPlaceOrder()
return $cardForm;
}
- public function isVersion17(){
+ public function isVersion17()
+ {
return (bool)version_compare(_PS_VERSION_ ,'1.7','>=');
}
}
diff --git a/src/lemonway/services/LemonWayConfig.php b/src/lemonway/services/LemonWayConfig.php
index 0c86d23..2890971 100644
--- a/src/lemonway/services/LemonWayConfig.php
+++ b/src/lemonway/services/LemonWayConfig.php
@@ -23,57 +23,65 @@
* @copyright 2017 Lemon way
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
+
class LemonWayConfig
{
+ const LEMONWAY_DEFAULT_ENVIRONMENT = 'lwecommerce';
+
+ const LEMONWAY_DIRECTKIT_FORMAT_URL_PROD = 'https://ws.lemonway.fr/mb/%s/prod/directkitxml/service.asmx';
+ const LEMONWAY_DIRECTKIT_FORMAT_URL_TEST = 'https://sandbox-api.lemonway.fr/mb/%s/dev/directkitxml/service.asmx';
+ const LEMONWAY_WEBKIT_FORMAT_URL_PROD = 'https://webkit.lemonway.fr/mb/%s/prod';
+ const LEMONWAY_WEBKIT_FORMAT_URL_TEST = 'https://sandbox-webkit.lemonway.fr/%s/dev';
+
+ private function getEvironmentName()
+ {
+ $env_name = Configuration::get('CUSTOM_ENVIRONMENT_NAME', null);
+
+ //If no custom environment we use lwecommerce
+ if (empty($env_name)) {
+ $env_name = self::LEMONWAY_DEFAULT_ENVIRONMENT;
+ }
- const LEMONWAY_WEBKIT_4ECOMMERCE_URL_PROD = 'https://webkit.lemonway.fr/mb/lwecommerce/prod/';
- const LEMONWAY_WEBKIT_4ECOMMERCE_URL_TEST = 'https://sandbox-webkit.lemonway.fr/lwecommerce/dev/';
- const LEMONWAY_DIRECTKIT_4ECOMMERCE_URL_PROD = 'https://ws.lemonway.fr/mb/lwecommerce/prod/directkitxml/service.asmx';
- const LEMONWAY_DIRECTKIT_4ECOMMERCE_URL_TEST = 'https://sandbox-api.lemonway.fr/mb/lwecommerce/dev/directkitxml/service.asmx';
+ return $env_name;
+ }
public static function isTestMode()
{
return (bool) Configuration::get('LEMONWAY_IS_TEST_MODE', null);
}
- public static function getDirectkitUrl()
+ public static function is4EcommerceMode()
{
- $url = Configuration::get('LEMONWAY_DIRECTKIT_URL', null);
+ $env_name = Configuration::get('CUSTOM_ENVIRONMENT_NAME', null);
- if (LemonWayConfig::isTestMode()) {
- $url = Configuration::get('LEMONWAY_DIRECTKIT_URL_TEST', null);
- }
-
- //If not custom urls was entered we use 4ecommerce urls
- if (empty($url)) {
- $url = self::LEMONWAY_DIRECTKIT_4ECOMMERCE_URL_PROD;
+ // If no custom environment name so lwecommerce
+ return (empty($env_name));
+ }
- if (LemonWayConfig::isTestMode()) {
- $url = self::LEMONWAY_DIRECTKIT_4ECOMMERCE_URL_TEST;
- }
+ public static function getDirectkitUrl()
+ {
+ $env_name = LemonWayConfig::getEvironmentName();
+
+ if (LemonWayConfig::isTestMode()) {
+ $url = sprintf(self::LEMONWAY_DIRECTKIT_FORMAT_URL_TEST, $env_name);
+ } else {
+ $url = sprintf(self::LEMONWAY_DIRECTKIT_FORMAT_URL_PROD, $env_name);
}
- return rtrim($url, '/');
+ return $url;
}
public static function getWebkitUrl()
{
- $url = Configuration::get('LEMONWAY_WEBKIT_URL', null);
+ $env_name = LemonWayConfig::getEvironmentName();
if (LemonWayConfig::isTestMode()) {
- $url = Configuration::get('LEMONWAY_WEBKIT_URL_TEST', null);
+ $url = sprintf(self::LEMONWAY_WEBKIT_FORMAT_URL_TEST, $env_name);
+ } else {
+ $url = sprintf(self::LEMONWAY_WEBKIT_FORMAT_URL_PROD, $env_name);
}
- //If not custom urls was entered we use 4ecommerce urls
- if (empty($url)) {
- $url = self::LEMONWAY_WEBKIT_4ECOMMERCE_URL_PROD;
-
- if (LemonWayConfig::isTestMode()) {
- $url = self::LEMONWAY_WEBKIT_4ECOMMERCE_URL_TEST;
- }
- }
-
- return rtrim($url, '/');
+ return $url;
}
public static function getWalletMerchantId()
@@ -100,18 +108,4 @@ public static function getOneclicEnabled($method)
{
return Configuration::get('LEMONWAY_' . strtoupper($method) . '_ONECLIC_ENABLED', null);
}
-
- public static function is4EcommerceMode(){
- $directKitUrl = Configuration::get('LEMONWAY_DIRECTKIT_URL', null);
- if (LemonWayConfig::isTestMode()) {
- $directKitUrl = Configuration::get('LEMONWAY_DIRECTKIT_URL_TEST', null);
- }
-
- $webkitUrl = Configuration::get('LEMONWAY_WEBKIT_URL', null);
- if (LemonWayConfig::isTestMode()) {
- $webkitUrl = Configuration::get('LEMONWAY_WEBKIT_URL_TEST', null);
- }
-
- return !($directKitUrl && $webkitUrl);
- }
}