Skip to content

Commit 4f257ad

Browse files
nrostrow-metaNoah Ostrowski
andauthored
Having dynamic checkout APIs throw error if config value is not enabled (#625)
Co-authored-by: Noah Ostrowski <[email protected]>
1 parent cfadd77 commit 4f257ad

9 files changed

+38
-10
lines changed

app/code/Meta/Sales/Api/AddCartItemsApiInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ interface AddCartItemsApiInterface
3333
* @param string $externalBusinessId
3434
* @param \Magento\Quote\Api\Data\CartItemInterface[] $items
3535
* @return \Meta\Sales\Api\AddCartItemsApiResponseInterface
36-
* @throws UnauthorizedTokenException
37-
* @throws LocalizedException
36+
* @throws \Magento\Framework\Exception\UnauthorizedTokenException
37+
* @throws \Magento\Framework\Exception\LocalizedException
3838
*/
3939
public function addCartItems(string $externalBusinessId, array $items): AddCartItemsApiResponseInterface;
4040
}

app/code/Meta/Sales/Api/CreateCartApiInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ interface CreateCartApiInterface
3030
*
3131
* @param string $externalBusinessId
3232
* @return string
33-
* @throws UnauthorizedTokenException
34-
* @throws LocalizedException
33+
* @throws \Magento\Framework\Exception\UnauthorizedTokenException
34+
* @throws \Magento\Framework\Exception\LocalizedException
3535
*/
3636
public function createCart(string $externalBusinessId): string;
3737
}

app/code/Meta/Sales/Helper/OrderHelper.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,29 @@ class OrderHelper
4545
*/
4646
private CollectionFactory $collectionFactory;
4747

48+
/**
49+
* @var SystemConfig
50+
*/
51+
private SystemConfig $systemConfig;
52+
4853
/**
4954
* Constructor
5055
*
5156
* @param OrderExtensionFactory $orderExtensionFactory
5257
* @param FacebookOrderInterfaceFactory $facebookOrderFactory
5358
* @param CollectionFactory $collectionFactory
59+
* @param SystemConfig $systemConfig
5460
*/
5561
public function __construct(
5662
OrderExtensionFactory $orderExtensionFactory,
5763
FacebookOrderInterfaceFactory $facebookOrderFactory,
58-
CollectionFactory $collectionFactory
64+
CollectionFactory $collectionFactory,
65+
SystemConfig $systemConfig
5966
) {
6067
$this->orderExtensionFactory = $orderExtensionFactory;
6168
$this->facebookOrderFactory = $facebookOrderFactory;
6269
$this->collectionFactory = $collectionFactory;
70+
$this->systemConfig = $systemConfig;
6371
}
6472

6573
/**
@@ -149,4 +157,18 @@ public function getMBEInstalledConfigsByExternalBusinessId(string $externalBusin
149157
return [];
150158
}
151159
}
160+
161+
/**
162+
* Throws an exception if dynamic checkout apis are not enabled
163+
*
164+
* @return void
165+
*/
166+
public function checkDynamicCheckoutConfig(): void
167+
{
168+
if (!$this->systemConfig->areDynamicCheckoutApisEnabled()) {
169+
throw new LocalizedException(__(
170+
"Dynamic Checkout APIs are not enabled"
171+
));
172+
}
173+
}
152174
}

app/code/Meta/Sales/Model/Api/AddCartItemsApi.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ public function __construct(
7474
* @param string $externalBusinessId
7575
* @param \Magento\Quote\Api\Data\CartItemInterface[] $items
7676
* @return \Meta\Sales\Api\AddCartItemsApiResponseInterface
77-
* @throws UnauthorizedTokenException
78-
* @throws LocalizedException
77+
* @throws \Magento\Framework\Exception\UnauthorizedTokenException
78+
* @throws \Magento\Framework\Exception\LocalizedException
7979
*/
8080
public function addCartItems(string $externalBusinessId, array $items): AddCartItemsApiResponseInterface
8181
{
82+
$this->orderHelper->checkDynamicCheckoutConfig();
8283
$this->authenticator->authenticateRequest();
8384
$storeId = $this->orderHelper->getStoreIdByExternalBusinessId($externalBusinessId);
8485
$itemsAdded = [];

app/code/Meta/Sales/Model/Api/CartShippingOptionsApi.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function __construct(
8383
*/
8484
public function cartShippingOptions(string $externalBusinessId, string $cartId, AddressInterface $address): array
8585
{
86+
$this->orderHelper->checkDynamicCheckoutConfig();
8687
$this->authenticator->authenticateRequest();
8788
$storeId = $this->orderHelper->getStoreIdByExternalBusinessId($externalBusinessId);
8889
try {

app/code/Meta/Sales/Model/Api/CartTotalsApi.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ public function __construct(
7575
* @param string $externalBusinessId
7676
* @param string $cartId
7777
* @return \Magento\Quote\Api\Data\TotalsInterface
78-
* @throws UnauthorizedTokenException
78+
* @throws \Magento\Framework\Exception\UnauthorizedTokenException
7979
* @throws \Magento\Framework\Exception\NoSuchEntityException
8080
* @throws \Magento\Framework\Exception\LocalizedException
8181
*/
8282
public function getCartTotals(string $externalBusinessId, string $cartId): TotalsInterface
8383
{
84+
$this->orderHelper->checkDynamicCheckoutConfig();
8485
$this->authenticator->authenticateRequest();
8586
$storeId = $this->orderHelper->getStoreIdByExternalBusinessId($externalBusinessId);
8687
try {

app/code/Meta/Sales/Model/Api/CreateCartApi.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ public function __construct(
101101
*
102102
* @param string $externalBusinessId
103103
* @return string
104-
* @throws UnauthorizedTokenException
105-
* @throws LocalizedException
104+
* @throws \Magento\Framework\Exception\UnauthorizedTokenException
105+
* @throws \Magento\Framework\Exception\LocalizedException
106106
*/
107107
public function createCart(string $externalBusinessId): string
108108
{
109+
$this->orderHelper->checkDynamicCheckoutConfig();
109110
$this->authenticator->authenticateRequest();
110111
$storeId = $this->orderHelper->getStoreIdByExternalBusinessId($externalBusinessId);
111112

app/code/Meta/Sales/Model/Api/DeleteCartItemApi.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function __construct(
8282
*/
8383
public function deleteCartItem(string $externalBusinessId, string $cartId, string $itemId): bool
8484
{
85+
$this->orderHelper->checkDynamicCheckoutConfig();
8586
$this->authenticator->authenticateRequest();
8687
$storeId = $this->orderHelper->getStoreIdByExternalBusinessId($externalBusinessId);
8788
try {

app/code/Meta/Sales/Model/Api/SetCartShippingOptionApi.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function setCartShippingOption(
8585
string $cartId,
8686
ShippingInformationInterface $addressInformation
8787
): PaymentDetailsInterface {
88+
$this->orderHelper->checkDynamicCheckoutConfig();
8889
$this->authenticator->authenticateRequest();
8990
$storeId = $this->orderHelper->getStoreIdByExternalBusinessId($externalBusinessId);
9091
try {

0 commit comments

Comments
 (0)