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

Move the Payment booster view logic #243

Merged
merged 17 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
24 changes: 1 addition & 23 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Config implements ConfigInterface
private const PATH_SECRET = 'checkout/bold_checkout_base/shared_secret';
private const PATH_ENABLED = 'checkout/bold_checkout_base/enabled';
private const PATH_TYPE = 'checkout/bold_checkout_base/type';
private const PATH_PAYMENT_TITLE = 'checkout/bold_checkout_base/payment_title';
public const PATH_PAYMENT_TITLE = 'checkout/bold_checkout_base/payment_title';
private const PATH_PARALLEL_CHECKOUT_BUTTON_TITLE = 'checkout/bold_checkout_base/parallel_checkout_button_title';
private const PATH_ENABLED_FOR = 'checkout/bold_checkout_advanced/enabled_for';
private const PATH_IP_WHITELIST = 'checkout/bold_checkout_advanced/ip_whitelist';
Expand Down Expand Up @@ -325,28 +325,6 @@ public function isCheckoutTypeParallel(int $websiteId): bool
) === ConfigInterface::VALUE_TYPE_PARALLEL;
}

/**
* @inheritDoc
*/
public function isCheckoutTypeSelfHosted(int $websiteId): bool
{
return (int)$this->configManagement->getValue(
self::PATH_TYPE,
$websiteId
) === ConfigInterface::VALUE_TYPE_SELF;
}

/**
* @inheritDoc
*/
public function isCheckoutTypeSelfHostedReact(int $websiteId): bool
{
return (int)$this->configManagement->getValue(
self::PATH_TYPE,
$websiteId
) === ConfigInterface::VALUE_TYPE_SELF_REACT;
}

/**
* @inheritDoc
*/
Expand Down
2 changes: 0 additions & 2 deletions Model/Config/Source/CheckoutTypeSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public function toOptionArray(): array
return [
['value' => ConfigInterface::VALUE_TYPE_STANDARD, 'label' => __('Bold-Hosted (Standard)')],
['value' => ConfigInterface::VALUE_TYPE_PARALLEL, 'label' => __('Dual')],
['value' => ConfigInterface::VALUE_TYPE_SELF, 'label' => __('Payment Booster')],
['value' => ConfigInterface::VALUE_TYPE_SELF_REACT, 'label' => __('Self-Hosted')],
];
}
}
18 changes: 0 additions & 18 deletions Model/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ interface ConfigInterface
public const VALUE_ENABLED_FOR_PERCENTAGE = 3;
public const VALUE_TYPE_STANDARD = 0;
public const VALUE_TYPE_PARALLEL = 1;
public const VALUE_TYPE_SELF = 2;
public const VALUE_TYPE_SELF_REACT = 3;
public const PATH_SHOP_ID = 'checkout/bold_checkout_base/shop_id';

/**
Expand Down Expand Up @@ -170,22 +168,6 @@ public function isCheckoutTypeStandard(int $websiteId): bool;
*/
public function isCheckoutTypeParallel(int $websiteId): bool;

/**
* Check if Bold Checkout type is self-hosted (Magento storefront).
*
* @param int $websiteId
* @return bool
*/
public function isCheckoutTypeSelfHosted(int $websiteId): bool;

/**
* Check if Bold Checkout type is self-hosted (React application).
*
* @param int $websiteId
* @return bool
*/
public function isCheckoutTypeSelfHostedReact(int $websiteId): bool;

/**
* Get Bold Payment storefront title.
*
Expand Down
49 changes: 0 additions & 49 deletions Model/Order/Address/Converter.php

This file was deleted.

28 changes: 26 additions & 2 deletions Model/Order/InitOrderFromQuote.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
namespace Bold\Checkout\Model\Order;

use Bold\Checkout\Api\Http\ClientInterface;
use Bold\Checkout\Model\Order\InitOrderFromQuote\OrderDataProcessorInterface;
use Bold\Checkout\Model\Quote\GetCartLineItems;
use Bold\Checkout\Model\Quote\QuoteAction;
use Bold\Checkout\Model\Quote\SetQuoteExtensionData;
use Magento\Customer\Api\Data\AddressInterface;
use Magento\Directory\Model\Country;
use Magento\Directory\Model\ResourceModel\Country\CollectionFactory;
Expand Down Expand Up @@ -41,26 +43,42 @@ class InitOrderFromQuote
*/
private $quoteAction;

/**
* @var SetQuoteExtensionData
*/
private $setQuoteExtensionData;

/**
* @var OrderDataProcessorInterface[]
*/
private $orderDataProcessors;

/**
* @param ClientInterface $client
* @param CollectionFactory $countryCollectionFactory
* @param GetCartLineItems $getCartLineItems
* @param QuoteAction $quoteAction
* @param SetQuoteExtensionData $setQuoteExtensionData
* @param OrderDataProcessorInterface[] $orderDataProcessors
*/
public function __construct(
ClientInterface $client,
CollectionFactory $countryCollectionFactory,
GetCartLineItems $getCartLineItems,
QuoteAction $quoteAction
QuoteAction $quoteAction,
SetQuoteExtensionData $setQuoteExtensionData,
array $orderDataProcessors = []
) {
$this->client = $client;
$this->countryCollectionFactory = $countryCollectionFactory;
$this->getCartLineItems = $getCartLineItems;
$this->quoteAction = $quoteAction;
$this->setQuoteExtensionData = $setQuoteExtensionData;
$this->orderDataProcessors = $orderDataProcessors;
}

/**
* Initialize order on bold side.
* Initialize order on Bold side.
*
* @param CartInterface $quote
* @param string $flowId
Expand Down Expand Up @@ -112,6 +130,12 @@ public function init(CartInterface $quote, string $flowId = self::FLOW_ID): arra
throw new LocalizedException(__('Cannot authenticate customer with id="%1"', $quote->getCustomerId()));
}

$this->setQuoteExtensionData->execute((int)$quote->getId(), false);

foreach ($this->orderDataProcessors as $processor) {
$orderData = $processor->process($orderData, $quote);
}

return $orderData;
}

Expand Down
21 changes: 21 additions & 0 deletions Model/Order/InitOrderFromQuote/OrderDataProcessorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);

namespace Bold\Checkout\Model\Order\InitOrderFromQuote;

use Magento\Quote\Api\Data\CartInterface;

/**
* Process bold order data service interface.
*/
interface OrderDataProcessorInterface
{
/**
* Process bold order data.
*
* @param array $data
* @param CartInterface $quote
* @return array
*/
public function process(array $data, CartInterface $quote): array;
}
40 changes: 26 additions & 14 deletions Model/Order/PlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
use Bold\Checkout\Api\Data\PlaceOrder\ResultInterface;
use Bold\Checkout\Api\Data\PlaceOrder\ResultInterfaceFactory;
use Bold\Checkout\Api\PlaceOrderInterface;
use Bold\Checkout\Model\ConfigInterface;
use Bold\Checkout\Model\Http\Client\Request\Validator\OrderPayloadValidator;
use Bold\Checkout\Model\Order\PlaceOrder\CreateOrderFromPayload;
use Bold\Checkout\Model\Order\PlaceOrder\ProcessOrder;
use Bold\Checkout\Model\Order\PlaceOrder\Progress;
use Bold\Checkout\Model\Quote\LoadAndValidate;
use Bold\Checkout\Model\Quote\QuoteExtensionDataFactory;
use Bold\Checkout\Model\ResourceModel\Quote\QuoteExtensionData;
use Exception;
use Magento\Framework\Exception\LocalizedException;

Expand All @@ -37,11 +38,6 @@ class PlaceOrder implements PlaceOrderInterface
*/
private $orderPayloadValidator;

/**
* @var ConfigInterface
*/
private $config;

/**
* @var CreateOrderFromPayload
*/
Expand All @@ -62,34 +58,47 @@ class PlaceOrder implements PlaceOrderInterface
*/
private $loadAndValidate;

/**
* @var QuoteExtensionDataFactory
*/
private $quoteExtensionDataFactory;

/**
* @var QuoteExtensionData
*/
private $quoteExtensionDataResource;

/**
* @param OrderPayloadValidator $orderPayloadValidator
* @param ResultInterfaceFactory $responseFactory
* @param ErrorInterfaceFactory $errorFactory
* @param ConfigInterface $config
* @param CreateOrderFromPayload $createOrderFromPayload
* @param ProcessOrder $processOrder
* @param Progress $progress
* @param LoadAndValidate $loadAndValidate
* @param QuoteExtensionDataFactory $quoteExtensionDataFactory
* @param QuoteExtensionData $quoteExtensionDataResource
*/
public function __construct(
OrderPayloadValidator $orderPayloadValidator,
ResultInterfaceFactory $responseFactory,
ErrorInterfaceFactory $errorFactory,
ConfigInterface $config,
CreateOrderFromPayload $createOrderFromPayload,
ProcessOrder $processOrder,
Progress $progress,
LoadAndValidate $loadAndValidate
LoadAndValidate $loadAndValidate,
QuoteExtensionDataFactory $quoteExtensionDataFactory,
QuoteExtensionData $quoteExtensionDataResource
) {
$this->responseFactory = $responseFactory;
$this->errorFactory = $errorFactory;
$this->orderPayloadValidator = $orderPayloadValidator;
$this->config = $config;
$this->createOrderFromPayload = $createOrderFromPayload;
$this->processOrder = $processOrder;
$this->progress = $progress;
$this->loadAndValidate = $loadAndValidate;
$this->quoteExtensionDataFactory = $quoteExtensionDataFactory;
$this->quoteExtensionDataResource = $quoteExtensionDataResource;
}

/**
Expand All @@ -111,8 +120,12 @@ public function place(string $shopId, OrderDataInterface $order): ResultInterfac
return $this->getValidationErrorResponse($e->getMessage());
}
try {
$websiteId = (int)$quote->getStore()->getWebsiteId();
$magentoOrder = $this->config->isCheckoutTypeSelfHosted($websiteId)
$quoteExtensionData = $this->quoteExtensionDataFactory->create();
$this->quoteExtensionDataResource->load(
$quoteExtensionData,
$quote->getId(), QuoteExtensionData::QUOTE_ID
);
$magentoOrder = $quoteExtensionData->getOrderCreated()
? $this->processOrder->process($order)
: $this->createOrderFromPayload->createOrder($order, $quote);
} catch (Exception $e) {
Expand Down Expand Up @@ -141,7 +154,7 @@ public function place(string $shopId, OrderDataInterface $order): ResultInterfac
* Build validation error response.
*
* @param string $message
* @return Bold\Checkout\Api\Data\PlaceOrder\ResultInterface
* @return ResultInterface
*/
private function getValidationErrorResponse(string $message): ResultInterface
{
Expand All @@ -159,5 +172,4 @@ private function getValidationErrorResponse(string $message): ResultInterface
]
);
}

}
1 change: 1 addition & 0 deletions Model/Order/PlaceOrder/CreateOrderFromPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Bold\Checkout\Api\Data\PlaceOrder\Request\OrderDataInterface;
use Bold\Checkout\Model\Order\OrderExtensionData;
use Bold\Checkout\Model\Order\OrderExtensionDataFactory;
use Bold\Checkout\Model\Order\PlaceOrder\CreateOrderFromPayload\CreateOrderFromQuote;
use Bold\Checkout\Model\ResourceModel\Order\OrderExtensionData as OrderExtensionDataResource;
use Exception;
use Magento\Framework\Event\ManagerInterface as EventManagerInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Bold\Checkout\Model\Order\PlaceOrder;
namespace Bold\Checkout\Model\Order\PlaceOrder\CreateOrderFromPayload;

use Bold\Checkout\Api\Data\PlaceOrder\Request\OrderDataInterface;
use Bold\Checkout\Model\Payment\Gateway\Service;
Expand Down
2 changes: 0 additions & 2 deletions Model/Order/PlaceOrder/ProcessOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderInterfaceFactory;
use Magento\Sales\Model\OrderRepository;
use Magento\Sales\Model\ResourceModel\Order;

/**
* Process order in case of self-hosted checkout.
Expand Down
3 changes: 2 additions & 1 deletion Model/Payment/Gateway/Config/CanUseCheckoutValueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(Session $checkoutSession)
*/
public function handle(array $subject, $storeId = null): bool
{
return $this->checkoutSession->getBoldCheckoutData() !== null;
return $this->checkoutSession->getBoldCheckoutData() !== null
&& !$this->checkoutSession->getQuote()->getIsMultiShipping();
}
}
3 changes: 2 additions & 1 deletion Model/Payment/Gateway/Config/IsActiveValueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public function handle(array $subject, $storeId = null)
{
try {
if ($this->state->getAreaCode() === Area::AREA_FRONTEND) {
return $this->checkoutSession->getBoldCheckoutData() !== null;
return $this->checkoutSession->getBoldCheckoutData() !== null
&& !$this->checkoutSession->getQuote()->getIsMultiShipping();
}
} catch (LocalizedException $e) {
return false;
Expand Down
Loading