diff --git a/modules/btcpay/btcpay.php b/modules/btcpay/btcpay.php index 11d8a90..24d799d 100644 --- a/modules/btcpay/btcpay.php +++ b/modules/btcpay/btcpay.php @@ -7,14 +7,13 @@ use BTCPay\Installer\OrderStates; use BTCPay\Installer\Tables; use BTCPay\Installer\Webhook; -use BTCPay\LegacyBitcoinPaymentRepository; use BTCPay\Repository\BitcoinPaymentRepository; +use BTCPay\Repository\TableRepository; use BTCPay\Server\Client; use BTCPayServer\Exception\BTCPayException; use BTCPayServer\Exception\RequestException; use PrestaShop\PrestaShop\Adapter\Configuration; use PrestaShop\PrestaShop\Adapter\Presenter\Order\OrderPresenter; -use PrestaShop\PrestaShop\Adapter\SymfonyContainer; use PrestaShop\PrestaShop\Core\Payment\PaymentOption; if (!defined('_PS_VERSION_')) { @@ -39,11 +38,6 @@ class BTCPay extends PaymentModule ], ]; - /** - * @var BitcoinPaymentRepository - */ - private $repository; - /** * @var Configuration */ @@ -123,8 +117,8 @@ public function install(): bool return false; } - if (null === ($repository = $this->getRepository())) { - $this->addModuleErrors(['Expected a BitcoinPaymentRepository repository, but received NULL']); + if (null === ($repository = $this->get('prestashop.module.btcpay.repository.install')) || false === $repository instanceof TableRepository) { + $this->addModuleErrors(['Expected a TableRepository repository, but received null/something else']); return false; } @@ -223,11 +217,8 @@ public function hookDisplayAdminOrderMainBottom($params): ?string return null; } - // Get legacy repository - $repository = new LegacyBitcoinPaymentRepository(); - // Get the order - if (null === ($bitcoinPayment = $repository->getOneByOrderID($params['id_order']))) { + if (null === ($bitcoinPayment = BitcoinPaymentRepository::getOneByOrderID($params['id_order']))) { return null; } @@ -322,11 +313,8 @@ public function hookDisplayOrderDetail(array $params): ?string return null; } - // Get legacy repository - $repository = new LegacyBitcoinPaymentRepository(); - // Get the order - if (null === ($bitcoinPayment = $repository->getOneByOrderID($order->id))) { + if (null === ($bitcoinPayment = BitcoinPaymentRepository::getOneByOrderID($order->id))) { return null; } @@ -381,7 +369,7 @@ public function hookPaymentReturn($params): ?string } // Get the order - if (null === ($bitcoinPayment = (new LegacyBitcoinPaymentRepository())->getOneByOrderID($order->id))) { + if (null === ($bitcoinPayment = BitcoinPaymentRepository::getOneByOrderID($order->id))) { return null; } @@ -478,7 +466,7 @@ public function hookActionCartSave(array $params): void } // Get the order - if (null === ($bitcoinPayment = (new LegacyBitcoinPaymentRepository())->getOneByCartID($cart->id))) { + if (null === ($bitcoinPayment = BitcoinPaymentRepository::getOneByCartID($cart->id))) { return; } @@ -500,21 +488,6 @@ private function addModuleErrors(array $errors): void } } - private function getRepository(): ?BitcoinPaymentRepository - { - if (null === $this->repository) { - try { - $this->repository = $this->get('prestashop.module.btcpay.repository'); - } catch (Throwable $e) { - if (null !== ($container = SymfonyContainer::getInstance())) { - $this->repository = new BitcoinPaymentRepository($container->get('doctrine.dbal.default_connection'), $container->getParameter('database_prefix')); - } - } - } - - return $this->repository; - } - private function displayModuleWarnings(): void { // Try and create the client diff --git a/modules/btcpay/config/services.yml b/modules/btcpay/config/services.yml index 7b317bc..7a28f04 100644 --- a/modules/btcpay/config/services.yml +++ b/modules/btcpay/config/services.yml @@ -7,8 +7,8 @@ services: class: BTCPay # Repositories - prestashop.module.btcpay.repository: - class: BTCPay\Repository\BitcoinPaymentRepository + prestashop.module.btcpay.repository.install: + class: BTCPay\Repository\TableRepository arguments: - '@doctrine.dbal.default_connection' - '%database_prefix%' diff --git a/modules/btcpay/controllers/front/validation.php b/modules/btcpay/controllers/front/validation.php index 516cd87..24a43ad 100644 --- a/modules/btcpay/controllers/front/validation.php +++ b/modules/btcpay/controllers/front/validation.php @@ -2,7 +2,7 @@ use BTCPay\Constants; use BTCPay\Invoice\Processor; -use BTCPay\LegacyBitcoinPaymentRepository; +use BTCPay\Repository\BitcoinPaymentRepository; use BTCPay\Server\Client; use PrestaShop\PrestaShop\Adapter\Configuration; @@ -25,17 +25,11 @@ class BTCPayValidationModuleFrontController extends ModuleFrontController */ private $configuration; - /** - * @var LegacyBitcoinPaymentRepository - */ - private $repository; - public function __construct() { parent::__construct(); $this->configuration = new Configuration(); - $this->repository = new LegacyBitcoinPaymentRepository(); } /** @@ -78,7 +72,7 @@ public function postProcess(): void // Get the passed invoice reference, which we can then use to get the actual order $invoiceReference = Tools::getValue('invoice_reference', 0); - if (null === ($bitcoinPayment = $this->repository->getOneByInvoiceReference($invoiceReference))) { + if (null === ($bitcoinPayment = BitcoinPaymentRepository::getOneByInvoiceReference($invoiceReference))) { $this->warning[] = $translator->trans('The passed invoice reference is not valid.', [], 'Modules.Btcpay.Front'); $this->redirectWithNotifications($this->context->link->getPageLink('cart', $this->ssl)); diff --git a/modules/btcpay/controllers/front/webhook.php b/modules/btcpay/controllers/front/webhook.php index 7f3b621..e235566 100644 --- a/modules/btcpay/controllers/front/webhook.php +++ b/modules/btcpay/controllers/front/webhook.php @@ -1,7 +1,6 @@ configuration = new Configuration(); $this->client = Client::createFromConfiguration($this->configuration); - $this->handler = new WebhookHandler($this->module, $this->context, $this->client, new LegacyBitcoinPaymentRepository()); + $this->handler = new WebhookHandler($this->module, $this->context, $this->client); } /** diff --git a/modules/btcpay/src/Factory/CustomerMessage.php b/modules/btcpay/src/Factory/CustomerMessage.php index 6782eaf..73422da 100644 --- a/modules/btcpay/src/Factory/CustomerMessage.php +++ b/modules/btcpay/src/Factory/CustomerMessage.php @@ -33,7 +33,7 @@ public static function create(\CustomerThread $ct, string $message): \CustomerMe public static function addToOrder(\Shop $shop, \Order $order, string $message): void { // Find or create the customer thread - $ct = CustomerThreadRepository::fetchOrCreateByByEmailAndOrder($shop, $order); + $ct = CustomerThreadRepository::fetchOrCreate($shop, $order); // Ensure the thread is open $ct->status = 'open'; diff --git a/modules/btcpay/src/Installer/Tables.php b/modules/btcpay/src/Installer/Tables.php index fdc924a..b0102be 100644 --- a/modules/btcpay/src/Installer/Tables.php +++ b/modules/btcpay/src/Installer/Tables.php @@ -2,18 +2,18 @@ namespace BTCPay\Installer; -use BTCPay\Repository\BitcoinPaymentRepository; +use BTCPay\Repository\TableRepository; class Tables { /** - * @var BitcoinPaymentRepository + * @var TableRepository */ - private $repository; + private $tableRepository; - public function __construct(BitcoinPaymentRepository $repository) + public function __construct(TableRepository $repository) { - $this->repository = $repository; + $this->tableRepository = $repository; } /** @@ -22,7 +22,7 @@ public function __construct(BitcoinPaymentRepository $repository) */ public function install(): array { - return $this->repository->createTables(); + return $this->tableRepository->createTables(); } /** @@ -31,6 +31,6 @@ public function install(): array */ public function uninstall(): array { - return $this->repository->dropTables(); + return $this->tableRepository->dropTables(); } } diff --git a/modules/btcpay/src/LegacyBitcoinPaymentRepository.php b/modules/btcpay/src/LegacyBitcoinPaymentRepository.php deleted file mode 100644 index 2f3a45c..0000000 --- a/modules/btcpay/src/LegacyBitcoinPaymentRepository.php +++ /dev/null @@ -1,135 +0,0 @@ -connection = \Db::getInstance(); - } - - /** - * @throws \PrestaShopException - */ - public function create(int $cartId, string $status, string $invoiceId): BitcoinPayment - { - $bitcoinPayment = new BitcoinPayment(); - $bitcoinPayment->setCartId($cartId); - $bitcoinPayment->setStatus($status); - $bitcoinPayment->setInvoiceId($invoiceId); - - if (false === $bitcoinPayment->save(true)) { - \PrestaShopLogger::addLog('[ERROR] Could not store bitcoin_payment', \PrestaShopLogger::LOG_SEVERITY_LEVEL_ERROR); - - throw new \RuntimeException('[ERROR] Could not store bitcoin_payment'); - } - - \PrestaShopLogger::addLog('[INFO] Created bitcoin_payment for invoice ' . $invoiceId, \PrestaShopLogger::LOG_SEVERITY_LEVEL_INFORMATIVE, null, 'BitcoinPayment', $bitcoinPayment->getId()); - - return $bitcoinPayment; - } - - /** - * @throws \PrestaShopDatabaseException - * @throws \JsonException - */ - public function getOneByInvoiceID(string $invoiceId): ?BitcoinPayment - { - $query = new \DbQuery(); - $query->select('bp.*') - ->from('bitcoin_payment', 'bp') - ->where(\sprintf('bp.invoice_id = "%s"', $invoiceId)) - ->limit(1); - - $result = $this->connection->query($query); - if (0 !== ($errorCode = (int) $result->errorCode())) { - throw new \PrestaShopDatabaseException(\json_encode($result->errorInfo(), \JSON_THROW_ON_ERROR), $errorCode); - } - - if (false === ($object = $result->fetchObject(BitcoinPayment::class))) { - return null; - } - - return $object; - } - - /** - * @throws \PrestaShopDatabaseException - * @throws \JsonException - */ - public function getOneByInvoiceReference(string $invoiceReference): ?BitcoinPayment - { - $query = new \DbQuery(); - $query->select('bp.*') - ->from('bitcoin_payment', 'bp') - ->where(\sprintf('bp.invoice_reference = "%s"', $invoiceReference)) - ->limit(1); - - $result = $this->connection->query($query); - if (0 !== ($errorCode = (int) $result->errorCode())) { - throw new \PrestaShopDatabaseException(\json_encode($result->errorInfo(), \JSON_THROW_ON_ERROR), $errorCode); - } - - if (false === ($object = $result->fetchObject(BitcoinPayment::class))) { - return null; - } - - return $object; - } - - /** - * @throws \PrestaShopDatabaseException - * @throws \JsonException - */ - public function getOneByCartID(int $cartID): ?BitcoinPayment - { - $query = new \DbQuery(); - $query->select('bp.*') - ->from('bitcoin_payment', 'bp') - ->where(\sprintf('bp.cart_id = "%s"', $cartID)) - ->limit(1); - - $result = $this->connection->query($query); - if (0 !== ($errorCode = (int) $result->errorCode())) { - throw new \PrestaShopDatabaseException(\json_encode($result->errorInfo(), \JSON_THROW_ON_ERROR), $errorCode); - } - - if (false === ($object = $result->fetchObject(BitcoinPayment::class))) { - return null; - } - - return $object; - } - - /** - * @throws \PrestaShopDatabaseException - * @throws \JsonException - */ - public function getOneByOrderID(int $orderID): ?BitcoinPayment - { - $query = new \DbQuery(); - $query->select('bp.*') - ->from('bitcoin_payment', 'bp') - ->where(\sprintf('bp.order_id = "%s"', $orderID)) - ->limit(1); - - $result = $this->connection->query($query); - if (0 !== ($errorCode = (int) $result->errorCode())) { - throw new \PrestaShopDatabaseException(\json_encode($result->errorInfo(), \JSON_THROW_ON_ERROR), $errorCode); - } - - if (false === ($object = $this->connection->query($query)->fetchObject(BitcoinPayment::class))) { - return null; - } - - return $object; - } -} diff --git a/modules/btcpay/src/Repository/BitcoinPaymentRepository.php b/modules/btcpay/src/Repository/BitcoinPaymentRepository.php index 8c28627..1b1fc75 100644 --- a/modules/btcpay/src/Repository/BitcoinPaymentRepository.php +++ b/modules/btcpay/src/Repository/BitcoinPaymentRepository.php @@ -2,80 +2,124 @@ namespace BTCPay\Repository; -use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Exception; +use BTCPay\Entity\BitcoinPayment; class BitcoinPaymentRepository { /** - * @var Connection + * @throws \PrestaShopException */ - private $connection; + public static function create(int $cartId, string $status, string $invoiceId): BitcoinPayment + { + $bitcoinPayment = new BitcoinPayment(); + $bitcoinPayment->setCartId($cartId); + $bitcoinPayment->setStatus($status); + $bitcoinPayment->setInvoiceId($invoiceId); + + if (false === $bitcoinPayment->save(true)) { + \PrestaShopLogger::addLog('[ERROR] Could not store bitcoin_payment', \PrestaShopLogger::LOG_SEVERITY_LEVEL_ERROR); + + throw new \RuntimeException('[ERROR] Could not store bitcoin_payment'); + } + + \PrestaShopLogger::addLog('[INFO] Created bitcoin_payment for invoice ' . $invoiceId, \PrestaShopLogger::LOG_SEVERITY_LEVEL_INFORMATIVE, null, 'BitcoinPayment', $bitcoinPayment->getId()); + + return $bitcoinPayment; + } /** - * @var string + * @throws \PrestaShopDatabaseException + * @throws \JsonException */ - private $prefix; + public static function getOneByInvoiceID(string $invoiceId): ?BitcoinPayment + { + $query = new \DbQuery(); + $query->select('bp.*') + ->from('bitcoin_payment', 'bp') + ->where(\sprintf('bp.invoice_id = "%s"', $invoiceId)) + ->limit(1); + + $result = \Db::getInstance()->query($query); + if (0 !== ($errorCode = (int) $result->errorCode())) { + throw new \PrestaShopDatabaseException(\json_encode($result->errorInfo(), \JSON_THROW_ON_ERROR), $errorCode); + } + + if (false === ($object = $result->fetchObject(BitcoinPayment::class))) { + return null; + } + + return $object; + } - public function __construct(Connection $connection, string $prefix) + /** + * @throws \PrestaShopDatabaseException + * @throws \JsonException + */ + public static function getOneByInvoiceReference(string $invoiceReference): ?BitcoinPayment { - $this->connection = $connection; - $this->prefix = $prefix; + $query = new \DbQuery(); + $query->select('bp.*') + ->from('bitcoin_payment', 'bp') + ->where(\sprintf('bp.invoice_reference = "%s"', $invoiceReference)) + ->limit(1); + + $result = \Db::getInstance()->query($query); + if (0 !== ($errorCode = (int) $result->errorCode())) { + throw new \PrestaShopDatabaseException(\json_encode($result->errorInfo(), \JSON_THROW_ON_ERROR), $errorCode); + } + + if (false === ($object = $result->fetchObject(BitcoinPayment::class))) { + return null; + } + + return $object; } /** + * @throws \PrestaShopDatabaseException * @throws \JsonException */ - public function createTables(): array + public static function getOneByCartID(int $cartID): ?BitcoinPayment { - $errors = []; - $engine = \_MYSQL_ENGINE_; - - $queries = [ - "CREATE TABLE IF NOT EXISTS `{$this->prefix}bitcoin_payment`( - `id` int(11) NOT NULL AUTO_INCREMENT, - `cart_id` int(11) NOT NULL, - `order_id` int(11), - `status` varchar(255) NOT NULL, - `invoice_id` varchar(255), - `invoice_reference` varchar(255), - `amount` varchar(255), - `bitcoin_price` varchar(255), - `bitcoin_paid` varchar(255), - `bitcoin_address` varchar(255), - `bitcoin_refund_address` varchar(255), - `redirect` varchar(255), - `rate` varchar(255), - PRIMARY KEY (`id`), - UNIQUE KEY `invoice_id` (`invoice_id`) - ) ENGINE=$engine DEFAULT CHARSET=utf8", - ]; - - try { - foreach ($queries as $query) { - $this->connection->executeQuery($query); - } - } catch (Exception $e) { - $errors[] = ['key' => \json_encode($e->getMessage(), \JSON_THROW_ON_ERROR), 'parameters' => [], 'domain' => 'Admin.Modules.Notification']; + $query = new \DbQuery(); + $query->select('bp.*') + ->from('bitcoin_payment', 'bp') + ->where(\sprintf('bp.cart_id = "%s"', $cartID)) + ->limit(1); + + $result = \Db::getInstance()->query($query); + if (0 !== ($errorCode = (int) $result->errorCode())) { + throw new \PrestaShopDatabaseException(\json_encode($result->errorInfo(), \JSON_THROW_ON_ERROR), $errorCode); } - return $errors; + if (false === ($object = $result->fetchObject(BitcoinPayment::class))) { + return null; + } + + return $object; } /** + * @throws \PrestaShopDatabaseException * @throws \JsonException */ - public function dropTables(): array + public static function getOneByOrderID(int $orderID): ?BitcoinPayment { - $errors = []; - $query = "DROP TABLE IF EXISTS `{$this->prefix}bitcoin_payment`"; + $query = new \DbQuery(); + $query->select('bp.*') + ->from('bitcoin_payment', 'bp') + ->where(\sprintf('bp.order_id = "%s"', $orderID)) + ->limit(1); + + $result = \Db::getInstance()->query($query); + if (0 !== ($errorCode = (int) $result->errorCode())) { + throw new \PrestaShopDatabaseException(\json_encode($result->errorInfo(), \JSON_THROW_ON_ERROR), $errorCode); + } - try { - $this->connection->executeQuery($query); - } catch (Exception $e) { - $errors[] = ['key' => \json_encode($e->getMessage(), \JSON_THROW_ON_ERROR), 'parameters' => [], 'domain' => 'Admin.Modules.Notification']; + if (false === ($object = $result->fetchObject(BitcoinPayment::class))) { + return null; } - return $errors; + return $object; } } diff --git a/modules/btcpay/src/Repository/CustomerThreadRepository.php b/modules/btcpay/src/Repository/CustomerThreadRepository.php index 0daa082..eaa381b 100644 --- a/modules/btcpay/src/Repository/CustomerThreadRepository.php +++ b/modules/btcpay/src/Repository/CustomerThreadRepository.php @@ -10,7 +10,7 @@ class CustomerThreadRepository * @throws \PrestaShopException * @throws \PrestaShopDatabaseException */ - public static function fetchOrCreateByByEmailAndOrder(\Shop $shop, \Order $order): \CustomerThread + public static function fetchOrCreate(\Shop $shop, \Order $order): \CustomerThread { // Get the customer $customer = $order->getCustomer(); diff --git a/modules/btcpay/src/Repository/TableRepository.php b/modules/btcpay/src/Repository/TableRepository.php new file mode 100644 index 0000000..6b2cf8a --- /dev/null +++ b/modules/btcpay/src/Repository/TableRepository.php @@ -0,0 +1,81 @@ +connection = $connection; + $this->prefix = $prefix; + } + + /** + * @throws \JsonException + */ + public function createTables(): array + { + $errors = []; + $engine = \_MYSQL_ENGINE_; + + $queries = [ + "CREATE TABLE IF NOT EXISTS `{$this->prefix}bitcoin_payment`( + `id` int(11) NOT NULL AUTO_INCREMENT, + `cart_id` int(11) NOT NULL, + `order_id` int(11), + `status` varchar(255) NOT NULL, + `invoice_id` varchar(255), + `invoice_reference` varchar(255), + `amount` varchar(255), + `bitcoin_price` varchar(255), + `bitcoin_paid` varchar(255), + `bitcoin_address` varchar(255), + `bitcoin_refund_address` varchar(255), + `redirect` varchar(255), + `rate` varchar(255), + PRIMARY KEY (`id`), + UNIQUE KEY `invoice_id` (`invoice_id`) + ) ENGINE=$engine DEFAULT CHARSET=utf8", + ]; + + try { + foreach ($queries as $query) { + $this->connection->executeQuery($query); + } + } catch (Exception $e) { + $errors[] = ['key' => \json_encode($e->getMessage(), \JSON_THROW_ON_ERROR), 'parameters' => [], 'domain' => 'Admin.Modules.Notification']; + } + + return $errors; + } + + /** + * @throws \JsonException + */ + public function dropTables(): array + { + $errors = []; + $query = "DROP TABLE IF EXISTS `{$this->prefix}bitcoin_payment`"; + + try { + $this->connection->executeQuery($query); + } catch (Exception $e) { + $errors[] = ['key' => \json_encode($e->getMessage(), \JSON_THROW_ON_ERROR), 'parameters' => [], 'domain' => 'Admin.Modules.Notification']; + } + + return $errors; + } +} diff --git a/modules/btcpay/src/Server/Client.php b/modules/btcpay/src/Server/Client.php index 8cb5bc5..b8cf539 100644 --- a/modules/btcpay/src/Server/Client.php +++ b/modules/btcpay/src/Server/Client.php @@ -3,7 +3,7 @@ namespace BTCPay\Server; use BTCPay\Constants; -use BTCPay\LegacyBitcoinPaymentRepository; +use BTCPay\Repository\BitcoinPaymentRepository; use BTCPayServer\Client\AbstractClient; use BTCPayServer\Client\ApiKey as ApiKeyClient; use BTCPayServer\Client\Invoice as InvoiceClient; @@ -62,11 +62,6 @@ class Client extends AbstractClient */ private $configuration; - /** - * @var LegacyBitcoinPaymentRepository - */ - private $repository; - public function __construct(string $baseUrl, string $apiKey) { $httpClient = new CurlAdapter(); @@ -83,7 +78,6 @@ public function __construct(string $baseUrl, string $apiKey) $this->webhook = new Webhook($baseUrl, $apiKey, $httpClient); $this->configuration = new Configuration(); - $this->repository = new LegacyBitcoinPaymentRepository(); } public static function createFromConfiguration(ShopConfigurationInterface $configuration): ?self @@ -170,7 +164,7 @@ public function getBTCPayRedirect(\Cart $cart): ?string return null; } - if (null === ($bitcoinPayment = $this->repository->getOneByCartID($cart->id))) { + if (null === ($bitcoinPayment = BitcoinPaymentRepository::getOneByCartID($cart->id))) { return null; } diff --git a/modules/btcpay/src/Server/Factory.php b/modules/btcpay/src/Server/Factory.php index c66b4f2..85bfd28 100644 --- a/modules/btcpay/src/Server/Factory.php +++ b/modules/btcpay/src/Server/Factory.php @@ -4,18 +4,13 @@ use BTCPay\Constants; use BTCPay\Exception\BTCPayException; -use BTCPay\LegacyBitcoinPaymentRepository; +use BTCPay\Repository\BitcoinPaymentRepository; use BTCPayServer\Client\InvoiceCheckoutOptions; use BTCPayServer\Util\PreciseNumber; use PrestaShop\PrestaShop\Adapter\Configuration; class Factory { - /** - * @var LegacyBitcoinPaymentRepository - */ - private $repository; - /** * @var \Link */ @@ -38,7 +33,6 @@ class Factory public function __construct(\BTCPay $module, \Context $context) { - $this->repository = new LegacyBitcoinPaymentRepository(); $this->link = new \Link(); $this->configuration = new Configuration(); $this->context = $context; @@ -121,8 +115,8 @@ public function createPaymentRequest(\Customer $customer, \Cart $cart): ?string $orderStatus = (string) $this->configuration->get(Constants::CONFIGURATION_ORDER_STATE_WAITING); // Register invoice into bitcoin_payment table, if we didn't have one before. - if (null === ($bitcoinPayment = $this->repository->getOneByCartID($cart->id))) { - $bitcoinPayment = $this->repository->create($cart->id, $orderStatus, $invoiceId); + if (null === ($bitcoinPayment = BitcoinPaymentRepository::getOneByCartID($cart->id))) { + $bitcoinPayment = BitcoinPaymentRepository::create($cart->id, $orderStatus, $invoiceId); } $bitcoinPayment->setInvoiceId($invoiceId); diff --git a/modules/btcpay/src/Server/WebhookHandler.php b/modules/btcpay/src/Server/WebhookHandler.php index da5eff3..133dcbe 100644 --- a/modules/btcpay/src/Server/WebhookHandler.php +++ b/modules/btcpay/src/Server/WebhookHandler.php @@ -5,7 +5,7 @@ use BTCPay\Constants; use BTCPay\Factory\CustomerMessage; use BTCPay\Invoice\Processor; -use BTCPay\LegacyBitcoinPaymentRepository; +use BTCPay\Repository\BitcoinPaymentRepository; use PrestaShop\PrestaShop\Adapter\Configuration; use Symfony\Component\HttpFoundation\Request; @@ -16,11 +16,6 @@ class WebhookHandler */ private $context; - /** - * @var LegacyBitcoinPaymentRepository - */ - private $repository; - /** * @var Configuration */ @@ -31,10 +26,9 @@ class WebhookHandler */ private $processor; - public function __construct(\BTCPay $module, \Context $context, Client $client, LegacyBitcoinPaymentRepository $repository) + public function __construct(\BTCPay $module, \Context $context, Client $client) { $this->context = $context; - $this->repository = $repository; $this->configuration = new Configuration(); $this->processor = new Processor($module, $context, $this->configuration, $client); } @@ -124,7 +118,7 @@ private function paymentReceived(array $data): void $invoiceId = (string) $data['invoiceId']; \PrestaShopLogger::addLog(\sprintf('[INFO] Payment received for invoice %s', $invoiceId)); - if (null === ($bitcoinPayment = $this->repository->getOneByInvoiceID($invoiceId))) { + if (null === ($bitcoinPayment = BitcoinPaymentRepository::getOneByInvoiceID($invoiceId))) { $error = \sprintf('[WARNING] Could not load order with invoice ID %s', $invoiceId); \PrestaShopLogger::addLog(\sprintf('[INFO] Received IPN: %s', \json_encode($data, \JSON_THROW_ON_ERROR))); \PrestaShopLogger::addLog($error, \PrestaShopLogger::LOG_SEVERITY_LEVEL_WARNING); @@ -146,7 +140,7 @@ private function paymentReceivedDelayedOrder(array $data): void $invoiceId = (string) $data['invoiceId']; \PrestaShopLogger::addLog(\sprintf('[INFO] Payment received for invoice %s', $invoiceId)); - if (null === ($bitcoinPayment = $this->repository->getOneByInvoiceID($invoiceId))) { + if (null === ($bitcoinPayment = BitcoinPaymentRepository::getOneByInvoiceID($invoiceId))) { $error = \sprintf('[WARNING] Could not load order with invoice ID %s', $invoiceId); \PrestaShopLogger::addLog(\sprintf('[INFO] Received IPN: %s', \json_encode($data, \JSON_THROW_ON_ERROR))); \PrestaShopLogger::addLog($error, \PrestaShopLogger::LOG_SEVERITY_LEVEL_WARNING); @@ -192,7 +186,7 @@ private function invoiceFailed(array $data): void $invoiceId = (string) $data['invoiceId']; \PrestaShopLogger::addLog(\sprintf("[INFO] Invoice '%s' failed, either because it wasn't paid, it expired or it was marked as invalid", $invoiceId)); - if (null === ($bitcoinPayment = $this->repository->getOneByInvoiceID($invoiceId))) { + if (null === ($bitcoinPayment = BitcoinPaymentRepository::getOneByInvoiceID($invoiceId))) { $error = \sprintf('[WARNING] Could not load order with invoice ID %s', $invoiceId); \PrestaShopLogger::addLog(\sprintf('[INFO] Received IPN: %s', \json_encode($data, \JSON_THROW_ON_ERROR))); \PrestaShopLogger::addLog($error, \PrestaShopLogger::LOG_SEVERITY_LEVEL_WARNING); @@ -242,7 +236,7 @@ private function invoiceSettled(array $data): void $invoiceId = (string) $data['invoiceId']; \PrestaShopLogger::addLog(\sprintf("[INFO] Invoice '%s' has been settled and thus fully paid", $invoiceId)); - if (null === ($bitcoinPayment = $this->repository->getOneByInvoiceID($invoiceId))) { + if (null === ($bitcoinPayment = BitcoinPaymentRepository::getOneByInvoiceID($invoiceId))) { $error = \sprintf('[WARNING] Could not load order with invoice ID %s', $invoiceId); \PrestaShopLogger::addLog(\sprintf('[INFO] Received IPN: %s', \json_encode($data, \JSON_THROW_ON_ERROR))); \PrestaShopLogger::addLog($error, \PrestaShopLogger::LOG_SEVERITY_LEVEL_WARNING);