From f2fd7bf7c360e7ac8002dceca45b6d1113355d18 Mon Sep 17 00:00:00 2001 From: Christian Proske Date: Mon, 6 Dec 2021 13:26:52 +0100 Subject: [PATCH] fix #97 --- lib/Checkout/AbstractCheckout.php | 17 +++++++++++++---- lib/Checkout/OrderCheckout.php | 4 +++- lib/Checkout/PaymentCheckout.php | 5 +++++ lib/PaymentMethod.php | 16 +++++++++------- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/Checkout/AbstractCheckout.php b/lib/Checkout/AbstractCheckout.php index dab7cf5..0d469c8 100644 --- a/lib/Checkout/AbstractCheckout.php +++ b/lib/Checkout/AbstractCheckout.php @@ -99,8 +99,8 @@ public function __construct(Bestellung $oBestellung, MollieAPI $api = null) * @param string $id * @param bool $test * - * @throws CircularReferenceException * @throws ServiceNotFoundException + * @throws CircularReferenceException * @return void * */ @@ -279,9 +279,9 @@ public function getAPI(): MollieAPI /** * @param null|mixed $hash * - * @throws Exception * @throws CircularReferenceException * @throws ServiceNotFoundException + * @throws Exception * @return void * */ @@ -349,6 +349,15 @@ public function updateModel(): self $this->getModel()->cCurrency = $this->getMollie()->amount->currency; $this->getModel()->cStatus = $this->getMollie()->status; } + + // TODO: DOKU + if (!defined('MOLLIE_DISABLE_REMINDER')) { + define('MOLLIE_DISABLE_REMINDER', []); + } + if (is_array(MOLLIE_DISABLE_REMINDER) && $this->getModel()->cMethod && in_array($this->getModel()->cMethod, MOLLIE_DISABLE_REMINDER)) { + $this->getModel()->dReminder = date('Y-m-d H:i:s'); + } + $this->getModel()->kBestellung = $this->getBestellung()->kBestellung ?: ModelInterface::NULL; $this->getModel()->cBestellNr = $this->getBestellung()->cBestellNr; $this->getModel()->bSynced = $this->getModel()->bSynced ?? (self::Plugin('ws5_mollie')->getConfig()->getValue('onlyPaid') !== 'on'); @@ -400,8 +409,8 @@ public function completlyPaid(): bool /** * @param Bestellung $oBestellung * @param OrderModel $model - * @throws CircularReferenceException * @throws ServiceNotFoundException + * @throws CircularReferenceException * @return bool */ public static function makeFetchable(Bestellung $oBestellung, OrderModel $model): bool @@ -423,8 +432,8 @@ public static function makeFetchable(Bestellung $oBestellung, OrderModel $model) /** * @param $msg * @param int $level - * @throws CircularReferenceException * @throws ServiceNotFoundException + * @throws CircularReferenceException * @return $this */ public function Log(string $msg, $level = LOGLEVEL_NOTICE) diff --git a/lib/Checkout/OrderCheckout.php b/lib/Checkout/OrderCheckout.php index d5731e9..b8009c5 100644 --- a/lib/Checkout/OrderCheckout.php +++ b/lib/Checkout/OrderCheckout.php @@ -58,7 +58,9 @@ public function create(array $paymentOptions = []): Order try { $this->order = $this->getAPI()->getClient()->orders->get($this->getModel()->cOrderId, ['embed' => 'payments']); if (in_array($this->order->status, [OrderStatus::STATUS_COMPLETED, OrderStatus::STATUS_PAID, OrderStatus::STATUS_AUTHORIZED, OrderStatus::STATUS_PENDING], true)) { - throw new RuntimeException(self::Plugin('ws5_mollie')->getLocalization()->getTranslation('errAlreadyPaid')); + $this->Log(self::Plugin('ws5_mollie')->getLocalization()->getTranslation('errAlreadyPaid')); + + return $this->order; } if ($this->order->status === OrderStatus::STATUS_CREATED) { if ($this->order->payments()) { diff --git a/lib/Checkout/PaymentCheckout.php b/lib/Checkout/PaymentCheckout.php index 582e476..4615f1d 100644 --- a/lib/Checkout/PaymentCheckout.php +++ b/lib/Checkout/PaymentCheckout.php @@ -41,6 +41,11 @@ public function create(array $paymentOptions = []): Payment if ($this->getModel()->cOrderId) { try { $this->payment = $this->getAPI()->getClient()->payments->get($this->getModel()->cOrderId); + if (in_array($this->payment->status, [PaymentStatus::STATUS_AUTHORIZED, PaymentStatus::STATUS_PAID], true)) { + $this->Log(self::Plugin('ws5_mollie')->getLocalization()->getTranslation('errAlreadyPaid')); + + return $this->payment; + } if ($this->payment->status === PaymentStatus::STATUS_OPEN) { $this->updateModel()->updateModel(); diff --git a/lib/PaymentMethod.php b/lib/PaymentMethod.php index fefd892..07c18fe 100644 --- a/lib/PaymentMethod.php +++ b/lib/PaymentMethod.php @@ -167,8 +167,8 @@ public static function getLocale(string $cISOSprache, string $country = null): s * @param $billingCountry * @param $currency * @param $amount - * @throws ApiException * @throws IncompatiblePlatform + * @throws ApiException * @return bool */ protected static function isMethodPossible($method, string $locale, $billingCountry, $currency, $amount): bool @@ -260,12 +260,14 @@ public function preparePaymentProcess(Bestellung $order): void $this->doLog('mollie::preparePaymentProcess: PUI - ' . $e->getMessage() . ' - ' . print_r(['cBestellNr' => $order->cBestellNr], 1), LOGLEVEL_NOTICE); } - ifndef('MOLLIE_REDIRECT_DELAY', 3); - $checkoutMode = self::Plugin('ws5_mollie')->getConfig()->getValue('checkoutMode'); - Shop::Smarty()->assign('redirect', $url) - ->assign('checkoutMode', $checkoutMode); - if ($checkoutMode === 'Y' && !headers_sent()) { - header('Location: ' . $url); + if ($url) { + ifndef('MOLLIE_REDIRECT_DELAY', 3); + $checkoutMode = self::Plugin('ws5_mollie')->getConfig()->getValue('checkoutMode'); + Shop::Smarty()->assign('redirect', $url) + ->assign('checkoutMode', $checkoutMode); + if ($checkoutMode === 'Y' && !headers_sent()) { + header('Location: ' . $url); + } } } catch (Exception $e) { $this->doLog('mollie::preparePaymentProcess: ' . $e->getMessage() . ' - ' . print_r(['cBestellNr' => $order->cBestellNr], 1), LOGLEVEL_ERROR);