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-252 Hosted iframe fix #196

Merged
merged 19 commits into from
Oct 3, 2024
60 changes: 59 additions & 1 deletion controllers/front/return.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
use Invertus\SaferPay\Api\Enum\TransactionStatus;
use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\SaferPay\Controller\AbstractSaferPayController;
use Invertus\SaferPay\Core\Payment\DTO\CheckoutData;
use Invertus\SaferPay\DTO\Response\Assert\AssertBody;
use Invertus\SaferPay\Enum\ControllerName;
use Invertus\SaferPay\Exception\Api\SaferPayApiException;
use Invertus\SaferPay\Processor\CheckoutProcessor;
use Invertus\SaferPay\Service\SaferPayOrderStatusService;
use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAssertion;
use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization;
Expand All @@ -44,7 +46,62 @@ public function postProcess()
$cartId = (int) Tools::getValue('cartId');
$order = new Order($this->getOrderId($cartId));

if (!$order->id) {
/** @var SaferPayTransactionAssertion $transactionAssert */
$transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class);

$assertResponseBody = $transactionAssert->assert($cartId);
$transactionStatus = $assertResponseBody->getTransaction()->getStatus();
MarijusCoding marked this conversation as resolved.
Show resolved Hide resolved

if (Tools::getValue('isBusinessLicence')) {
MarijusCoding marked this conversation as resolved.
Show resolved Hide resolved
/** @var CheckoutProcessor $checkoutProcessor **/
$checkoutProcessor = $this->module->getService(CheckoutProcessor::class);
$checkoutData = CheckoutData::create(
(int) $cartId,
$assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod(),
(int) Configuration::get(SaferPayConfig::IS_BUSINESS_LICENCE)
);

$checkoutData->setOrderStatus($transactionStatus);
$checkoutProcessor->run($checkoutData);

$orderId = $this->getOrderId($cartId);

$order = new Order($orderId);

if (!$assertResponseBody->getLiability()->getLiabilityShift() &&
in_array($order->payment, SaferPayConfig::SUPPORTED_3DS_PAYMENT_METHODS) &&
(int) Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D) === SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D_CANCEL
) {
/** @var SaferPayOrderStatusService $orderStatusService */
$orderStatusService = $this->module->getService(SaferPayOrderStatusService::class);
$orderStatusService->cancel($order);
}

//NOTE to get latest information possible and not override new information.
$order = new Order($orderId);
$paymentMethod = $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod();

// if payment does not support order capture, it means it always auto-captures it (at least with accountToAccount payment),
// so in this case if status comes back "captured" we just update the order state accordingly
if (!SaferPayConfig::supportsOrderCapture($paymentMethod) &&
$transactionStatus === TransactionStatus::CAPTURED
) {
/** @var SaferPayOrderStatusService $orderStatusService */
$orderStatusService = $this->module->getService(SaferPayOrderStatusService::class);
$orderStatusService->setComplete($order);

return;
}

if (SaferPayConfig::supportsOrderCapture($paymentMethod) &&
(int) Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR) === SaferPayConfig::DEFAULT_PAYMENT_BEHAVIOR_CAPTURE &&
$transactionStatus !== TransactionStatus::CAPTURED
) {
/** @var SaferPayOrderStatusService $orderStatusService */
$orderStatusService = $this->module->getService(SaferPayOrderStatusService::class);
$orderStatusService->capture($order);
}

return;
}

Expand All @@ -55,6 +112,7 @@ public function postProcess()

MarijusCoding marked this conversation as resolved.
Show resolved Hide resolved
/** @var SaferPayOrderStatusService $orderStatusService */
$orderStatusService = $this->module->getService(SaferPayOrderStatusService::class);

if ($transactionResponse->getTransaction()->getStatus() === TransactionStatus::PENDING) {
$orderStatusService->setPending($order);
}
Expand Down
9 changes: 6 additions & 3 deletions src/DTO/Request/Initialize/InitializeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,14 @@ public function getAsArray()
'AddressSource' => $this->deliveryAddressForm->getAddressSource(),
'MandatoryFields' => $this->deliveryAddressForm->getMandatoryFields(),
],
'CardForm' => [
'HolderName' => SaferPayConfig::SAFERPAY_CARDFORM_HOLDERNAME_REQUIRENCE,
],
];

if ($this->getPaymentMeansField() === []) {
$return['CardForm'] = [
'HolderName' => SaferPayConfig::SAFERPAY_CARDFORM_HOLDERNAME_REQUIRENCE,
];
}

if ($this->notification !== null) {
$return['Notification'] = [
'MerchantEmails' => [$this->notification->getMerchantEmail()],
Expand Down
2 changes: 1 addition & 1 deletion views/templates/front/credit_cards.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</tr>
</thead>
{foreach $rows as $row}
{$row nofilter|escape:'htmlall':'UTF-8'}
{$row escape:'htmlall':'UTF-8'|nofilter}
MarijusCoding marked this conversation as resolved.
Show resolved Hide resolved
{/foreach}
</table>
</div>
Expand Down