Skip to content

Commit

Permalink
Merge pull request #151 from Invertus/release_1.2.1
Browse files Browse the repository at this point in the history
Release 1.2.1
  • Loading branch information
mant02 authored Mar 6, 2024
2 parents 5700a45 + d6dd9b2 commit 5fda3f3
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 37 deletions.
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,7 @@
- BO : Additional improvements and fixes

- ## [1.2.0] - *
- BO : Added order creation after authorization functionality
- BO : Added order creation after authorization functionality

- ## [1.2.1] - *
- FO : Increased compatibility with PrestaShop 1.6
15 changes: 12 additions & 3 deletions controllers/front/notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ public function postProcess()
$updateSaferPayOrderAction->run(new SaferPayOrder($saferPayOrderId), self::SAFERPAY_ORDER_AUTHORIZE_ACTION);

// If order does not exist but assertion is valid that means order authorized or captured.
$orderId = Order::getIdByCartId($cartId);

if (method_exists('Order', 'getIdByCartId')) {
$orderId = Order::getIdByCartId($cartId);
} else {
// For PrestaShop 1.6 use the alternative method
$orderId = Order::getOrderByCartId($cartId);
}
if (!$orderId) {
/** @var CheckoutProcessor $checkoutProcessor **/
$checkoutProcessor = $this->module->getService(CheckoutProcessor::class);
Expand All @@ -92,7 +96,12 @@ public function postProcess()

$checkoutProcessor->run($checkoutData);

$orderId = Order::getIdByCartId($cart->id);
if (method_exists('Order', 'getIdByCartId')) {
$orderId = Order::getIdByCartId($cartId);
} else {
// For PrestaShop 1.6 or lower, use the alternative method
$orderId = Order::getOrderByCartId($cartId);
}
}

//TODO look into pipeline design pattern to use when object is modified in multiple places to avoid this issue.
Expand Down
26 changes: 22 additions & 4 deletions controllers/front/return.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ public function postProcess()
$checkoutProcessor = $this->module->getService(CheckoutProcessor::class);
$checkoutProcessor->run($checkoutData);

$orderId = \Order::getIdByCartId($cartId);
if (method_exists('Order', 'getIdByCartId')) {
$orderId = Order::getIdByCartId($cartId);
} else {
// For PrestaShop 1.6 use the alternative method
$orderId = Order::getOrderByCartId($cartId);
}

$paymentBehaviourWithout3DS = (int) Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D);

Expand Down Expand Up @@ -175,7 +180,14 @@ private function getSuccessControllerName($isBusinessLicence, $fieldToken)
return $successController;
}

private function executeTransaction(int $orderId, int $selectedCard)
/**
* @param int $orderId
* @param int $selectedCard
*
* @return \Invertus\SaferPay\DTO\Response\Assert\AssertBody
* @throws Exception
*/
private function executeTransaction($orderId, $selectedCard)
{
/** @var SaferPayTransactionAuthorization $saferPayTransactionAuthorization */
$saferPayTransactionAuthorization = $this->module->getService(SaferPayTransactionAuthorization::class);
Expand All @@ -189,14 +201,20 @@ private function executeTransaction(int $orderId, int $selectedCard)
return $response;
}

private function executePaymentPageAssertion(int $cartId, int $isBusinessLicence)
/**
* @param int $cartId
* @param int $isBusinessLicence
*
* @return \Invertus\SaferPay\DTO\Response\Assert\AssertBody|null
* @throws Exception
*/
private function executePaymentPageAssertion($cartId, $isBusinessLicence)
{

/** @var SaferPayTransactionAssertion $transactionAssert */
$transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class);
$assertionResponse = $transactionAssert->assert($cartId);


return $assertionResponse;
}
}
9 changes: 8 additions & 1 deletion controllers/front/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,19 @@ public function postProcess()
$exceptionService = $this->module->getService(SaferPayExceptionService::class);
$this->errors[] = $exceptionService->getErrorMessageForException($exception, $exceptionService->getErrorMessages());

if (method_exists('Order', 'getIdByCartId')) {
$orderId = Order::getIdByCartId($this->context->cart->id);
} else {
// For PrestaShop 1.6 use the alternative method
$orderId = Order::getOrderByCartId($this->context->cart->id);
}

$redirectLink = $this->context->link->getModuleLink(
$this->module->name,
'fail',
[
'cartId' => $this->context->cart->id,
'orderId' => Order::getIdByCartId($this->context->cart->id),
'orderId' => $orderId,
'secureKey' => $this->context->cart->secure_key,
'moduleId' => $this->module->id,
],
Expand Down
6 changes: 3 additions & 3 deletions saferpayofficial.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct($name = null)
{
$this->name = 'saferpayofficial';
$this->author = 'Invertus';
$this->version = '1.2.0';
$this->version = '1.2.1';
$this->module_key = '3d3506c3e184a1fe63b936b82bda1bdf';
$this->displayName = 'SaferpayOfficial';
$this->description = 'Saferpay Payment module';
Expand Down Expand Up @@ -572,7 +572,7 @@ public function hookActionEmailSendBefore($params)
$canSendOrderConfirmationEmail = $this->getService(\Invertus\SaferPay\Core\Order\Verification\CanSendOrderConfirmationEmail::class);

if ($params['template'] === 'order_conf') {
return $canSendOrderConfirmationEmail->verify($order, (int) $order->current_state);
return $canSendOrderConfirmationEmail->verify((int) $order->current_state);
}

if ($params['template'] === 'new_order') {
Expand Down Expand Up @@ -615,7 +615,7 @@ public function hookActionOrderStatusUpdate($params = [])
/** @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)) {
if ($canSendOrderConfirmationEmail->verify((int) $orderStatus->id)) {
$mailService->sendOrderConfMail($order, (int) $orderStatus->id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

class CanSendOrderConfirmationEmail
{
public function verify(\Order $order, $orderStatusId)
public function verify($orderStatusId)
{
if (!\Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_SEND_ORDER_CONFIRMATION)) {
return false;
Expand Down
5 changes: 5 additions & 0 deletions src/Entity/SaferPayOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class SaferPayOrder extends ObjectModel
*/
public $id_order;

/**
* @var Int|null
*/
public $id_cart;

/**
* @var Int
*/
Expand Down
7 changes: 6 additions & 1 deletion src/EntityBuilder/SaferPayOrderBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ class SaferPayOrderBuilder
//TODO to pass $body as InitializeBody.
public function create($body, $cartId, $customerId, $isTransaction)
{
$orderId = Order::getIdByCartId($cartId);
if (method_exists('Order', 'getIdByCartId')) {
$orderId = Order::getIdByCartId($cartId);
} else {
// For PrestaShop 1.6 use the alternative method
$orderId = Order::getOrderByCartId($cartId);
}

$saferPayOrder = new SaferPayOrder();
$saferPayOrder->token = $body->Token;
Expand Down
4 changes: 1 addition & 3 deletions src/Exception/CouldNotProcessCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@

namespace Invertus\SaferPay\Exception;

use Invertus\SaferPay\Exception\Restriction\SaferPayException;

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

class CouldNotProcessCheckout extends SaferPayException
class CouldNotProcessCheckout extends SaferPayException
{
/**
* @param int $cartId
Expand Down
2 changes: 0 additions & 2 deletions src/Exception/Order/CouldNotChangeOrderStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

namespace Invertus\SaferPay\Exception;

use Invertus\SaferPay\Exception\Restriction\SaferPayException;

if (!defined('_PS_VERSION_')) {
exit;
}
Expand Down
13 changes: 3 additions & 10 deletions src/Exception/SaferPayException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
*@license SIX Payment Services
*/

namespace Invertus\SaferPay\Exception\Restriction;

use Invertus\SaferPay\Exception\ExceptionCode;
namespace Invertus\SaferPay\Exception;

if (!defined('_PS_VERSION_')) {
exit;
Expand All @@ -48,15 +46,10 @@ public function getContext()
return $this->context;
}

/**
* @param \Exception $exception
*
* @return static
*/
public static function unknownError($exception)
public static function unknownError()
{
return new static(
'An unknown error error occurred. Please check system logs or contact Click to Pay support.',
'An unknown error error occurred. Please check system logs or contact support.',
ExceptionCode::UNKNOWN_ERROR
);
}
Expand Down
12 changes: 10 additions & 2 deletions src/Processor/CheckoutProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private function processCreateSaferPayOrder($initializeBody, $cartId, $customerI
);
}

private function processAuthorizedOrder(CheckoutData $data, Cart $cart): void
private function processAuthorizedOrder(CheckoutData $data, Cart $cart)
{
try {
$saferPayOrder = new SaferPayOrder($this->saferPayOrderRepository->getIdByCartId($cart->id));
Expand All @@ -188,7 +188,15 @@ private function processAuthorizedOrder(CheckoutData $data, Cart $cart): void
$this->processCreateOrder($cart, $data->getPaymentMethod());
}

$order = new Order(Order::getIdByCartId($cart->id));
if (method_exists('Order', 'getIdByCartId')) {
$orderId = Order::getIdByCartId($cart->id);
$order = new Order($orderId);
} else {
// For PrestaShop 1.6 use the alternative method
$orderId = Order::getOrderByCartId($cart->id);
$order = new Order($orderId);
}

$saferPayOrder->id_order = $order->id;

if ($data->getOrderStatus() === 'AUTHORIZED') {
Expand Down
8 changes: 7 additions & 1 deletion src/Service/CartDuplicationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ private function restoreCartRuleQuantity($cartId, $cartRuleId)
$cartRule->quantity++;
$cartRule->update();

$orderId = Order::getIdByCartId($cartId);
if (method_exists('Order', 'getIdByCartId')) {
$orderId = Order::getIdByCartId($cartId);
} else {
// For PrestaShop 1.6 or lower, use the alternative method
$orderId = Order::getOrderByCartId($cartId);
}

$sql = 'DELETE FROM `' . _DB_PREFIX_ . 'order_cart_rule`
WHERE id_order = ' . (int) $orderId . '
AND id_cart_rule = ' . (int) $cartRuleId;
Expand Down
4 changes: 2 additions & 2 deletions src/Service/Request/InitializeRequestObjectCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function create(
$payment = $this->requestObjectCreator->createPayment($cart, $totalPrice);
$payer = new Payer();

$languageCode = !empty($cart->getAssociatedLanguage()->iso_code)
? $cart->getAssociatedLanguage()->iso_code
$languageCode = !empty(\Context::getContext()->language->iso_code)
? \Context::getContext()->language->iso_code
: 'en';

$payer->setLanguageCode($languageCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function assert($cartId)
);

$saferPayOrder->transaction_id = $assertBody->getTransaction()->getId();
$saferPayOrder->id_cart = $cartId;
$saferPayOrder->update();

return $assertBody;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function authorize($cartId, $saveCard, $selectedCard)
);

$saferPayOrder->transaction_id = $assertBody->getTransaction()->getId();
$saferPayOrder->id_cart = $cartId;
$saferPayOrder->update();

return $assertBody;
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Service/SaferPayPaymentNotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
class SaferPayPaymentNotationTest extends UnitTestCase
{
/** @dataProvider getPaymentMethodForDisplayDataProvider */
public function testGetForDisplay(string $paymentMethod, string $expectedResult)
public function testGetForDisplay($paymentMethod, $expectedResult)
{
$result = (new \Invertus\SaferPay\Service\SaferPayPaymentNotation)->getForDisplay($paymentMethod);
$this->assertEquals($expectedResult, $result);
}

/** @dataProvider getPaymentMethodDataProvider */
public function testGetShortName(string $paymentMethod, string $expectedResult)
public function testGetShortName($paymentMethod, $expectedResult)
{
$result = (new \Invertus\SaferPay\Service\SaferPayPaymentNotation)->getShortName($paymentMethod);
$this->assertEquals($expectedResult, $result);
Expand Down
2 changes: 1 addition & 1 deletion views/templates/hook/front/payments.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
*}

{foreach $payments as $payment}
{$payment|escape:'htmlall':'UTF-8'}
{$payment|cleanHtml nofilter}
{/foreach}

0 comments on commit 5fda3f3

Please sign in to comment.