Skip to content

Commit

Permalink
Merge pull request #126 from Invertus/1.1.6
Browse files Browse the repository at this point in the history
1.1.6
  • Loading branch information
GytisZum authored Oct 18, 2023
2 parents c93cb44 + 7e720aa commit f7dfd0e
Show file tree
Hide file tree
Showing 7 changed files with 459 additions and 16 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@
## [1.1.5] - *

- BO : Fixed the redirect issue when payment was aborted.

## [1.1.6] - *
- BO : Added additional check for confirmation email regarding payment status and customer behavior
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ protected function initForm()
$fields = [];
$fields[] = [
'type' => 'free',
'label' => '',
'name' => 'payment_method_label',
];
$fields[] = [
Expand Down
31 changes: 17 additions & 14 deletions saferpayofficial.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct($name = null)
{
$this->name = 'saferpayofficial';
$this->author = 'Invertus';
$this->version = '1.1.5';
$this->version = '1.1.6';
$this->module_key = '3d3506c3e184a1fe63b936b82bda1bdf';
$this->displayName = 'SaferpayOfficial';
$this->description = 'Saferpay Payment module';
Expand Down Expand Up @@ -508,6 +508,7 @@ public function hookActionEmailSendBefore($params)
return true;
}
$cart = new Cart($params['cart']->id);
/** @var \Order $order */
$order = Order::getByCartId($cart->id);

if (!$order) {
Expand All @@ -518,11 +519,11 @@ public function hookActionEmailSendBefore($params)
return true;
}

/** @var \Invertus\SaferPay\Core\Order\Verification\CanSendOrderConfirmationEmail $canSendOrderConfirmationEmail */
$canSendOrderConfirmationEmail = $this->getService(\Invertus\SaferPay\Core\Order\Verification\CanSendOrderConfirmationEmail::class);

if ($params['template'] === 'order_conf') {
if (Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_SEND_ORDER_CONFIRMATION)) {
return true;
}
return false;
return $canSendOrderConfirmationEmail->verify($order, (int) $order->current_state);
}

if ($params['template'] === 'new_order') {
Expand Down Expand Up @@ -554,17 +555,19 @@ public function hookActionOrderStatusUpdate($params = [])
return;
}

if (!Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_SEND_NEW_ORDER_MAIL)) {
return;
}
/** @var \Invertus\SaferPay\Service\SaferPayMailService $mailService */
$mailService = $this->getService(\Invertus\SaferPay\Service\SaferPayMailService::class);

$saferPayAuthorizedStatus = (int) Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_PAYMENT_AUTHORIZED);
if ($orderStatus->id === $saferPayAuthorizedStatus) {
/** @var \Invertus\SaferPay\Service\SaferPayMailService $mailService */
$mailService = $this->getService(
\Invertus\SaferPay\Service\SaferPayMailService::class
);
$mailService->sendNewOrderMail($order, $orderStatus->id);
if ($orderStatus->id === $saferPayAuthorizedStatus && Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_SEND_NEW_ORDER_MAIL)) {
$mailService->sendNewOrderMail($order, (int) $orderStatus->id);
}

/** @var \Invertus\SaferPay\Core\Order\Verification\CanSendOrderConfirmationEmail $canSendOrderConfirmationEmail */
$canSendOrderConfirmationEmail = $this->getService(\Invertus\SaferPay\Core\Order\Verification\CanSendOrderConfirmationEmail::class);

if ($canSendOrderConfirmationEmail->verify($order, (int) $orderStatus->id)) {
$mailService->sendOrderConfMail($order, (int)$orderStatus->id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/ApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function getBaseUrl()
private function isValidResponse(Response $response)
{
if ($response->code >= 300){
throw new SaferPayApiException('Initialize API failed', SaferPayApiException::INITIALIZE);
throw new SaferPayApiException(sprintf('Initialize API failed: %s', $response->raw_body), SaferPayApiException::INITIALIZE);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Config/SaferPayConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class SaferPayConfig
const SAFERPAY_SEND_ORDER_CONFIRMATION = 'SAFERPAY_SEND_ORDER_CONFIRMATION';
const SAFERPAY_SEND_NEW_ORDER_MAIL = 'SAFERPAY_SEND_NEW_ORDER_MAIL';

const STATUS_PS_OS_OUTOFSTOCK_PAID = 'PS_OS_OUTOFSTOCK_PAID';

const SAFERPAY_ORDER_STATE_CHOICE_AWAITING_PAYMENT = 'SAFERPAY_ORDER_STATE_CHOICE_AWAITING_PAYMENT';

const SAFERPAY_TEMPLATE_LOCATION = 'module:saferpayofficial/views/templates/';
Expand Down
59 changes: 59 additions & 0 deletions src/Core/Order/Verification/CanSendOrderConfirmationEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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 [email protected] 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 <[email protected]>
*@copyright SIX Payment Services
*@license SIX Payment Services
*/

namespace Invertus\SaferPay\Core\Order\Verification;

use Invertus\SaferPay\Config\SaferPayConfig;

class CanSendOrderConfirmationEmail
{
public function verify(\Order $order, $orderStatusId)
{
if (!\Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_SEND_ORDER_CONFIRMATION)) {
return false;
}

if (!$this->isOrderStatusValid($orderStatusId)) {
return false;
}

return true;
}

private function isOrderStatusValid($orderStatusId)
{
if ((int) \Configuration::get(SaferPayConfig::SAFERPAY_PAYMENT_AUTHORIZED) === (int) $orderStatusId) {
return true;
}

if ((int) \Configuration::get(SaferPayConfig::SAFERPAY_PAYMENT_COMPLETED) === (int) $orderStatusId) {
return true;
}

if ((int) \Configuration::get(SaferPayConfig::STATUS_PS_OS_OUTOFSTOCK_PAID) === (int) $orderStatusId) {
return true;
}

return false;
}
}
Loading

0 comments on commit f7dfd0e

Please sign in to comment.