Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SL-155/aborted-payment-issue #122

Merged
merged 1 commit into from
Aug 22, 2023
Merged
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
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
Loading