diff --git a/src/Handler/Order/OrderCreationHandler.php b/src/Handler/Order/OrderCreationHandler.php index 827c1d995..7a3316cf4 100644 --- a/src/Handler/Order/OrderCreationHandler.php +++ b/src/Handler/Order/OrderCreationHandler.php @@ -298,6 +298,7 @@ private function createRecurringOrderEntity(Order $order, string $method): void 'Failed to create recurring order', [ 'Exception message' => $exception->getMessage(), + 'Exception code' => $exception->getCode(), ] ); } diff --git a/subscription/Exception/CouldNotProvideCarrierDeliveryPrice.php b/subscription/Exception/CouldNotProvideSubscriptionCarrierDeliveryPrice.php similarity index 60% rename from subscription/Exception/CouldNotProvideCarrierDeliveryPrice.php rename to subscription/Exception/CouldNotProvideSubscriptionCarrierDeliveryPrice.php index c6f20a9e4..6c9709b7f 100644 --- a/subscription/Exception/CouldNotProvideCarrierDeliveryPrice.php +++ b/subscription/Exception/CouldNotProvideSubscriptionCarrierDeliveryPrice.php @@ -2,17 +2,17 @@ namespace Mollie\Subscription\Exception; -class CouldNotProvideCarrierDeliveryPrice extends MollieSubscriptionException +class CouldNotProvideSubscriptionCarrierDeliveryPrice extends MollieSubscriptionException { - public static function failedToFindSelectedCarrierForSubscriptionOrder(): CouldNotProvideCarrierDeliveryPrice + public static function failedToFindSelectedCarrier(): CouldNotProvideSubscriptionCarrierDeliveryPrice { return new self( - 'Failed to find selected carrier for subscription order', - ExceptionCode::ORDER_FAILED_TO_FIND_SELECTED_CARRIER_FOR_SUBSCRIPTION_ORDER + 'Failed to find selected carrier', + ExceptionCode::ORDER_FAILED_TO_FIND_SELECTED_CARRIER ); } - public static function failedToFindOrderCart(): CouldNotProvideCarrierDeliveryPrice + public static function failedToFindOrderCart(): CouldNotProvideSubscriptionCarrierDeliveryPrice { return new self( 'Failed to find order cart', @@ -20,7 +20,7 @@ public static function failedToFindOrderCart(): CouldNotProvideCarrierDeliveryPr ); } - public static function failedToFindOrderCustomer(): CouldNotProvideCarrierDeliveryPrice + public static function failedToFindOrderCustomer(): CouldNotProvideSubscriptionCarrierDeliveryPrice { return new self( 'Failed to find order customer', @@ -28,15 +28,15 @@ public static function failedToFindOrderCustomer(): CouldNotProvideCarrierDelive ); } - public static function failedToApplySelectedCarrierForSubscriptionOrder(): CouldNotProvideCarrierDeliveryPrice + public static function failedToApplySelectedCarrier(): CouldNotProvideSubscriptionCarrierDeliveryPrice { return new self( - 'Failed to apply selected carrier for subscription order', - ExceptionCode::ORDER_FAILED_TO_APPLY_SELECTED_CARRIER_FOR_SUBSCRIPTION_ORDER + 'Failed to apply selected carrier', + ExceptionCode::ORDER_FAILED_TO_APPLY_SELECTED_CARRIER ); } - public static function failedToFindOrderDeliveryAddress(): CouldNotProvideCarrierDeliveryPrice + public static function failedToFindOrderDeliveryAddress(): CouldNotProvideSubscriptionCarrierDeliveryPrice { return new self( 'Failed to find order delivery address', @@ -44,7 +44,7 @@ public static function failedToFindOrderDeliveryAddress(): CouldNotProvideCarrie ); } - public static function failedToFindOrderDeliveryCountry(): CouldNotProvideCarrierDeliveryPrice + public static function failedToFindOrderDeliveryCountry(): CouldNotProvideSubscriptionCarrierDeliveryPrice { return new self( 'Failed to find order delivery country', @@ -52,11 +52,11 @@ public static function failedToFindOrderDeliveryCountry(): CouldNotProvideCarrie ); } - public static function failedToGetSelectedCarrierPriceForSubscriptionOrder(): CouldNotProvideCarrierDeliveryPrice + public static function failedToGetSelectedCarrierPrice(): CouldNotProvideSubscriptionCarrierDeliveryPrice { return new self( - 'Failed to get selected carrier price for subscription order', - ExceptionCode::ORDER_FAILED_TO_GET_SELECTED_CARRIER_PRICE_FOR_SUBSCRIPTION_ORDER + 'Failed to get selected carrier price', + ExceptionCode::ORDER_FAILED_TO_GET_SELECTED_CARRIER_PRICE ); } } diff --git a/subscription/Exception/ExceptionCode.php b/subscription/Exception/ExceptionCode.php index f20f4d025..f2a485c64 100644 --- a/subscription/Exception/ExceptionCode.php +++ b/subscription/Exception/ExceptionCode.php @@ -6,15 +6,13 @@ class ExceptionCode { //Order error codes starts from 1000 - public const ORDER_FAILED_TO_CREATE_ORDER_PAYMENT_FEE = 1001; - public const ORDER_FAILED_TO_UPDATE_ORDER_TOTAL_WITH_PAYMENT_FEE = 1002; - public const ORDER_FAILED_TO_FIND_SELECTED_CARRIER_FOR_SUBSCRIPTION_ORDER = 1003; - public const ORDER_FAILED_TO_FIND_ORDER_CART = 1004; - public const ORDER_FAILED_TO_FIND_ORDER_CUSTOMER = 1005; - public const ORDER_FAILED_TO_APPLY_SELECTED_CARRIER_FOR_SUBSCRIPTION_ORDER = 1006; - public const ORDER_FAILED_TO_FIND_ORDER_DELIVERY_ADDRESS = 1007; - public const ORDER_FAILED_TO_FIND_ORDER_DELIVERY_COUNTRY = 1008; - public const ORDER_FAILED_TO_GET_SELECTED_CARRIER_PRICE_FOR_SUBSCRIPTION_ORDER = 1009; + public const ORDER_FAILED_TO_FIND_SELECTED_CARRIER = 1001; + public const ORDER_FAILED_TO_FIND_ORDER_CART = 1002; + public const ORDER_FAILED_TO_FIND_ORDER_CUSTOMER = 1003; + public const ORDER_FAILED_TO_APPLY_SELECTED_CARRIER = 1004; + public const ORDER_FAILED_TO_FIND_ORDER_DELIVERY_ADDRESS = 1005; + public const ORDER_FAILED_TO_FIND_ORDER_DELIVERY_COUNTRY = 1006; + public const ORDER_FAILED_TO_GET_SELECTED_CARRIER_PRICE = 1007; //Cart error codes starts from 2000 diff --git a/subscription/Factory/CreateSubscriptionDataFactory.php b/subscription/Factory/CreateSubscriptionDataFactory.php index aa58a68f3..fbf63adb7 100644 --- a/subscription/Factory/CreateSubscriptionDataFactory.php +++ b/subscription/Factory/CreateSubscriptionDataFactory.php @@ -10,9 +10,9 @@ use Mollie\Repository\PaymentMethodRepositoryInterface; use Mollie\Subscription\DTO\CreateSubscriptionData as SubscriptionDataDTO; use Mollie\Subscription\DTO\Object\Amount; -use Mollie\Subscription\Exception\CouldNotProvideCarrierDeliveryPrice; +use Mollie\Subscription\Exception\CouldNotProvideSubscriptionCarrierDeliveryPrice; use Mollie\Subscription\Exception\SubscriptionIntervalException; -use Mollie\Subscription\Provider\CarrierDeliveryPriceProvider; +use Mollie\Subscription\Provider\SubscriptionCarrierDeliveryPriceProvider; use Mollie\Subscription\Provider\SubscriptionDescriptionProvider; use Mollie\Subscription\Provider\SubscriptionIntervalProvider; use Mollie\Subscription\Repository\CombinationRepository; @@ -43,8 +43,8 @@ class CreateSubscriptionDataFactory private $module; /** @var Context */ private $context; - /** @var CarrierDeliveryPriceProvider */ - private $carrierDeliveryPriceProvider; + /** @var SubscriptionCarrierDeliveryPriceProvider */ + private $subscriptionCarrierDeliveryPriceProvider; public function __construct( MolCustomerRepository $customerRepository, @@ -55,7 +55,7 @@ public function __construct( PaymentMethodRepositoryInterface $methodRepository, Mollie $module, Context $context, - CarrierDeliveryPriceProvider $carrierDeliveryPriceProvider + SubscriptionCarrierDeliveryPriceProvider $subscriptionCarrierDeliveryPriceProvider ) { $this->customerRepository = $customerRepository; $this->subscriptionInterval = $subscriptionInterval; @@ -65,12 +65,12 @@ public function __construct( $this->methodRepository = $methodRepository; $this->module = $module; $this->context = $context; - $this->carrierDeliveryPriceProvider = $carrierDeliveryPriceProvider; + $this->subscriptionCarrierDeliveryPriceProvider = $subscriptionCarrierDeliveryPriceProvider; } /** * @throws \PrestaShopException - * @throws CouldNotProvideCarrierDeliveryPrice + * @throws CouldNotProvideSubscriptionCarrierDeliveryPrice * @throws SubscriptionIntervalException */ public function build(Order $order, array $subscriptionProduct): SubscriptionDataDTO @@ -87,13 +87,13 @@ public function build(Order $order, array $subscriptionProduct): SubscriptionDat $description = $this->subscriptionDescription->getSubscriptionDescription($order); try { - $deliveryPrice = $this->carrierDeliveryPriceProvider->getPrice( + $deliveryPrice = $this->subscriptionCarrierDeliveryPriceProvider->getPrice( (int) $order->id_address_delivery, (int) $order->id_cart, (int) $order->id_customer, $subscriptionProduct ); - } catch (CouldNotProvideCarrierDeliveryPrice $exception) { + } catch (CouldNotProvideSubscriptionCarrierDeliveryPrice $exception) { // TODO throw generic error when new logger will be implemented throw $exception; } diff --git a/subscription/Provider/CarrierDeliveryPriceProvider.php b/subscription/Provider/SubscriptionCarrierDeliveryPriceProvider.php similarity index 78% rename from subscription/Provider/CarrierDeliveryPriceProvider.php rename to subscription/Provider/SubscriptionCarrierDeliveryPriceProvider.php index f22f794e8..39dd93fbf 100644 --- a/subscription/Provider/CarrierDeliveryPriceProvider.php +++ b/subscription/Provider/SubscriptionCarrierDeliveryPriceProvider.php @@ -9,9 +9,9 @@ use Mollie\Repository\CartRepositoryInterface; use Mollie\Repository\CountryRepositoryInterface; use Mollie\Repository\CustomerRepositoryInterface; -use Mollie\Subscription\Exception\CouldNotProvideCarrierDeliveryPrice; +use Mollie\Subscription\Exception\CouldNotProvideSubscriptionCarrierDeliveryPrice; -class CarrierDeliveryPriceProvider +class SubscriptionCarrierDeliveryPriceProvider { /** @var ConfigurationAdapter */ private $configuration; @@ -43,7 +43,7 @@ public function __construct( } /** - * @throws CouldNotProvideCarrierDeliveryPrice + * @throws CouldNotProvideSubscriptionCarrierDeliveryPrice */ public function getPrice(int $addressDeliveryId, int $cartId, int $customerId, array $subscriptionProduct): float { @@ -52,10 +52,12 @@ public function getPrice(int $addressDeliveryId, int $cartId, int $customerId, a /** @var \Carrier|null $carrier */ $carrier = $this->carrierRepository->findOneBy([ 'id_carrier' => $subscriptionCarrierId, + 'active' => 1, + 'deleted' => 0, ]); if (!$carrier) { - throw CouldNotProvideCarrierDeliveryPrice::failedToFindSelectedCarrierForSubscriptionOrder(); + throw CouldNotProvideSubscriptionCarrierDeliveryPrice::failedToFindSelectedCarrier(); } /** @var \Cart|null $cart */ @@ -64,7 +66,7 @@ public function getPrice(int $addressDeliveryId, int $cartId, int $customerId, a ]); if (!$cart) { - throw CouldNotProvideCarrierDeliveryPrice::failedToFindOrderCart(); + throw CouldNotProvideSubscriptionCarrierDeliveryPrice::failedToFindOrderCart(); } /** @var \Customer|null $customer */ @@ -73,7 +75,7 @@ public function getPrice(int $addressDeliveryId, int $cartId, int $customerId, a ]); if (!$customer) { - throw CouldNotProvideCarrierDeliveryPrice::failedToFindOrderCustomer(); + throw CouldNotProvideSubscriptionCarrierDeliveryPrice::failedToFindOrderCustomer(); } $getAvailableOrderCarriers = $this->carrierRepository->getCarriersForOrder( @@ -83,7 +85,7 @@ public function getPrice(int $addressDeliveryId, int $cartId, int $customerId, a ); if (!in_array($subscriptionCarrierId, array_column($getAvailableOrderCarriers, 'id_carrier'), false)) { - throw CouldNotProvideCarrierDeliveryPrice::failedToApplySelectedCarrierForSubscriptionOrder(); + throw CouldNotProvideSubscriptionCarrierDeliveryPrice::failedToApplySelectedCarrier(); } /** @var \Address|bool $address */ @@ -92,7 +94,7 @@ public function getPrice(int $addressDeliveryId, int $cartId, int $customerId, a ]); if (!$address) { - throw CouldNotProvideCarrierDeliveryPrice::failedToFindOrderDeliveryAddress(); + throw CouldNotProvideSubscriptionCarrierDeliveryPrice::failedToFindOrderDeliveryAddress(); } /** @var \Country|bool $country */ @@ -101,7 +103,7 @@ public function getPrice(int $addressDeliveryId, int $cartId, int $customerId, a ]); if (!$country) { - throw CouldNotProvideCarrierDeliveryPrice::failedToFindOrderDeliveryCountry(); + throw CouldNotProvideSubscriptionCarrierDeliveryPrice::failedToFindOrderDeliveryCountry(); } /** @var float|bool $deliveryPrice */ @@ -114,7 +116,7 @@ public function getPrice(int $addressDeliveryId, int $cartId, int $customerId, a ); if (is_bool($deliveryPrice) && !$deliveryPrice) { - throw CouldNotProvideCarrierDeliveryPrice::failedToGetSelectedCarrierPriceForSubscriptionOrder(); + throw CouldNotProvideSubscriptionCarrierDeliveryPrice::failedToGetSelectedCarrierPrice(); } return (float) $deliveryPrice; diff --git a/tests/Integration/Subscription/Provider/CarrierDeliveryPriceProviderTest.php b/tests/Integration/Subscription/Provider/SubscriptionCarrierDeliveryPriceProviderTest.php similarity index 81% rename from tests/Integration/Subscription/Provider/CarrierDeliveryPriceProviderTest.php rename to tests/Integration/Subscription/Provider/SubscriptionCarrierDeliveryPriceProviderTest.php index bf8e5416c..1a5a890dc 100644 --- a/tests/Integration/Subscription/Provider/CarrierDeliveryPriceProviderTest.php +++ b/tests/Integration/Subscription/Provider/SubscriptionCarrierDeliveryPriceProviderTest.php @@ -4,16 +4,16 @@ use Mollie\Adapter\ConfigurationAdapter; use Mollie\Config\Config; -use Mollie\Subscription\Exception\CouldNotProvideCarrierDeliveryPrice; +use Mollie\Subscription\Exception\CouldNotProvideSubscriptionCarrierDeliveryPrice; use Mollie\Subscription\Exception\ExceptionCode; -use Mollie\Subscription\Provider\CarrierDeliveryPriceProvider; +use Mollie\Subscription\Provider\SubscriptionCarrierDeliveryPriceProvider; use Mollie\Tests\Integration\BaseTestCase; use Mollie\Tests\Integration\Factory\AddressFactory; use Mollie\Tests\Integration\Factory\CarrierFactory; use Mollie\Tests\Integration\Factory\CartFactory; use Mollie\Tests\Integration\Factory\ProductFactory; -class CarrierDeliveryPriceProviderTest extends BaseTestCase +class SubscriptionCarrierDeliveryPriceProviderTest extends BaseTestCase { public function setUp(): void { @@ -67,10 +67,10 @@ public function testItSuccessfullyProvidesCarrierDeliveryPrice(): void $cart->updateQty(2, $product1->id); $cart->updateQty(3, $product2->id); - /** @var CarrierDeliveryPriceProvider $carrierDeliveryPriceProvider */ - $carrierDeliveryPriceProvider = $this->getService(CarrierDeliveryPriceProvider::class); + /** @var SubscriptionCarrierDeliveryPriceProvider $subscriptionCarrierDeliveryPriceProvider */ + $subscriptionCarrierDeliveryPriceProvider = $this->getService(SubscriptionCarrierDeliveryPriceProvider::class); - $result = $carrierDeliveryPriceProvider->getPrice( + $result = $subscriptionCarrierDeliveryPriceProvider->getPrice( $address->id, $cart->id, $cart->id_customer, @@ -124,13 +124,13 @@ public function testItUnsuccessfullyProvidesCarrierDeliveryPriceCarrierIsOutOfZo $cart->updateQty(2, $product1->id); $cart->updateQty(3, $product2->id); - $this->expectException(CouldNotProvideCarrierDeliveryPrice::class); - $this->expectExceptionCode(ExceptionCode::ORDER_FAILED_TO_APPLY_SELECTED_CARRIER_FOR_SUBSCRIPTION_ORDER); + $this->expectException(CouldNotProvideSubscriptionCarrierDeliveryPrice::class); + $this->expectExceptionCode(ExceptionCode::ORDER_FAILED_TO_APPLY_SELECTED_CARRIER); - /** @var CarrierDeliveryPriceProvider $carrierDeliveryPriceProvider */ - $carrierDeliveryPriceProvider = $this->getService(CarrierDeliveryPriceProvider::class); + /** @var SubscriptionCarrierDeliveryPriceProvider $subscriptionCarrierDeliveryPriceProvider */ + $subscriptionCarrierDeliveryPriceProvider = $this->getService(SubscriptionCarrierDeliveryPriceProvider::class); - $carrierDeliveryPriceProvider->getPrice( + $subscriptionCarrierDeliveryPriceProvider->getPrice( $address->id, $cart->id, $cart->id_customer,