Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ composer.lock
tests/.env
/node_modules
var/cache/*
!var/cache/index.php
!var/cache/index.php
.DS_Store
14 changes: 9 additions & 5 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@

## [1.0.15] - 2022-05-31

- BO : "Invalid credentials" exception catcher added.
- BO : "Invalid credentials" exception catcher added.

## [1.0.16] - 2022-06-07

- BO : Changed mastercard config name from MASTERCARD to MasterCard.
- BO : Changed mastercard config name from MASTERCARD to MasterCard.

## [1.0.17] - 2022-06-14

Expand All @@ -82,7 +82,7 @@

- BO: Added new switch to control when new order mail is sent to merchant.
- BO : Fixed issue where on older PS version capture order would send wrong price.
-
-
## [1.0.19] - *

- FO: added ability to save and use saved cards with hosted fields payment
Expand Down Expand Up @@ -116,7 +116,7 @@

## [1.1.1] - *

- FO : Fixed ApplePay payment method was not displayed on Macintosh PC's.
- FO : Fixed ApplePay payment method was not displayed on Macintosh PC's.

## [1.1.2] - *

Expand Down Expand Up @@ -160,7 +160,7 @@

- ## [1.2.2] - *
- FO : Confirmation email after order authorization fix
- BO : Order confirmation email setting removed
- BO : Order confirmation email setting removed
- BO : Security improvements

- ## [1.2.3] - *
Expand Down Expand Up @@ -198,3 +198,7 @@
- Fixed issue when user is redirected to payment page in Back office when module is disabled
- Fixed issue when payment option is disabled but showing
- Fixed order confirmation email delivery

## [1.2.8]
- Added new setting to group debit/credit cards as 'Cards' in checkout
- Added new setting to send order confirmation mail on payment completion
Comment on lines +202 to +204

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The changelog for version 1.2.8 is missing the main bug fix introduced in this pull request. According to the PR title, a critical bug regarding email notifications for shipped orders was fixed. It's important to document this fix for users and future developers.

I suggest updating the changelog to include this information.

Suggested change
## [1.2.8]
- Added new setting to group debit/credit cards as 'Cards' in checkout
- Added new setting to send order confirmation mail on payment completion
## [1.2.8]
- Fixed an issue where email notifications for order status changes (e.g., 'shipped') were not being sent for Saferpay orders.
- Added new setting to group debit/credit cards as 'Cards' in checkout
- Added new setting to send order confirmation mail on payment completion

21 changes: 21 additions & 0 deletions controllers/admin/AdminSaferPayOfficialSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ private function displayEmailSettings()
'cast' => 'intval',
'type' => 'bool',
],
SaferPayConfig::SAFERPAY_SEND_ORDER_CONF_MAIL => [
'title' => $this->module->l('Send order confirmation mail on payment completion'),
'desc' => $this->module->l('Send an email from Saferpay on payment completion'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool',
],
SaferPayConfig::SAFERPAY_SEND_NEW_ORDER_MAIL . '_description' => [
'type' => 'desc',
'class' => 'col-lg-12',
Expand Down Expand Up @@ -323,6 +330,20 @@ private function displayPaymentBehaviorConfiguration()
'desc' => $this->module->l('Select the option to determine whether the order should be created'),
'form_group_class' => 'thumbs_chose',
],
SaferPayConfig::SAFERPAY_GROUP_CARDS => [
'type' => 'bool',
'title' => $this->module->l("Group debit/credit cards as 'Cards' in checkout", self::FILE_NAME),
'validation' => 'isBool',
'cast' => 'intval',
'desc' => $this->module->l("If enabled, all supported card brands (Visa, Mastercard, Amex, etc.) will be grouped and shown as a single 'Cards' payment method at checkout.", self::FILE_NAME),
],
SaferPayConfig::SAFERPAY_GROUP_CARDS_LOGO => [
'type' => 'bool',
'title' => $this->module->l("Show 'Cards' payment method logo", self::FILE_NAME),
'validation' => 'isBool',
'cast' => 'intval',
'desc' => $this->module->l("If enabled, a logo for the grouped 'Cards' payment method will be displayed at checkout.", self::FILE_NAME),
],
],
'buttons' => [
'save_and_connect' => [
Expand Down
30 changes: 25 additions & 5 deletions saferpayofficial.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,25 @@ public function hookPaymentOptions($params)
$logosEnabled = $paymentRepository->getAllActiveLogosNames();
$logosEnabled = array_column($logosEnabled, 'name');

if (Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_GROUP_CARDS_LOGO)) {
$logosEnabled[] = \Invertus\SaferPay\Config\SaferPayConfig::PAYMENT_CARDS;
}

$activePaymentMethods = $paymentRepository->getActivePaymentMethodsNames();
$activePaymentMethods = array_column($activePaymentMethods, 'name');

/** @var \Invertus\SaferPay\Provider\CurrencyProvider $currencyProvider */
$currencyProvider = $this->getService(\Invertus\SaferPay\Provider\CurrencyProvider::class);

$allCurrencies = $currencyProvider->getAllCurrenciesInArray();

/** @var \Invertus\SaferPay\Service\CardPaymentGroupingService $cardGroupingService */
$cardGroupingService = $this->getService(\Invertus\SaferPay\Service\CardPaymentGroupingService::class);

if (Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_GROUP_CARDS)) {
$paymentMethods = $cardGroupingService->group($paymentMethods, $allCurrencies);
}

foreach ($paymentMethods as $paymentMethod) {
$paymentMethod['paymentMethod'] = str_replace(' ', '', $paymentMethod['paymentMethod']);

Expand Down Expand Up @@ -600,13 +613,20 @@ public function hookActionEmailSendBefore($params)
return true;
}

if ($params['template'] === 'new_order') {
if ((int) Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_SEND_NEW_ORDER_MAIL)) {
return true;
}
// Define which email templates should be controlled for SaferPay orders
$controlledTemplates = [
'new_order' => \Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_SEND_NEW_ORDER_MAIL,
'order_conf' => \Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_SEND_ORDER_CONF_MAIL,
];

// Check if this template should be controlled
if (isset($controlledTemplates[$params['template']])) {
$configKey = $controlledTemplates[$params['template']];
return (bool) Configuration::get($configKey);
}

return false;
// Allow all other email templates (including order status changes like 'shipped')
return true;
}

public function hookActionAdminControllerSetMedia()
Expand Down
26 changes: 24 additions & 2 deletions src/Config/SaferPayConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class SaferPayConfig
const PAYMENT_LASTSCHRIFT = 'DIRECTDEBIT';
const PAYMENT_ACCOUNTTOACCOUNT = 'ACCOUNTTOACCOUNT';
const PAYMENT_PAYCONIQ = 'PAYCONIQ';
const PAYMENT_CARD = 'CARD';
const PAYMENT_CARDS = 'CARD';
const PAYMENT_POSTFINANCE_PAY = 'POSTFINANCEPAY';
const PAYMENT_WECHATPAY = 'WECHATPAY';
const PAYMENT_CLICKTOPAY = 'CLICKTOPAY';
Expand Down Expand Up @@ -148,7 +148,7 @@ class SaferPayConfig
'SOFORTUEBERWEISUNG' => self::PAYMENT_SOFORT,
'AccountToAccount' => self::PAYMENT_ACCOUNTTOACCOUNT,
'Payconiq' => self::PAYMENT_PAYCONIQ,
'Card' => self::PAYMENT_CARD,
'Card' => self::PAYMENT_CARDS,
'PostFinancePay' => self::PAYMENT_POSTFINANCE_PAY,
'WeChatPay' => self::PAYMENT_WECHATPAY,
'Blik' => self::PAYMENT_BLIK,
Expand Down Expand Up @@ -236,8 +236,10 @@ class SaferPayConfig
const SAFERPAY_PAYMENT_AUTHORIZATION_FAILED = 'SAFERPAY_PAYMENT_AUTHORIZATION_FAILED';

const SAFERPAY_SEND_NEW_ORDER_MAIL = 'SAFERPAY_SEND_NEW_ORDER_MAIL';
const SAFERPAY_SEND_ORDER_CONF_MAIL = 'SAFERPAY_SEND_ORDER_CONF_MAIL';
const SAFERPAY_ALLOW_SAFERPAY_SEND_CUSTOMER_MAIL = 'SAFERPAY_ALLOW_SAFERPAY_SEND_CUSTOMER_MAIL';
const SAFERPAY_ORDER_CREATION_AFTER_AUTHORIZATION = 'SAFERPAY_ORDER_CREATION_AFTER_AUTHORIZATION';
const SAFERPAY_GROUP_CARDS = 'SAFERPAY_GROUP_CARDS';

const STATUS_PS_OS_OUTOFSTOCK_PAID = 'PS_OS_OUTOFSTOCK_PAID';

Expand Down Expand Up @@ -291,6 +293,23 @@ class SaferPayConfig
self::SUPER_CHECKOUT_MODULE,
];

/**
* Card brands that can be grouped under 'Cards' method
*/
const CARD_BRANDS = [
self::PAYMENT_AMEX,
self::PAYMENT_MAESTRO,
self::PAYMENT_MASTERCARD,
self::PAYMENT_VISA,
self::PAYMENT_VPAY,
self::PAYMENT_JCB,
self::PAYMENT_DINERS,
self::PAYMENT_MYONE,
self::PAYMENT_BANCONTACT,
];

const SAFERPAY_GROUP_CARDS_LOGO = 'SAFERPAY_GROUP_CARDS_LOGO';

public static function supportsOrderCapture($paymentMethod)
{
//payments that DOES NOT SUPPORT capture
Expand Down Expand Up @@ -420,6 +439,7 @@ public static function getDefaultConfiguration()
self::SAFERPAY_ORDER_STATE_CHOICE_AWAITING_PAYMENT => (int) Configuration::get(
self::SAFERPAY_PAYMENT_AWAITING
),
self::SAFERPAY_GROUP_CARDS => 0,
];
}

Expand Down Expand Up @@ -453,6 +473,8 @@ public static function getUninstallConfiguration()
self::FIELDS_LIBRARY,
self::FIELDS_LIBRARY . self::TEST_SUFFIX,
self::SAFERPAY_ORDER_CREATION_AFTER_AUTHORIZATION,
self::SAFERPAY_GROUP_CARDS,
self::SAFERPAY_SEND_ORDER_CONF_MAIL,
];
}

Expand Down
72 changes: 72 additions & 0 deletions src/Service/CardPaymentGroupingService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
*NOTICE OF LICENSE
*
*This source file is subject to the Open Software License (OSL 3.0)
*that is bundled with this package in the file LICENSE.txt.
*It is also available through the world-wide-web at this URL:
*http://opensource.org/licenses/osl-3.0.php
*If you did not receive a copy of the license and are unable to
*obtain it through the world-wide-web, please send an email
*to license@prestashop.com so we can send you a copy immediately.
*
*DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
*versions in the future. If you wish to customize PrestaShop for your
*needs please refer to http://www.prestashop.com for more information.
*
*@author INVERTUS UAB www.invertus.eu <support@invertus.eu>
*@copyright SIX Payment Services
*@license SIX Payment Services
*/

namespace Invertus\SaferPay\Service;

use Invertus\SaferPay\Config\SaferPayConfig;
use SaferPayOfficial;

if (!defined('_PS_VERSION_')) {
exit;
}

class CardPaymentGroupingService
{
/** @var SaferPayOfficial */
private $module;

public function __construct(SaferPayOfficial $module)
{
$this->module = $module;
}

/**
* @param array $paymentMethods Raw payment methods from API
* @param array $allCurrencies List of all supported currencies (for CARD method)
*
* @return array Filtered/grouped payment methods
*/
public function group(array $paymentMethods, array $allCurrencies): array
{
$result = [];
$hasCardMethods = false;

foreach ($paymentMethods as $method) {
if (in_array($method['paymentMethod'], SaferPayConfig::CARD_BRANDS, true)) {
$hasCardMethods = true;
} else {
$result[] = $method;
}
}

if ($hasCardMethods) {
$result[] = [
'paymentMethod' => SaferPayConfig::PAYMENT_CARDS,
'logoUrl' => _PS_BASE_URL_SSL_ . $this->module->getPathUri() . 'views/img/' . SaferPayConfig::PAYMENT_CARDS . '.png',
'currencies' => $allCurrencies,
];
}

return $result;
}
}
2 changes: 1 addition & 1 deletion src/Service/LegacyTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private function getTranslations()
SaferPayConfig::PAYMENT_WLCRYPTOPAYMENTS => $this->module->l('Cryptocurrencies', self::FILE_NAME),
SaferPayConfig::PAYMENT_ACCOUNTTOACCOUNT => $this->module->l('AccountToAccount', self::FILE_NAME),
SaferPayConfig::PAYMENT_PAYCONIQ => $this->module->l('Payconiq', self::FILE_NAME),
SaferPayConfig::PAYMENT_CARD => $this->module->l('Card', self::FILE_NAME),
SaferPayConfig::PAYMENT_CARDS => $this->module->l('Cards', self::FILE_NAME),
SaferPayConfig::PAYMENT_POSTFINANCE_PAY => $this->module->l('PostFinancePay', self::FILE_NAME),
SaferPayConfig::PAYMENT_WECHATPAY => $this->module->l('WeChatPay', self::FILE_NAME),
SaferPayConfig::PAYMENT_BLIK => $this->module->l('Blik', self::FILE_NAME),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace Invertus\SaferPay\Service\PaymentRestrictionValidation;

use Invertus\SaferPay\Adapter\LegacyContext;
use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\SaferPay\Repository\SaferPayPaymentRepository;
use Invertus\SaferPay\Repository\SaferPayRestrictionRepository;
use Invertus\SaferPay\Service\SaferPayObtainPaymentMethods;
Expand Down Expand Up @@ -72,6 +73,10 @@ public function __construct(
*/
public function isValid($paymentName)
{
if ($paymentName === SaferPayConfig::PAYMENT_CARDS) {
return true;
}

if (!$this->isPaymentMethodEnabled($paymentName)) {
return false;
}
Expand Down
36 changes: 36 additions & 0 deletions upgrade/install-1.2.8.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
*NOTICE OF LICENSE
*
*This source file is subject to the Open Software License (OSL 3.0)
*that is bundled with this package in the file LICENSE.txt.
*It is also available through the world-wide-web at this URL:
*http://opensource.org/licenses/osl-3.0.php
*If you did not receive a copy of the license and are unable to
*obtain it through the world-wide-web, please send an email
*to license@prestashop.com so we can send you a copy immediately.
*
*DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
*versions in the future. If you wish to customize PrestaShop for your
*needs please refer to http://www.prestashop.com for more information.
*
*@author INVERTUS UAB www.invertus.eu <support@invertus.eu>
*@copyright SIX Payment Services
*@license SIX Payment Services
*/

use Invertus\SaferPay\Config\SaferPayConfig;

if (!defined('_PS_VERSION_')) {
exit;
}

function upgrade_module_1_2_8()
{
Configuration::updateValue(SaferPayConfig::SAFERPAY_GROUP_CARDS, 0);
Configuration::updateValue(SaferPayConfig::SAFERPAY_SEND_ORDER_CONF_MAIL, 0);

return true;
}
Comment on lines +30 to +36

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This function contains an unnecessary line with whitespace. For better code style and readability, it should be removed and a proper blank line can be added before the return statement.

function upgrade_module_1_2_8()
{
    Configuration::updateValue(SaferPayConfig::SAFERPAY_GROUP_CARDS, 0);
    Configuration::updateValue(SaferPayConfig::SAFERPAY_SEND_ORDER_CONF_MAIL, 0);

    return true;
}

Binary file added views/img/CARD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading