From 8b087f8f82c97f43acb0b37f34f5afc9c13c730a Mon Sep 17 00:00:00 2001 From: mandan2 Date: Tue, 24 Oct 2023 17:54:02 +0300 Subject: [PATCH 1/3] PIPRES-352: Billie payment method setup --- src/Builder/FormBuilder.php | 12 +-- src/Config/Config.php | 26 ++--- .../ApplePayDirectCertificateHandler.php | 5 +- src/Handler/Order/OrderCreationHandler.php | 4 +- src/Install/OrderStateInstaller.php | 10 +- src/Presenter/OrderListActionBuilder.php | 5 +- .../BancontactPaymentOptionProvider.php | 5 +- .../BasePaymentOptionProvider.php | 5 +- .../CreditCardPaymentOptionProvider.php | 5 +- ...itCardSingleClickPaymentOptionProvider.php | 5 +- .../IdealPaymentOptionProvider.php | 5 +- src/Service/ConfigFieldService.php | 98 ++++++++++--------- src/Service/CustomerService.php | 5 +- src/Service/OrderStatusService.php | 2 +- src/Service/SettingsSaveService.php | 40 ++++---- src/Service/TransactionService.php | 35 ++++--- src/Validator/OrderConfMailValidator.php | 2 +- .../Install/OrderStateInstallerTest.php | 4 +- upgrade/Upgrade-4.2.0.php | 12 +-- upgrade/Upgrade-5.4.3.php | 79 +++++++++++++++ views/templates/admin/invoice_description.tpl | 4 +- 21 files changed, 236 insertions(+), 132 deletions(-) diff --git a/src/Builder/FormBuilder.php b/src/Builder/FormBuilder.php index 5414a6a63..cc660f0fc 100644 --- a/src/Builder/FormBuilder.php +++ b/src/Builder/FormBuilder.php @@ -406,8 +406,6 @@ protected function getAccountSettingsSection($isApiKeyProvided) 'customLogoUrl' => $this->creditCardLogoProvider->getLogoPathUri() . "?{$dateStamp}", 'customLogoExist' => $this->creditCardLogoProvider->logoExists(), 'voucherCategory' => $this->configurationAdapter->get(Config::MOLLIE_VOUCHER_CATEGORY), - 'klarnaPayments' => Config::KLARNA_PAYMENTS, - 'klarnaStatuses' => [Config::MOLLIE_STATUS_KLARNA_AUTHORIZED, Config::MOLLIE_STATUS_KLARNA_SHIPPED], 'applePayDirectProduct' => (int) $this->configurationAdapter->get(Config::MOLLIE_APPLE_PAY_DIRECT_PRODUCT), 'applePayDirectCart' => (int) $this->configurationAdapter->get(Config::MOLLIE_APPLE_PAY_DIRECT_CART), 'applePayDirectStyle' => (int) $this->configurationAdapter->get(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE), @@ -481,22 +479,22 @@ protected function getAdvancedSettingsSection() $input[] = [ 'type' => 'select', - 'label' => $this->module->l('Select when to create the Klarna invoice', self::FILE_NAME), + 'label' => $this->module->l('Select when to create the Order invoice', self::FILE_NAME), 'desc' => $this->module->display($this->module->getPathUri(), 'views/templates/admin/invoice_description.tpl'), 'tab' => $advancedSettings, - 'name' => Config::MOLLIE_KLARNA_INVOICE_ON, + 'name' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, 'options' => [ 'query' => [ [ - 'id' => Config::MOLLIE_STATUS_DEFAULT, + 'id' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT, 'name' => $this->module->l('Default', self::FILE_NAME), ], [ - 'id' => Config::MOLLIE_STATUS_KLARNA_AUTHORIZED, + 'id' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED, 'name' => $this->module->l('Authorised', self::FILE_NAME), ], [ - 'id' => Config::MOLLIE_STATUS_KLARNA_SHIPPED, + 'id' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED, 'name' => $this->module->l('Shipped', self::FILE_NAME), ], ], diff --git a/src/Config/Config.php b/src/Config/Config.php index 2d04d8844..3756672de 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -144,11 +144,11 @@ class Config const MOLLIE_STATUS_INITIATED = 'MOLLIE_STATUS_INITIATED'; const MOLLIE_STATUS_PARTIALLY_SHIPPED = 'MOLLIE_PARTIALLY_SHIPPED'; const MOLLIE_STATUS_ORDER_COMPLETED = 'MOLLIE_STATUS_ORDER_COMPLETED'; - const MOLLIE_STATUS_DEFAULT = 'MOLLIE_STATUS_DEFAULT'; - const MOLLIE_STATUS_KLARNA_AUTHORIZED = 'MOLLIE_STATUS_KLARNA_AUTHORIZED'; - const MOLLIE_STATUS_KLARNA_SHIPPED = 'MOLLIE_STATUS_KLARNA_SHIPPED'; + const MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT = 'MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT'; + const MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED = 'MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED'; + const MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED = 'MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED'; const MOLLIE_STATUS_CHARGEBACK = 'MOLLIE_STATUS_CHARGEBACK'; - const MOLLIE_KLARNA_INVOICE_ON = 'MOLLIE_KLARNA_INVOICE_ON'; + const MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS = 'MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS'; const MOLLIE_APPLE_PAY_DIRECT_PRODUCT = 'MOLLIE_APPLE_PAY_DIRECT_PRODUCT'; const MOLLIE_APPLE_PAY_DIRECT_CART = 'MOLLIE_APPLE_PAY_DIRECT_CART'; @@ -262,16 +262,18 @@ class Config const RESTORE_CART_BACKTRACE_MEMORIZATION_SERVICE = 'memo'; const RESTORE_CART_BACKTRACE_RETURN_CONTROLLER = 'return'; - const KLARNA_PAYMENTS = [ + const AUTHORIZABLE_PAYMENTS = [ PaymentMethod::KLARNA_PAY_LATER, PaymentMethod::KLARNA_SLICE_IT, PaymentMethod::KLARNA_PAY_NOW, + self::MOLLIE_PAYMENT_METHOD_BILLIE, ]; const ORDER_API_ONLY_METHODS = [ PaymentMethod::KLARNA_PAY_LATER, PaymentMethod::KLARNA_SLICE_IT, PaymentMethod::KLARNA_PAY_NOW, + self::MOLLIE_PAYMENT_METHOD_BILLIE, self::MOLLIE_VOUCHER_METHOD_ID, self::MOLLIE_in3_METHOD_ID, ]; @@ -309,6 +311,7 @@ class Config 'voucher' => 'Voucher', 'klarnapaynow' => 'Klarna Pay now.', 'in3' => 'in3', + 'billie' => 'Billie', ]; const MOLLIE_BUTTON_ORDER_TOTAL_REFRESH = 'MOLLIE_BUTTON_ORDER_TOTAL_REFRESH'; @@ -318,14 +321,15 @@ class Config public static function getStatuses() { - $isKlarnaDefault = Configuration::get(Config::MOLLIE_KLARNA_INVOICE_ON) === Config::MOLLIE_STATUS_DEFAULT; + $isAuthorizablePaymentInvoiceOnStatusDefault = + Configuration::get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS) === Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT; return [ self::MOLLIE_AWAITING_PAYMENT => Configuration::get(self::MOLLIE_STATUS_AWAITING), PaymentStatus::STATUS_PAID => Configuration::get(self::MOLLIE_STATUS_PAID), OrderStatus::STATUS_COMPLETED => Configuration::get(self::MOLLIE_STATUS_COMPLETED), - PaymentStatus::STATUS_AUTHORIZED => $isKlarnaDefault ? - Configuration::get(self::MOLLIE_STATUS_PAID) : Configuration::get(self::MOLLIE_STATUS_KLARNA_AUTHORIZED), + PaymentStatus::STATUS_AUTHORIZED => $isAuthorizablePaymentInvoiceOnStatusDefault ? + Configuration::get(self::MOLLIE_STATUS_PAID) : Configuration::get(self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED), PaymentStatus::STATUS_CANCELED => Configuration::get(self::MOLLIE_STATUS_CANCELED), PaymentStatus::STATUS_EXPIRED => Configuration::get(self::MOLLIE_STATUS_EXPIRED), RefundStatus::STATUS_REFUNDED => Configuration::get(self::MOLLIE_STATUS_REFUNDED), @@ -338,7 +342,7 @@ public static function getStatuses() self::STATUS_PAID_ON_BACKORDER => Configuration::get('PS_OS_OUTOFSTOCK_PAID'), self::STATUS_PENDING_ON_BACKORDER => Configuration::get('PS_OS_OUTOFSTOCK_UNPAID'), self::STATUS_ON_BACKORDER => Configuration::get('PS_OS_OUTOFSTOCK'), - self::MOLLIE_STATUS_KLARNA_SHIPPED => Configuration::get(self::MOLLIE_STATUS_KLARNA_SHIPPED), + self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED => Configuration::get(self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED), self::MOLLIE_CHARGEBACK => Configuration::get(self::MOLLIE_STATUS_CHARGEBACK), ]; } @@ -360,8 +364,8 @@ public static function getMollieOrderStatuses() self::MOLLIE_STATUS_PARTIAL_REFUND, self::MOLLIE_STATUS_AWAITING, self::MOLLIE_STATUS_ORDER_COMPLETED, - self::MOLLIE_STATUS_KLARNA_AUTHORIZED, - self::MOLLIE_STATUS_KLARNA_SHIPPED, + self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED, + self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED, self::MOLLIE_STATUS_CHARGEBACK, ]; } diff --git a/src/Handler/Certificate/ApplePayDirectCertificateHandler.php b/src/Handler/Certificate/ApplePayDirectCertificateHandler.php index bf871b219..56bccab30 100644 --- a/src/Handler/Certificate/ApplePayDirectCertificateHandler.php +++ b/src/Handler/Certificate/ApplePayDirectCertificateHandler.php @@ -13,6 +13,7 @@ namespace Mollie\Handler\Certificate; use Mollie; +use Mollie\Factory\ModuleFactory; use Mollie\Handler\Certificate\Exception\ApplePayDirectCertificateCreation; use Mollie\Utility\FileUtility; @@ -30,9 +31,9 @@ class ApplePayDirectCertificateHandler implements CertificateHandlerInterface private $mollie; private $serverRoot; - public function __construct(Mollie $mollie) + public function __construct(ModuleFactory $moduleFactory) { - $this->mollie = $mollie; + $this->mollie = $moduleFactory->getModule(); $this->serverRoot = $_SERVER['DOCUMENT_ROOT']; } diff --git a/src/Handler/Order/OrderCreationHandler.php b/src/Handler/Order/OrderCreationHandler.php index 0770682ac..b22b85574 100644 --- a/src/Handler/Order/OrderCreationHandler.php +++ b/src/Handler/Order/OrderCreationHandler.php @@ -99,9 +99,9 @@ public function __construct( * * @throws \Exception */ - public function createOrder($apiPayment, int $cartId, bool $isKlarnaOrder = false): int + public function createOrder($apiPayment, int $cartId, bool $isAuthorizablePayment = false): int { - $orderStatus = $isKlarnaOrder ? + $orderStatus = $isAuthorizablePayment ? (int) Config::getStatuses()[PaymentStatus::STATUS_AUTHORIZED] : (int) Config::getStatuses()[PaymentStatus::STATUS_PAID]; diff --git a/src/Install/OrderStateInstaller.php b/src/Install/OrderStateInstaller.php index 9a07dcac7..d2bfb9a5e 100644 --- a/src/Install/OrderStateInstaller.php +++ b/src/Install/OrderStateInstaller.php @@ -33,7 +33,7 @@ public function __construct( /** * @throws CouldNotInstallModule */ - public function install() + public function install(): bool { $this->installOrderState( Config::MOLLIE_STATUS_PARTIAL_REFUND, @@ -69,9 +69,9 @@ public function install() ); $this->installOrderState( - Config::MOLLIE_STATUS_KLARNA_AUTHORIZED, + Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED, new OrderStateData( - 'Klarna payment authorized', + 'Order payment authorized', '#8A2BE2', true, true, @@ -85,9 +85,9 @@ public function install() ); $this->installOrderState( - Config::MOLLIE_STATUS_KLARNA_SHIPPED, + Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED, new OrderStateData( - 'Klarna payment shipped', + 'Order payment shipped', '#8A2BE2', true, true, diff --git a/src/Presenter/OrderListActionBuilder.php b/src/Presenter/OrderListActionBuilder.php index 5e2f476ca..8d6543711 100644 --- a/src/Presenter/OrderListActionBuilder.php +++ b/src/Presenter/OrderListActionBuilder.php @@ -13,6 +13,7 @@ namespace Mollie\Presenter; use Mollie; +use Mollie\Factory\ModuleFactory; use Smarty_Data; class OrderListActionBuilder @@ -23,9 +24,9 @@ class OrderListActionBuilder */ private $mollie; - public function __construct(Mollie $mollie) + public function __construct(ModuleFactory $moduleFactory) { - $this->mollie = $mollie; + $this->mollie = $moduleFactory->getModule(); } public function buildOrderPaymentResendButton(Smarty_Data $smarty, $orderId) diff --git a/src/Provider/PaymentOption/BancontactPaymentOptionProvider.php b/src/Provider/PaymentOption/BancontactPaymentOptionProvider.php index 6bfec0ce4..0ce649bd4 100644 --- a/src/Provider/PaymentOption/BancontactPaymentOptionProvider.php +++ b/src/Provider/PaymentOption/BancontactPaymentOptionProvider.php @@ -39,6 +39,7 @@ use Mollie; use Mollie\Adapter\Context; use Mollie\Api\Types\PaymentMethod; +use Mollie\Factory\ModuleFactory; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; @@ -79,14 +80,14 @@ class BancontactPaymentOptionProvider implements PaymentOptionProviderInterface private $orderTotalProvider; public function __construct( - Mollie $module, + ModuleFactory $moduleFactory, Context $context, CreditCardLogoProvider $creditCardLogoProvider, PaymentFeeProviderInterface $paymentFeeProvider, LanguageService $languageService, OrderTotalProviderInterface $orderTotalProvider ) { - $this->module = $module; + $this->module = $moduleFactory->getModule(); $this->context = $context; $this->creditCardLogoProvider = $creditCardLogoProvider; $this->paymentFeeProvider = $paymentFeeProvider; diff --git a/src/Provider/PaymentOption/BasePaymentOptionProvider.php b/src/Provider/PaymentOption/BasePaymentOptionProvider.php index 2296d821b..1d40c86bf 100644 --- a/src/Provider/PaymentOption/BasePaymentOptionProvider.php +++ b/src/Provider/PaymentOption/BasePaymentOptionProvider.php @@ -38,6 +38,7 @@ use Mollie; use Mollie\Adapter\Context; +use Mollie\Factory\ModuleFactory; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; @@ -78,14 +79,14 @@ class BasePaymentOptionProvider implements PaymentOptionProviderInterface private $orderTotalProvider; public function __construct( - Mollie $module, + ModuleFactory $moduleFactory, Context $context, CreditCardLogoProvider $creditCardLogoProvider, PaymentFeeProviderInterface $paymentFeeProvider, LanguageService $languageService, OrderTotalProviderInterface $orderTotalProvider ) { - $this->module = $module; + $this->module = $moduleFactory->getModule(); $this->context = $context; $this->creditCardLogoProvider = $creditCardLogoProvider; $this->paymentFeeProvider = $paymentFeeProvider; diff --git a/src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php b/src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php index 238ea2c21..017c2a079 100644 --- a/src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php +++ b/src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php @@ -41,6 +41,7 @@ use Mollie\Adapter\ConfigurationAdapter; use Mollie\Adapter\Context; use Mollie\Config\Config; +use Mollie\Factory\ModuleFactory; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; @@ -92,7 +93,7 @@ class CreditCardPaymentOptionProvider implements PaymentOptionProviderInterface private $configurationAdapter; public function __construct( - Mollie $module, + ModuleFactory $moduleFactory, Context $context, CreditCardLogoProvider $creditCardLogoProvider, OrderTotalProviderInterface $orderTotalProvider, @@ -101,7 +102,7 @@ public function __construct( MolCustomerRepository $customerRepository, ConfigurationAdapter $configurationAdapter ) { - $this->module = $module; + $this->module = $moduleFactory->getModule(); $this->context = $context; $this->creditCardLogoProvider = $creditCardLogoProvider; $this->orderTotalProvider = $orderTotalProvider; diff --git a/src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php b/src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php index 87eb54593..f508df453 100644 --- a/src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php +++ b/src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php @@ -41,6 +41,7 @@ use Mollie\Adapter\ConfigurationAdapter; use Mollie\Adapter\Context; use Mollie\Config\Config; +use Mollie\Factory\ModuleFactory; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; @@ -92,7 +93,7 @@ class CreditCardSingleClickPaymentOptionProvider implements PaymentOptionProvide private $configurationAdapter; public function __construct( - Mollie $module, + ModuleFactory $moduleFactory, Context $context, CreditCardLogoProvider $creditCardLogoProvider, OrderTotalProviderInterface $orderTotalProvider, @@ -101,7 +102,7 @@ public function __construct( MolCustomerRepository $customerRepository, ConfigurationAdapter $configurationAdapter ) { - $this->module = $module; + $this->module = $moduleFactory->getModule(); $this->context = $context; $this->creditCardLogoProvider = $creditCardLogoProvider; $this->orderTotalProvider = $orderTotalProvider; diff --git a/src/Provider/PaymentOption/IdealPaymentOptionProvider.php b/src/Provider/PaymentOption/IdealPaymentOptionProvider.php index e73f4b2f2..d1ed01dd7 100644 --- a/src/Provider/PaymentOption/IdealPaymentOptionProvider.php +++ b/src/Provider/PaymentOption/IdealPaymentOptionProvider.php @@ -39,6 +39,7 @@ use Mollie; use Mollie\Adapter\Context; use Mollie\Builder\Content\PaymentOption\IdealDropdownInfoBlock; +use Mollie\Factory\ModuleFactory; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; @@ -90,7 +91,7 @@ class IdealPaymentOptionProvider implements PaymentOptionProviderInterface private $orderTotalProvider; public function __construct( - Mollie $module, + ModuleFactory $moduleFactory, Context $context, CreditCardLogoProvider $creditCardLogoProvider, PaymentFeeProviderInterface $paymentFeeProvider, @@ -99,7 +100,7 @@ public function __construct( LanguageService $languageService, OrderTotalProviderInterface $orderTotalProvider ) { - $this->module = $module; + $this->module = $moduleFactory->getModule(); $this->context = $context; $this->creditCardLogoProvider = $creditCardLogoProvider; $this->paymentFeeProvider = $paymentFeeProvider; diff --git a/src/Service/ConfigFieldService.php b/src/Service/ConfigFieldService.php index 96bc13206..306a5951f 100644 --- a/src/Service/ConfigFieldService.php +++ b/src/Service/ConfigFieldService.php @@ -12,12 +12,12 @@ namespace Mollie\Service; -use Configuration; use Mollie; use Mollie\Adapter\ConfigurationAdapter; use Mollie\Config\Config; use Mollie\Factory\ModuleFactory; use Mollie\Repository\CountryRepository; +use Mollie\Utility\EnvironmentUtility; class ConfigFieldService { @@ -54,67 +54,71 @@ public function __construct( public function getConfigFieldsValues() { $configFields = [ - Config::MOLLIE_ENVIRONMENT => Configuration::get(Config::MOLLIE_ENVIRONMENT), - Config::MOLLIE_API_KEY => Configuration::get(Config::MOLLIE_API_KEY), - Config::MOLLIE_API_KEY_TEST => Configuration::get(Config::MOLLIE_API_KEY_TEST), - Config::MOLLIE_PAYMENTSCREEN_LOCALE => Configuration::get(Config::MOLLIE_PAYMENTSCREEN_LOCALE), - Config::MOLLIE_SEND_ORDER_CONFIRMATION => Configuration::get(Config::MOLLIE_SEND_ORDER_CONFIRMATION), + Config::MOLLIE_ENVIRONMENT => $this->configurationAdapter->get(Config::MOLLIE_ENVIRONMENT), + Config::MOLLIE_API_KEY => $this->configurationAdapter->get(Config::MOLLIE_API_KEY), + Config::MOLLIE_API_KEY_TEST => $this->configurationAdapter->get(Config::MOLLIE_API_KEY_TEST), + Config::MOLLIE_PAYMENTSCREEN_LOCALE => $this->configurationAdapter->get(Config::MOLLIE_PAYMENTSCREEN_LOCALE), + Config::MOLLIE_SEND_ORDER_CONFIRMATION => $this->configurationAdapter->get(Config::MOLLIE_SEND_ORDER_CONFIRMATION), Config::MOLLIE_IFRAME[(int) $this->configurationAdapter->get(Config::MOLLIE_ENVIRONMENT) ? 'production' : 'sandbox'] => $this->configurationAdapter->get(Config::MOLLIE_IFRAME), Config::MOLLIE_SINGLE_CLICK_PAYMENT[(int) $this->configurationAdapter->get(Config::MOLLIE_ENVIRONMENT) ? 'production' : 'sandbox'] => $this->configurationAdapter->get(Config::MOLLIE_SINGLE_CLICK_PAYMENT), - Config::MOLLIE_CSS => Configuration::get(Config::MOLLIE_CSS), - Config::MOLLIE_IMAGES => Configuration::get(Config::MOLLIE_IMAGES), - Config::MOLLIE_SHOW_RESEND_PAYMENT_LINK => Configuration::get(Config::MOLLIE_SHOW_RESEND_PAYMENT_LINK), + Config::MOLLIE_CSS => $this->configurationAdapter->get(Config::MOLLIE_CSS), + Config::MOLLIE_IMAGES => $this->configurationAdapter->get(Config::MOLLIE_IMAGES), + Config::MOLLIE_SHOW_RESEND_PAYMENT_LINK => $this->configurationAdapter->get(Config::MOLLIE_SHOW_RESEND_PAYMENT_LINK), Config::MOLLIE_ISSUERS[(int) $this->configurationAdapter->get(Config::MOLLIE_ENVIRONMENT) ? 'production' : 'sandbox'] => $this->configurationAdapter->get(Config::MOLLIE_ISSUERS), - Config::MOLLIE_METHOD_COUNTRIES => Configuration::get(Config::MOLLIE_METHOD_COUNTRIES), - Config::MOLLIE_METHOD_COUNTRIES_DISPLAY => Configuration::get(Config::MOLLIE_METHOD_COUNTRIES_DISPLAY), - - Config::MOLLIE_STATUS_OPEN => Configuration::get(Config::MOLLIE_STATUS_OPEN), - Config::MOLLIE_STATUS_AWAITING => Configuration::get(Config::MOLLIE_STATUS_AWAITING), - Config::MOLLIE_STATUS_PAID => Configuration::get(Config::MOLLIE_STATUS_PAID), - Config::MOLLIE_STATUS_COMPLETED => Configuration::get(Config::MOLLIE_STATUS_COMPLETED), - Config::MOLLIE_STATUS_CANCELED => Configuration::get(Config::MOLLIE_STATUS_CANCELED), - Config::MOLLIE_STATUS_EXPIRED => Configuration::get(Config::MOLLIE_STATUS_EXPIRED), - Config::MOLLIE_STATUS_PARTIAL_REFUND => Configuration::get(Config::MOLLIE_STATUS_PARTIAL_REFUND), - Config::MOLLIE_STATUS_REFUNDED => Configuration::get(Config::MOLLIE_STATUS_REFUNDED), - Config::MOLLIE_STATUS_CHARGEBACK => Configuration::get(Config::MOLLIE_STATUS_CHARGEBACK), - Config::MOLLIE_MAIL_WHEN_OPEN => Configuration::get(Config::MOLLIE_MAIL_WHEN_OPEN), - Config::MOLLIE_MAIL_WHEN_AWAITING => Configuration::get(Config::MOLLIE_MAIL_WHEN_AWAITING), - Config::MOLLIE_MAIL_WHEN_PAID => Configuration::get(Config::MOLLIE_MAIL_WHEN_PAID), - Config::MOLLIE_MAIL_WHEN_COMPLETED => Configuration::get(Config::MOLLIE_MAIL_WHEN_COMPLETED), - Config::MOLLIE_MAIL_WHEN_CANCELED => Configuration::get(Config::MOLLIE_MAIL_WHEN_CANCELED), - Config::MOLLIE_MAIL_WHEN_EXPIRED => Configuration::get(Config::MOLLIE_MAIL_WHEN_EXPIRED), - Config::MOLLIE_MAIL_WHEN_REFUNDED => Configuration::get(Config::MOLLIE_MAIL_WHEN_REFUNDED), - Config::MOLLIE_MAIL_WHEN_CHARGEBACK => Configuration::get(Config::MOLLIE_MAIL_WHEN_CHARGEBACK), - Config::MOLLIE_ACCOUNT_SWITCH => Configuration::get(Config::MOLLIE_ACCOUNT_SWITCH), - - Config::MOLLIE_DISPLAY_ERRORS => Configuration::get(Config::MOLLIE_DISPLAY_ERRORS), - Config::MOLLIE_DEBUG_LOG => Configuration::get(Config::MOLLIE_DEBUG_LOG), - Config::MOLLIE_API => Configuration::get(Config::MOLLIE_API), - - Config::MOLLIE_AUTO_SHIP_MAIN => Configuration::get(Config::MOLLIE_AUTO_SHIP_MAIN), - - Config::MOLLIE_STATUS_SHIPPING => Configuration::get(Config::MOLLIE_STATUS_SHIPPING), - Config::MOLLIE_MAIL_WHEN_SHIPPING => Configuration::get(Config::MOLLIE_MAIL_WHEN_SHIPPING), - Config::MOLLIE_KLARNA_INVOICE_ON => Configuration::get(Config::MOLLIE_KLARNA_INVOICE_ON), + Config::MOLLIE_METHOD_COUNTRIES => $this->configurationAdapter->get(Config::MOLLIE_METHOD_COUNTRIES), + Config::MOLLIE_METHOD_COUNTRIES_DISPLAY => $this->configurationAdapter->get(Config::MOLLIE_METHOD_COUNTRIES_DISPLAY), + + Config::MOLLIE_STATUS_OPEN => $this->configurationAdapter->get(Config::MOLLIE_STATUS_OPEN), + Config::MOLLIE_STATUS_AWAITING => $this->configurationAdapter->get(Config::MOLLIE_STATUS_AWAITING), + Config::MOLLIE_STATUS_PAID => $this->configurationAdapter->get(Config::MOLLIE_STATUS_PAID), + Config::MOLLIE_STATUS_COMPLETED => $this->configurationAdapter->get(Config::MOLLIE_STATUS_COMPLETED), + Config::MOLLIE_STATUS_CANCELED => $this->configurationAdapter->get(Config::MOLLIE_STATUS_CANCELED), + Config::MOLLIE_STATUS_EXPIRED => $this->configurationAdapter->get(Config::MOLLIE_STATUS_EXPIRED), + Config::MOLLIE_STATUS_PARTIAL_REFUND => $this->configurationAdapter->get(Config::MOLLIE_STATUS_PARTIAL_REFUND), + Config::MOLLIE_STATUS_REFUNDED => $this->configurationAdapter->get(Config::MOLLIE_STATUS_REFUNDED), + Config::MOLLIE_STATUS_CHARGEBACK => $this->configurationAdapter->get(Config::MOLLIE_STATUS_CHARGEBACK), + Config::MOLLIE_MAIL_WHEN_OPEN => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_OPEN), + Config::MOLLIE_MAIL_WHEN_AWAITING => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_AWAITING), + Config::MOLLIE_MAIL_WHEN_PAID => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_PAID), + Config::MOLLIE_MAIL_WHEN_COMPLETED => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_COMPLETED), + Config::MOLLIE_MAIL_WHEN_CANCELED => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_CANCELED), + Config::MOLLIE_MAIL_WHEN_EXPIRED => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_EXPIRED), + Config::MOLLIE_MAIL_WHEN_REFUNDED => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_REFUNDED), + Config::MOLLIE_MAIL_WHEN_CHARGEBACK => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_CHARGEBACK), + Config::MOLLIE_ACCOUNT_SWITCH => $this->configurationAdapter->get(Config::MOLLIE_ACCOUNT_SWITCH), + + Config::MOLLIE_DISPLAY_ERRORS => $this->configurationAdapter->get(Config::MOLLIE_DISPLAY_ERRORS), + Config::MOLLIE_DEBUG_LOG => $this->configurationAdapter->get(Config::MOLLIE_DEBUG_LOG), + Config::MOLLIE_API => $this->configurationAdapter->get(Config::MOLLIE_API), + + Config::MOLLIE_AUTO_SHIP_MAIN => $this->configurationAdapter->get(Config::MOLLIE_AUTO_SHIP_MAIN), + + Config::MOLLIE_STATUS_SHIPPING => $this->configurationAdapter->get(Config::MOLLIE_STATUS_SHIPPING), + Config::MOLLIE_MAIL_WHEN_SHIPPING => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_SHIPPING), + Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS => $this->configurationAdapter->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS), ]; - if (Mollie\Utility\EnvironmentUtility::getApiKey() && $this->module->getApiClient() !== null) { + if (EnvironmentUtility::getApiKey() && $this->module->getApiClient() !== null) { foreach ($this->apiService->getMethodsForConfig($this->module->getApiClient()) as $method) { $countryIds = $this->countryRepository->getMethodCountryIds($method['id']); + if ($countryIds) { - $configFields = array_merge($configFields, [Config::MOLLIE_COUNTRIES . $method['id'] . '[]' => $countryIds]); + $configFields[Config::MOLLIE_COUNTRIES . $method['id'] . '[]'] = $countryIds; + continue; } - $configFields = array_merge($configFields, [Config::MOLLIE_COUNTRIES . $method['id'] . '[]' => []]); + + $configFields[Config::MOLLIE_COUNTRIES . $method['id'] . '[]'] = []; } } $checkStatuses = []; - if (Configuration::get(Config::MOLLIE_AUTO_SHIP_STATUSES)) { - $checkConfs = @json_decode(Configuration::get(Config::MOLLIE_AUTO_SHIP_STATUSES), true); + if ($this->configurationAdapter->get(Config::MOLLIE_AUTO_SHIP_STATUSES)) { + $checkConfs = @json_decode($this->configurationAdapter->get(Config::MOLLIE_AUTO_SHIP_STATUSES), true); } + if (!isset($checkConfs) || !is_array($checkConfs)) { $checkConfs = []; } @@ -123,8 +127,6 @@ public function getConfigFieldsValues() $checkStatuses[Config::MOLLIE_AUTO_SHIP_STATUSES . '_' . (int) $conf] = true; } - $configFields = array_merge($configFields, $checkStatuses); - - return $configFields; + return array_merge($configFields, $checkStatuses); } } diff --git a/src/Service/CustomerService.php b/src/Service/CustomerService.php index 73bd4c4d9..0ecb0bbab 100644 --- a/src/Service/CustomerService.php +++ b/src/Service/CustomerService.php @@ -16,6 +16,7 @@ use Mollie; use Mollie\Config\Config; use Mollie\Exception\MollieException; +use Mollie\Factory\ModuleFactory; use Mollie\Repository\MolCustomerRepository; use Mollie\Utility\CustomerUtility; @@ -31,9 +32,9 @@ class CustomerService */ private $customerRepository; - public function __construct(Mollie $mollie, MolCustomerRepository $customerRepository) + public function __construct(ModuleFactory $moduleFactory, MolCustomerRepository $customerRepository) { - $this->mollie = $mollie; + $this->mollie = $moduleFactory->getModule(); $this->customerRepository = $customerRepository; } diff --git a/src/Service/OrderStatusService.php b/src/Service/OrderStatusService.php index 1d4c26d0e..33c1ea8d1 100644 --- a/src/Service/OrderStatusService.php +++ b/src/Service/OrderStatusService.php @@ -157,6 +157,6 @@ private function isStatusPaid($statusId) { return ((int) $statusId === (int) Configuration::get(Config::MOLLIE_STATUS_PAID)) || ((int) $statusId === (int) Configuration::get(Config::STATUS_PS_OS_OUTOFSTOCK_PAID)) || - ((int) $statusId === (int) Configuration::get(Config::MOLLIE_STATUS_KLARNA_AUTHORIZED)); + ((int) $statusId === (int) Configuration::get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED)); } } diff --git a/src/Service/SettingsSaveService.php b/src/Service/SettingsSaveService.php index 9e722021c..f6dea8868 100644 --- a/src/Service/SettingsSaveService.php +++ b/src/Service/SettingsSaveService.php @@ -13,7 +13,6 @@ namespace Mollie\Service; use Carrier; -use Configuration; use Exception; use Mollie; use Mollie\Adapter\ConfigurationAdapter; @@ -126,7 +125,7 @@ public function __construct( */ public function saveSettings(&$errors = []) { - $oldEnvironment = (int) Configuration::get(Config::MOLLIE_ENVIRONMENT); + $oldEnvironment = (int) $this->configurationAdapter->get(Config::MOLLIE_ENVIRONMENT); $environment = (int) Tools::getValue(Config::MOLLIE_ENVIRONMENT); $mollieApiKey = Tools::getValue(Config::MOLLIE_API_KEY); $mollieApiKeyTest = Tools::getValue(Config::MOLLIE_API_KEY_TEST); @@ -281,9 +280,9 @@ public function saveSettings(&$errors = []) } } try { - $this->handleKlarnaInvoiceStatus(); + $this->handleAuthorizablePaymentInvoiceStatus(); } catch (Exception $e) { - $errors[] = $this->module->l('There are issues with your Klarna statuses, please try resetting Mollie module.', self::FILE_NAME); + $errors[] = $this->module->l('There are issues with your authorizable payment statuses, please try resetting Mollie module.', self::FILE_NAME); } if (empty($errors)) { @@ -384,30 +383,33 @@ private function getStatusesValue($key) return $statesEnabled; } - private function handleKlarnaInvoiceStatus() + private function handleAuthorizablePaymentInvoiceStatus() { - $klarnaInvoiceStatus = Tools::getValue(Config::MOLLIE_KLARNA_INVOICE_ON); - $this->configurationAdapter->updateValue(Config::MOLLIE_KLARNA_INVOICE_ON, $klarnaInvoiceStatus); - if (Config::MOLLIE_STATUS_KLARNA_SHIPPED === $klarnaInvoiceStatus) { - $this->updateKlarnaStatuses(true); + $klarnaInvoiceStatus = (string) Tools::getValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS); + + $this->configurationAdapter->updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, $klarnaInvoiceStatus); + + if (Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED === $klarnaInvoiceStatus) { + $this->updateAuthorizablePaymentOrderStatus(true); return; } - $this->updateKlarnaStatuses(false); + $this->updateAuthorizablePaymentOrderStatus(false); } - private function updateKlarnaStatuses($isShipped = true) + private function updateAuthorizablePaymentOrderStatus(bool $isShipped = true) { - $klarnaInvoiceShippedId = Configuration::get(Config::MOLLIE_STATUS_KLARNA_SHIPPED); - $klarnaInvoiceShipped = new OrderState((int) $klarnaInvoiceShippedId); - $klarnaInvoiceShipped->invoice = $isShipped; - $klarnaInvoiceShipped->update(); + $authorizablePaymentStatusShippedId = $this->configurationAdapter->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED); + $authorizablePaymentStatusShipped = new OrderState((int) $authorizablePaymentStatusShippedId); + + $authorizablePaymentStatusShipped->invoice = $isShipped; + $authorizablePaymentStatusShipped->update(); - $klarnaInvoiceAcceptedId = Configuration::get(Config::MOLLIE_STATUS_KLARNA_AUTHORIZED); - $klarnaInvoiceAccepted = new OrderState((int) $klarnaInvoiceAcceptedId); + $authorizablePaymentStatusAuthorizedId = $this->configurationAdapter->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED); + $authorizablePaymentStatusAuthorized = new OrderState((int) $authorizablePaymentStatusAuthorizedId); - $klarnaInvoiceAccepted->invoice = !$isShipped; - $klarnaInvoiceAccepted->update(); + $authorizablePaymentStatusAuthorized->invoice = !$isShipped; + $authorizablePaymentStatusAuthorized->update(); } } diff --git a/src/Service/TransactionService.php b/src/Service/TransactionService.php index 381229130..24802c9b6 100644 --- a/src/Service/TransactionService.php +++ b/src/Service/TransactionService.php @@ -13,10 +13,10 @@ namespace Mollie\Service; use Cart; -use Configuration; use Currency; use Db; use Mollie; +use Mollie\Adapter\ConfigurationAdapter; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Order as MollieOrderAlias; use Mollie\Api\Resources\Payment; @@ -79,6 +79,8 @@ class TransactionService private $logger; /** @var ExceptionService */ private $exceptionService; + /** @var ConfigurationAdapter */ + private $configurationAdapter; public function __construct( ModuleFactory $moduleFactory, @@ -90,7 +92,8 @@ public function __construct( OrderPaymentFeeHandler $orderPaymentFeeHandler, ShipmentSenderHandlerInterface $shipmentSenderHandler, PrestaLoggerInterface $logger, - ExceptionService $exceptionService + ExceptionService $exceptionService, + ConfigurationAdapter $configurationAdapter ) { $this->module = $moduleFactory->getModule(); $this->orderStatusService = $orderStatusService; @@ -102,6 +105,7 @@ public function __construct( $this->shipmentSenderHandler = $shipmentSenderHandler; $this->logger = $logger; $this->exceptionService = $exceptionService; + $this->configurationAdapter = $configurationAdapter; } /** @@ -121,7 +125,7 @@ public function __construct( public function processTransaction($apiPayment) { if (empty($apiPayment)) { - if (Configuration::get(Config::MOLLIE_DEBUG_LOG) >= Config::DEBUG_LOG_ERRORS) { + if ($this->configurationAdapter->get(Config::MOLLIE_DEBUG_LOG) >= Config::DEBUG_LOG_ERRORS) { PrestaShopLogger::addLog(__METHOD__ . ' said: Received webhook request without proper transaction ID.', Config::WARNING); } @@ -199,10 +203,10 @@ public function processTransaction($apiPayment) throw new TransactionException('Cart id is missing in transaction metadata', HttpStatusCode::HTTP_UNPROCESSABLE_ENTITY); } - $isKlarnaOrder = in_array($apiPayment->method, Config::KLARNA_PAYMENTS, false); + $isAuthorizablePayment = in_array($apiPayment->method, Config::AUTHORIZABLE_PAYMENTS, false); if (!$orderId && $isPaymentFinished) { - $orderId = $this->orderCreationHandler->createOrder($apiPayment, $cart->id, $isKlarnaOrder); + $orderId = $this->orderCreationHandler->createOrder($apiPayment, $cart->id, $isAuthorizablePayment); if (!$orderId) { throw new TransactionException('Order is already created', HttpStatusCode::HTTP_METHOD_NOT_ALLOWED); @@ -257,9 +261,16 @@ public function processTransaction($apiPayment) $this->handleOrderDescription($apiPayment); } } else { - $isKlarnaDefault = Configuration::get(Config::MOLLIE_KLARNA_INVOICE_ON) === Config::MOLLIE_STATUS_DEFAULT; - if (in_array($apiPayment->method, Config::KLARNA_PAYMENTS) && !$isKlarnaDefault && $apiPayment->status === OrderStatus::STATUS_COMPLETED) { - $this->orderStatusService->setOrderStatus($orderId, Config::MOLLIE_STATUS_KLARNA_SHIPPED); + $isAuthorizablePaymentInvoiceOnStatusDefault = + $this->configurationAdapter->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS) + === Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT; + + if ( + !$isAuthorizablePaymentInvoiceOnStatusDefault + && $apiPayment->status === OrderStatus::STATUS_COMPLETED + && in_array($apiPayment->method, Config::AUTHORIZABLE_PAYMENTS, true) + ) { + $this->orderStatusService->setOrderStatus($orderId, Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED); } else { $this->orderStatusService->setOrderStatus($orderId, $apiPayment->status); } @@ -284,7 +295,7 @@ public function processTransaction($apiPayment) $this->savePaymentStatus($apiPayment->id, $apiPayment->status, $orderId); // Log successful webhook requests in extended log mode only - if (Config::DEBUG_LOG_ALL == Configuration::get(Config::MOLLIE_DEBUG_LOG)) { + if (Config::DEBUG_LOG_ALL == $this->configurationAdapter->get(Config::MOLLIE_DEBUG_LOG)) { PrestaShopLogger::addLog(__METHOD__ . ' said: Received webhook request for order ' . (int) $orderId . ' / transaction ' . $apiPayment->id, Config::NOTICE); } @@ -368,7 +379,7 @@ private function savePaymentStatus($transactionId, $status, $orderId) throw $e; } - if (!$result && Configuration::get(Config::MOLLIE_DEBUG_LOG) >= Config::DEBUG_LOG_ERRORS) { + if (!$result && $this->configurationAdapter->get(Config::MOLLIE_DEBUG_LOG) >= Config::DEBUG_LOG_ERRORS) { PrestaShopLogger::addLog(__METHOD__ . ' said: Could not save Mollie payment status for transaction "' . $transactionId . '". Reason: ' . Db::getInstance()->getMsgError(), Config::WARNING); } @@ -446,7 +457,7 @@ private function updateOrderPayments(array $transactionInfos, $orderReference) private function updateOrderDescription(MollieOrderAlias $apiPayment, int $orderId) { - $environment = (int) Configuration::get(Mollie\Config\Config::MOLLIE_ENVIRONMENT); + $environment = (int) $this->configurationAdapter->get(Mollie\Config\Config::MOLLIE_ENVIRONMENT); $paymentMethodId = $this->paymentMethodRepository->getPaymentMethodIdByMethodId($apiPayment->method, $environment); $paymentMethodObj = new MolPaymentMethod((int) $paymentMethodId); $orderNumber = TextGeneratorUtility::generateDescriptionFromCart($paymentMethodObj->description, $orderId); @@ -472,7 +483,7 @@ private function updatePaymentDescription(Payment $apiPayment, int $orderId): Pa if (!$orderId) { throw new TransactionException('Order does not exist', HttpStatusCode::HTTP_METHOD_NOT_ALLOWED); } - $environment = (int) Configuration::get(Mollie\Config\Config::MOLLIE_ENVIRONMENT); + $environment = (int) $this->configurationAdapter->get(Mollie\Config\Config::MOLLIE_ENVIRONMENT); $paymentMethodId = $this->paymentMethodRepository->getPaymentMethodIdByMethodId($apiPayment->method, $environment); $paymentMethodObj = new MolPaymentMethod((int) $paymentMethodId); $apiPayment->description = TextGeneratorUtility::generateDescriptionFromCart($paymentMethodObj->description, $orderId); diff --git a/src/Validator/OrderConfMailValidator.php b/src/Validator/OrderConfMailValidator.php index a8901029e..3823dce05 100644 --- a/src/Validator/OrderConfMailValidator.php +++ b/src/Validator/OrderConfMailValidator.php @@ -59,7 +59,7 @@ private function validateOrderState($orderStateId) return true; } - if ((int) $this->configurationAdapter->get(Config::MOLLIE_STATUS_KLARNA_AUTHORIZED) === $orderStateId) { + if ((int) $this->configurationAdapter->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED) === $orderStateId) { return true; } diff --git a/tests/Integration/Install/OrderStateInstallerTest.php b/tests/Integration/Install/OrderStateInstallerTest.php index a6f5598ae..efe13004b 100644 --- a/tests/Integration/Install/OrderStateInstallerTest.php +++ b/tests/Integration/Install/OrderStateInstallerTest.php @@ -86,7 +86,7 @@ public function requiredOrderStatusesDataProvider() 'pdfInvoice' => false, ], [ - 'key' => Config::MOLLIE_STATUS_KLARNA_AUTHORIZED, + 'key' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED, 'color' => '#8A2BE2', 'sendEmail' => true, 'logable' => true, @@ -97,7 +97,7 @@ public function requiredOrderStatusesDataProvider() 'pdfInvoice' => true, ], [ - 'key' => Config::MOLLIE_STATUS_KLARNA_SHIPPED, + 'key' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED, 'color' => '#8A2BE2', 'sendEmail' => true, 'logable' => true, diff --git a/upgrade/Upgrade-4.2.0.php b/upgrade/Upgrade-4.2.0.php index 69fb17797..ea901920d 100644 --- a/upgrade/Upgrade-4.2.0.php +++ b/upgrade/Upgrade-4.2.0.php @@ -11,6 +11,7 @@ use Mollie\Config\Config; use Mollie\Install\Installer; +use Mollie\Install\OrderStateInstaller; use Mollie\Service\OrderStateImageService; if (!defined('_PS_VERSION_')) { @@ -30,14 +31,13 @@ function upgrade_module_4_2_0($module) $segment->setMessage('Mollie upgrade 4.2.0'); $segment->track(); - /** @var Installer $installer */ - $installer = $module->getService(Installer::class); + /** @var OrderStateInstaller $orderStateInstaller */ + $orderStateInstaller = $module->getService(OrderStateInstaller::class); - $installer->klarnaPaymentAuthorizedState(); - $installer->klarnaPaymentShippedState(); + $orderStateInstaller->install(); - $acceptedStatusId = Configuration::get(Config::MOLLIE_STATUS_KLARNA_AUTHORIZED); - Configuration::updateValue(Config::MOLLIE_KLARNA_INVOICE_ON, $acceptedStatusId); + $acceptedStatusId = Configuration::get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED); + Configuration::updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, $acceptedStatusId); $module->registerHook('actionOrderGridQueryBuilderModifier'); $module->registerHook('actionOrderGridDefinitionModifier'); diff --git a/upgrade/Upgrade-5.4.3.php b/upgrade/Upgrade-5.4.3.php index 6f8594846..568dec529 100644 --- a/upgrade/Upgrade-5.4.3.php +++ b/upgrade/Upgrade-5.4.3.php @@ -10,6 +10,8 @@ * @see https://github.com/mollie/PrestaShop */ +use Mollie\Adapter\ConfigurationAdapter; +use Mollie\Config\Config; use Mollie\Install\ModuleTabInstaller; use Mollie\Logger\PrestaLoggerInterface; use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder; @@ -38,6 +40,9 @@ function upgrade_module_5_4_3(Mollie $module): bool return false; } + updateConfigurationValues543($module); + updateOrderStatusNames543($module); + return installPsAccounts543($module) && installCloudSync543($module); } @@ -95,3 +100,77 @@ function installCloudSync543(Mollie $module): bool return true; } + +function updateConfigurationValues543(Mollie $module) +{ + /** @var ConfigurationAdapter $configuration */ + $configuration = $module->getService(ConfigurationAdapter::class); + + if ( + !empty($configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED)) + && !empty($configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED)) + && !empty($configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS)) + && empty($configuration->get('MOLLIE_STATUS_KLARNA_AUTHORIZED')) + && empty($configuration->get('MOLLIE_STATUS_KLARNA_SHIPPED')) + && empty($configuration->get('MOLLIE_KLARNA_INVOICE_ON')) + ) { + return; + } + + $klarnaInvoiceOn = $configuration->get('MOLLIE_KLARNA_INVOICE_ON'); + + switch ($klarnaInvoiceOn) { + case 'MOLLIE_STATUS_KLARNA_AUTHORIZED': + $configuration->updateValue( + Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, + Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED + ); + break; + case 'MOLLIE_STATUS_KLARNA_SHIPPED': + $configuration->updateValue( + Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, + Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED + ); + break; + default: + $configuration->updateValue( + Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, + Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT + ); + } + + $configuration->updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED, (int) $configuration->get('MOLLIE_STATUS_KLARNA_AUTHORIZED')); + $configuration->updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED, (int) $configuration->get('MOLLIE_STATUS_KLARNA_SHIPPED')); + + $configuration->delete('MOLLIE_STATUS_KLARNA_AUTHORIZED'); + $configuration->delete('MOLLIE_STATUS_KLARNA_SHIPPED'); + $configuration->delete('MOLLIE_KLARNA_INVOICE_ON'); +} + +function updateOrderStatusNames543(Mollie $module) +{ + /** @var ConfigurationAdapter $configuration */ + $configuration = $module->getService(ConfigurationAdapter::class); + + $authorizablePaymentStatusShippedId = (int) $configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED); + $authorizablePaymentStatusShipped = new OrderState((int) $authorizablePaymentStatusShippedId); + + if (is_array($authorizablePaymentStatusShipped->name)) { + foreach ($authorizablePaymentStatusShipped->name as $langId => $name) { + $authorizablePaymentStatusShipped->name[$langId] = 'Order payment shipped'; + } + } + + $authorizablePaymentStatusShipped->save(); + + $authorizablePaymentStatusAuthorizedId = (int) $configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED); + $authorizablePaymentStatusAuthorized = new OrderState((int) $authorizablePaymentStatusAuthorizedId); + + if (is_array($authorizablePaymentStatusAuthorized->name)) { + foreach ($authorizablePaymentStatusAuthorized->name as $langId => $name) { + $authorizablePaymentStatusAuthorized->name[$langId] = 'Order payment authorized'; + } + } + + $authorizablePaymentStatusAuthorized->save(); +} diff --git a/views/templates/admin/invoice_description.tpl b/views/templates/admin/invoice_description.tpl index 59a508daa..03aeeec98 100644 --- a/views/templates/admin/invoice_description.tpl +++ b/views/templates/admin/invoice_description.tpl @@ -7,10 +7,10 @@ * @license https://github.com/mollie/PrestaShop/blob/master/LICENSE.md *}

- {l s='Select when to send Klarna invoices' mod='mollie'} + {l s='Select when to create the Order invoice' mod='mollie'}

- {l s='Default: The invoice is created based on Order settings > Statuses. There is no custom status created for Klarna.' mod='mollie'} + {l s='Default: The invoice is created based on Order settings > Statuses. There is no custom status created.' mod='mollie'}

{l s='Authorised: Create a full invoice when the order is authorized. Custom status is created.' mod='mollie'} From 4f54560a1c6a06b41611d7e487136572d6878c8e Mon Sep 17 00:00:00 2001 From: mandan2 Date: Tue, 7 Nov 2023 11:02:49 +0200 Subject: [PATCH 2/3] fix --- src/Service/SettingsSaveService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Service/SettingsSaveService.php b/src/Service/SettingsSaveService.php index f6dea8868..7df3662f1 100644 --- a/src/Service/SettingsSaveService.php +++ b/src/Service/SettingsSaveService.php @@ -385,11 +385,11 @@ private function getStatusesValue($key) private function handleAuthorizablePaymentInvoiceStatus() { - $klarnaInvoiceStatus = (string) Tools::getValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS); + $authorizablePaymentInvoiceOnStatus = (string) Tools::getValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS); - $this->configurationAdapter->updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, $klarnaInvoiceStatus); + $this->configurationAdapter->updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, $authorizablePaymentInvoiceOnStatus); - if (Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED === $klarnaInvoiceStatus) { + if (Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED === $authorizablePaymentInvoiceOnStatus) { $this->updateAuthorizablePaymentOrderStatus(true); return; From 7fd8967671814796e34642127449acb5ae6a788f Mon Sep 17 00:00:00 2001 From: mandan2 Date: Tue, 7 Nov 2023 11:29:48 +0200 Subject: [PATCH 3/3] DI missing service fix --- src/ServiceProvider/BaseServiceProvider.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index fb08fa359..891ebd7b5 100644 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -188,8 +188,7 @@ public function register(Container $container) $this->addService($container, PaymentMethodPositionHandlerInterface::class, PaymentMethodPositionHandler::class) ->withArgument(PaymentMethodRepositoryInterface::class); - $this->addService($container, CertificateHandlerInterface::class, ApplePayDirectCertificateHandler::class) - ->withArgument(Mollie::class); + $this->addService($container, CertificateHandlerInterface::class, $container->get(ApplePayDirectCertificateHandler::class)); $this->addService($container, ProfileIdProviderInterface::class, ProfileIdProvider::class);