Skip to content

Commit

Permalink
Merge pull request #125 from Invertus/can-send-order-confirmation
Browse files Browse the repository at this point in the history
Can send order confirmation:
  • Loading branch information
tomjas1997 authored Oct 12, 2023
2 parents e677b6c + 5638518 commit 6418c9c
Show file tree
Hide file tree
Showing 10 changed files with 455 additions and 15 deletions.
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
29 changes: 16 additions & 13 deletions saferpayofficial.php
Original file line number Diff line number Diff line change
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
Empty file modified src/Api/Enum/TransactionStatus.php
100644 → 100755
Empty file.
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;
}
}
Empty file modified src/Provider/BasicIdempotencyProvider.php
100644 → 100755
Empty file.
Empty file modified src/Provider/IdempotencyProviderInterface.php
100644 → 100755
Empty file.
Loading

0 comments on commit 6418c9c

Please sign in to comment.