Skip to content

Commit

Permalink
fix #97
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Proske committed Dec 6, 2021
1 parent aa90d90 commit f2fd7bf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
17 changes: 13 additions & 4 deletions lib/Checkout/AbstractCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
*/
Expand Down Expand Up @@ -279,9 +279,9 @@ public function getAPI(): MollieAPI
/**
* @param null|mixed $hash
*
* @throws Exception
* @throws CircularReferenceException
* @throws ServiceNotFoundException
* @throws Exception
* @return void
*
*/
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion lib/Checkout/OrderCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
5 changes: 5 additions & 0 deletions lib/Checkout/PaymentCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
16 changes: 9 additions & 7 deletions lib/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f2fd7bf

Please sign in to comment.