Skip to content

Commit

Permalink
Merge pull request #122 from Invertus/SL-155/aborted-payment-issue
Browse files Browse the repository at this point in the history
SL-155/aborted-payment-issue
  • Loading branch information
APabisz authored Aug 22, 2023
2 parents 7ea6f2f + 21ee441 commit a203e24
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 62 deletions.
2 changes: 1 addition & 1 deletion controllers/front/notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function assertTransaction($cartId)
{
/** @var SaferPayTransactionAssertion $transactionAssert */
$transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class);
$assertionResponse = $transactionAssert->assert(Order::getOrderByCartId($cartId));
$assertionResponse = $transactionAssert->assert(Order::getOrderByCartId($cartId), true);

return $assertionResponse;
}
Expand Down
64 changes: 51 additions & 13 deletions controllers/front/return.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,56 @@ public function postProcess()
]));
}

Tools::redirect($this->context->link->getModuleLink(
$this->module->name,
$this->getSuccessControllerName($isBusinessLicence, $fieldToken),
[
'cartId' => $cartId,
'orderId' => $orderId,
'moduleId' => $moduleId,
'secureKey' => $secureKey,
'selectedCard' => $selectedCard
],
true
));
try {
$this->assertTransaction($orderId);

Tools::redirect($this->context->link->getModuleLink(
$this->module->name,
$this->getSuccessControllerName($isBusinessLicence, $fieldToken),
[
'cartId' => $cartId,
'orderId' => $orderId,
'moduleId' => $moduleId,
'secureKey' => $secureKey,
'selectedCard' => $selectedCard,
],
true
));

} catch (Exception $e) {
PrestaShopLogger::addLog(
sprintf(
'Failed to assert transaction. Message: %s. File name: %s',
$e->getMessage(),
self::FILENAME
)
);

Tools::redirect($this->context->link->getModuleLink(
$this->module->name,
'failValidation',
[
'cartId' => $cartId,
'orderId' => $orderId,
'secureKey' => $secureKey,
],
true
));
}
}

/**
* @param $cartId
* @return AssertBody
* @throws Exception
*/
private function assertTransaction($orderId)
{
/** @var SaferPayTransactionAssertion $transactionAssert */
$transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class);
$assertionResponse = $transactionAssert->assert($orderId, false);

return $assertionResponse;
}

private function getSuccessControllerName($isBusinessLicence, $fieldToken)
Expand All @@ -88,4 +126,4 @@ private function getSuccessControllerName($isBusinessLicence, $fieldToken)

return $successController;
}
}
}
57 changes: 11 additions & 46 deletions controllers/front/success.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
*@license SIX Payment Services
*/

use Invertus\SaferPay\Api\Enum\TransactionStatus;
use Invertus\SaferPay\Controller\AbstractSaferPayController;
use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAssertion;

class SaferPayOfficialSuccessModuleFrontController extends AbstractSaferPayController
{
Expand Down Expand Up @@ -51,49 +49,16 @@ public function postProcess()
Tools::redirect($redirectLink);
}

try {
// TODO The shopping cart should be locked to prevent problems with the notify.php process running at the same time.
// $this->assertTransaction($orderId);

Tools::redirect($this->context->link->getPageLink(
'order-confirmation',
true,
null,
[
'id_cart' => $cartId,
'id_module' => $moduleId,
'id_order' => $orderId,
'key' => $secureKey,
]
));
} catch (Exception $e) {
PrestaShopLogger::addLog(
sprintf(
'Failed to assert transaction. Message: %s. File name: %s',
$e->getMessage(),
self::FILENAME
)
);

Tools::redirect($this->context->link->getModuleLink(
$this->module->name,
'failValidation',
[
'cartId' => $cartId,
'orderId' => $orderId,
'secureKey' => $secureKey
],
true
));
}
}

private function assertTransaction($orderId)
{
/** @var SaferPayTransactionAssertion $transactionAssert */
$transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class);
$assertionResponse = $transactionAssert->assert($orderId);

return $assertionResponse;
Tools::redirect($this->context->link->getPageLink(
'order-confirmation',
true,
null,
[
'id_cart' => $cartId,
'id_module' => $moduleId,
'id_order' => $orderId,
'key' => $secureKey,
]
));
}
}
6 changes: 4 additions & 2 deletions src/Service/TransactionFlow/SaferPayTransactionAssertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(
* @return AssertBody
* @throws \Exception
*/
public function assert($orderId)
public function assert($orderId, $changeOrderStatus)
{
$saferPayOrder = $this->getSaferPayOrder($orderId);
$order = new Order($orderId);
Expand All @@ -87,7 +87,9 @@ public function assert($orderId)
$saferPayOrder->transaction_id = $assertBody->getTransaction()->getId();
$saferPayOrder->update();

$this->orderStatusService->assert($order, $assertBody->getTransaction()->getStatus());
if ($changeOrderStatus) {
$this->orderStatusService->assert($order, $assertBody->getTransaction()->getStatus());
}

return $assertBody;
}
Expand Down

0 comments on commit a203e24

Please sign in to comment.