Skip to content

Commit

Permalink
Merge branch 'release/2.7.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennelandais committed Jul 10, 2019
2 parents 4ad9bc9 + c8c7b31 commit 44bbcc2
Show file tree
Hide file tree
Showing 69 changed files with 1,961 additions and 1,850 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Version 2.7.1

- Get payment method configuration from PHP SDK
- Add update notifications in admin dashboard

# Version 2.7.0

- Add MyBank Payment method
Expand Down
18 changes: 17 additions & 1 deletion bin/docker/images/prestashop/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ if [ ! -f /var/www/html/prestashopConsole.phar ];then
./prestashopConsole.phar configuration:set PS_SSL_ENABLED 1
fi

if [ "$ENVIRONMENT" = "$ENV_STAGE" ];then
mysql -h $MYSQL_HOST -D prestashop17 -u root -p$MYSQL_ROOT_PASSWORD <<EOF
UPDATE ps_module SET version='0.0.0' WHERE name='hipay_enterprise';
COMMIT;
EOF
fi

./prestashopConsole.phar c:flush


Expand All @@ -86,8 +93,17 @@ if [ ! -f /var/www/html/prestashopConsole.phar ];then
#service cron start
fi

if [ "$ENVIRONMENT" = "$ENV_DEVELOPMENT" ];then
MOD_DROITS=775
else
MOD_DROITS=755
fi


chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
chmod -R $MOD_DROITS /var/www/html



#===================================#
# START WEBSERVER
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Functionality tested
* - Notification box for new versions on main dashboard
* - Notification alert for new versions on configuration screens
*
*/
var utils = require('../../support/utils');
describe('Update notification box', function () {

/**
* Checks when module needs update on the main dashboard
*/
it('Needs update on main dashboard', function () {
cy.logToAdmin();
cy.get('#hipayupdate')
.should('exist')
.should('be.visible');
cy.get('#hipayupdate > .panel-heading')
.should('contain', 'HiPay Information');
cy.get('#hipayupdate #hipayNotifLogo')
.should('exist')
.should('be.visible');
cy.get('#hipayupdate p')
.should('exist')
.should('be.visible')
.should(($div) => {
const text = $div.text();
expect(text).to.match(/^(\s*)Une nouvelle version du module HiPay Enterprise est disponible\.(\s*)Voir les détails de la version 2\.7\.0(\s*)ou(\s*)mettre à jour\.(\s*)$/);
});
cy.adminLogOut();
});

/**
* Checks when module needs update on the config page
*/
it('Needs update on config page', function () {
cy.logToAdmin();
cy.goToHipayModuleAdmin();
cy.get('#hipayupdate')
.should('exist')
.should('be.visible')
.should('have.class', 'alert')
.should('have.class', 'alert-danger')
.should(($div) => {
const text = $div.text();
expect(text).to.match(/^(\s*)Une nouvelle version du module HiPay Enterprise est disponible\.(\s*)Voir les détails de la version 2\.7\.0(\s*)ou(\s*)mettre à jour\.(\s*)$/);
});
cy.adminLogOut();
});
});

2 changes: 1 addition & 1 deletion bin/tests/tests-cypress/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "hipay-enterprise-sdk-woocommerce",
"name": "hipay-enterprise-sdk-prestashop",
"version": "1.0.0",
"dependencies": {
"@hipay/hipay-cypress-utils": "^1.0.32",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function generate()
$PMRequest = null;

if (!empty($this->configHipay["payment"]["local_payment"][$this->params["method"]]["additionalFields"])) {
$PMRequest = new $this->configHipay["payment"]["local_payment"][$this->params["method"]]["additionalFields"]["sdkClass"]();
$sdkClass = $this->configHipay["payment"]["local_payment"][$this->params["method"]]["additionalFields"]["sdkClass"];
$PMRequest = new $sdkClass();

$this->mapRequest($PMRequest);
}
Expand Down
4 changes: 2 additions & 2 deletions src/hipay_enterprise/classes/apiHandler/ApiHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ private function baseParamsInit(&$params, $creditCard = true, $cart = false)
$params["delivery_informations"] = $this->getDeliveryInformation($cart);
} elseif ($this->configHipay["payment"]["global"]["activate_basket"] ||
(isset($params["method"]) &&
isset($this->configHipay["payment"]["local_payment"][$params["method"]]["forceBasket"])) &&
$this->configHipay["payment"]["local_payment"][$params["method"]]["forceBasket"]
isset($this->configHipay["payment"]["local_payment"][$params["method"]]["basketRequired"])) &&
$this->configHipay["payment"]["local_payment"][$params["method"]]["basketRequired"]
) {
$params["basket"] = $this->getCart($cart);
$params["delivery_informations"] = $this->getDeliveryInformation($cart);
Expand Down
57 changes: 51 additions & 6 deletions src/hipay_enterprise/classes/helper/HipayConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,19 +535,20 @@ private function setAllConfigHiPay($arrayHipay = null, $id_shop_group = null, $i
/**
* init local config
*
* @param $folderName
* @return array
*/
private function insertPaymentsConfig($folderName)
{
$creditCard = array();
$paymentMethod = array();

$files = scandir($this->jsonFilesPath . $folderName);

foreach ($files as $file) {
$creditCard = array_merge($creditCard, $this->addPaymentConfig($file, $folderName));
$paymentMethod = array_merge($paymentMethod, $this->addPaymentConfig($file, $folderName));
}

return $creditCard;
return $paymentMethod;
}

/**
Expand All @@ -559,13 +560,57 @@ private function insertPaymentsConfig($folderName)
*/
private function addPaymentConfig($file, $folderName)
{
$creditCard = array();
$paymentMethod = array();

if (preg_match('/(.*)\.json/', $file) == 1) {
$json = Tools::jsonDecode(Tools::file_get_contents($this->jsonFilesPath . $folderName . $file), true);
$creditCard[$json["name"]] = $json["config"];
$paymentMethod[$json["name"]] = $json["config"];

$sdkConfig = HiPay\Fullservice\Data\PaymentProduct\Collection::getItem($json["name"]);

if ($sdkConfig !== null) {
$paymentMethod[$json["name"]] = array_merge($sdkConfig->toArray(), $paymentMethod[$json["name"]]);
}

if (
isset($paymentMethod[$json["name"]]["currencies"]) &&
empty($paymentMethod[$json["name"]]["currencies"])
) {
$paymentMethod[$json["name"]]["currencies"] = $this->getActiveCurrencies();
}

if (
isset($paymentMethod[$json["name"]]["countries"]) &&
empty($paymentMethod[$json["name"]]["countries"])
) {
$paymentMethod[$json["name"]]["countries"] = $this->getActiveCountries();
}

}

return $paymentMethod;
}

private function getActiveCurrencies(){
$activeCurrenciesIso = array();
$activeCurrencies = Currency::getCurrencies(false, true);

foreach ($activeCurrencies as $currency) {
$activeCurrenciesIso[] = $currency["iso_code"];
}

return $activeCurrenciesIso;
}

private function getActiveCountries()
{
$activeCountriesIso = array();
$activeCountries = Country::getCountries($this->context->language->id, true);

foreach ($activeCountries as $country) {
$activeCountriesIso[] = $country["iso_code"];
}

return $creditCard;
return $activeCountriesIso;
}
}
33 changes: 23 additions & 10 deletions src/hipay_enterprise/classes/helper/HipayConfigFormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public function saveAccountInformations()
Tools::getValue("api_password_sandbox") &&
!Tools::getValue("api_username_sandbox"))
) {
$this->module->_errors[] = $this->module->l("If sandbox api username is filled sandbox api password is mandatory");
$this->module->_errors[] = $this->module->l(
"If sandbox api username is filled sandbox api password is mandatory"
);
return false;
} elseif (($key == "api_tokenjs_username_sandbox" &&
Tools::getValue("api_tokenjs_username_sandbox") &&
Expand All @@ -72,7 +74,9 @@ public function saveAccountInformations()
Tools::getValue("api_tokenjs_password_publickey_sandbox") &&
!Tools::getValue("api_tokenjs_username_sandbox"))
) {
$this->module->_errors[] = $this->module->l("If sandbox api TokenJS username is filled sandbox api TokenJS password is mandatory");
$this->module->_errors[] = $this->module->l(
"If sandbox api TokenJS username is filled sandbox api TokenJS password is mandatory"
);
return false;
} elseif (($key == "api_moto_username_sandbox" &&
Tools::getValue("api_moto_username_sandbox") &&
Expand All @@ -84,7 +88,9 @@ public function saveAccountInformations()
"api_moto_username_sandbox"
))
) {
$this->module->_errors[] = $this->module->l("If sandbox api MO/TO username is filled sandbox api MO/TO password is mandatory");
$this->module->_errors[] = $this->module->l(
"If sandbox api MO/TO username is filled sandbox api MO/TO password is mandatory"
);
return false;
} else {
if ($key == "api_secret_passphrase_sandbox" || $key == "api_moto_secret_passphrase_sandbox") {
Expand All @@ -106,7 +112,9 @@ public function saveAccountInformations()
Tools::getValue("api_password_production") &&
!Tools::getValue("api_username_production"))
) {
$this->module->_errors[] = $this->module->l("If production api username is filled production api password is mandatory");
$this->module->_errors[] = $this->module->l(
"If production api username is filled production api password is mandatory"
);
return false;
} elseif (($key == "api_tokenjs_username_production" &&
Tools::getValue("api_tokenjs_username_production") &&
Expand All @@ -115,7 +123,9 @@ public function saveAccountInformations()
Tools::getValue("api_tokenjs_password_publickey_production") &&
!Tools::getValue("api_tokenjs_username_production"))
) {
$this->module->_errors[] = $this->module->l("If production api TokenJS username is filled production api TokenJS password is mandatory");
$this->module->_errors[] = $this->module->l(
"If production api TokenJS username is filled production api TokenJS password is mandatory"
);
return false;
} elseif (($key == "api_moto_username_production" &&
Tools::getValue("api_moto_username_production") &&
Expand All @@ -125,7 +135,9 @@ public function saveAccountInformations()
Tools::getValue("api_moto_password_production") &&
!Tools::getValue("api_moto_username_production"))
) {
$this->module->_errors[] = $this->module->l("If production api MO/TO username is filled production api MO/TO password is mandatory");
$this->module->_errors[] = $this->module->l(
"If production api MO/TO username is filled production api MO/TO password is mandatory"
);
return false;
} else {
if ($key == "api_secret_passphrase_production" || $key == "api_moto_secret_passphrase_production") {
Expand Down Expand Up @@ -253,8 +265,8 @@ public function saveCreditCardInformations($context)
foreach ($conf as $key => $value) {
if (in_array($key, $keySaved)) {
$fieldValue = Tools::getValue($card . "_" . $key);
if ($key == "currencies") {
foreach (Tools::getValue($card . "_" . $key) as $currency) {
if ($key == "currencies" && $fieldValue) {
foreach ($fieldValue as $currency) {
if (!in_array($currency, $this->module->moduleCurrencies)) {
$this->module->db->setCurrencies($this->module->id, $context->shop->id, $currency);
}
Expand Down Expand Up @@ -309,13 +321,14 @@ public function saveLocalPaymentInformations($context)
);

foreach ($this->module->hipayConfigTool->getLocalPayment() as $card => $conf) {

$keySaved = array_merge($conf["displayConfigurationFields"], $keySavedBase);
foreach ($conf as $key => $value) {
//prevent specific fields from being updated
if (in_array($key, $keySaved)) {
$fieldValue = Tools::getValue($card . "_" . $key);
if ($key == "currencies") {
foreach (Tools::getValue($card . "_" . $key) as $currency) {
if ($key == "currencies" && $fieldValue) {
foreach ($fieldValue as $currency) {
if (!in_array($currency, $this->module->moduleCurrencies)) {
$this->module->db->setCurrencies($this->module->id, $context->shop->id, $currency);
}
Expand Down
24 changes: 24 additions & 0 deletions src/hipay_enterprise/classes/helper/HipayDBQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -963,4 +963,28 @@ public function isManualCapture($orderId)

return false;
}

/**
* Returns a module's version from database
* @param $moduleName The module's name
* @return mixed
* @throws PrestaShopDatabaseException
*/
public function getModuleVersion($moduleName){
$sql = 'SELECT version FROM `' .
_DB_PREFIX_ .
'module` WHERE name = \'' .
pSQL(
$moduleName
) .
'\' LIMIT 1;';

$result = Db::getInstance()->executeS($sql);

if(isset($result[0]) && is_array($result[0])) {
return $result[0]['version'];
} else {
return null;
}
}
}
2 changes: 1 addition & 1 deletion src/hipay_enterprise/classes/helper/HipayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public static function getActivatedPaymentByCountryAndCurrency(
if ($paymentMethodType == "local_payment") {
if (Configuration::get('PS_ROUND_TYPE') == Order::ROUND_LINE ||
Configuration::get('PS_ROUND_TYPE') == Order::ROUND_ITEM ||
!$settings["forceBasket"]
!$settings["basketRequired"]
) {
$activatedPayment[$name] = $settings;
$activatedPayment[$name]["link"] = $context->link->getModuleLink(
Expand Down
2 changes: 1 addition & 1 deletion src/hipay_enterprise/classes/helper/HipayNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private function saveCardToken()
$configCC = $this->module->hipayConfigTool->getPaymentCreditCard()[strtolower(
$this->transaction->getPaymentProduct()
)];
if (isset($configCC['recurring']) && $configCC['recurring']) {
if (isset($configCC['canRecurring']) && $configCC['canRecurring']) {

$card = array(
"token" => $this->transaction->getPaymentMethod()->getToken(),
Expand Down
Loading

0 comments on commit 44bbcc2

Please sign in to comment.