From f93f177ee5377d46af4b2fe429914d366cf2b82e Mon Sep 17 00:00:00 2001 From: Nicolas Barbey Date: Tue, 11 Jun 2024 10:00:04 +0200 Subject: [PATCH] fix payment options --- Config/module.xml | 2 +- Model/Api/Checkout.php | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Config/module.xml b/Config/module.xml index f0d1e1e..42b652d 100644 --- a/Config/module.xml +++ b/Config/module.xml @@ -19,7 +19,7 @@ en_US fr_FR - 2.2.24 + 2.2.25 Vincent Lopes-Vicente diff --git a/Model/Api/Checkout.php b/Model/Api/Checkout.php index 1543373..573dd49 100644 --- a/Model/Api/Checkout.php +++ b/Model/Api/Checkout.php @@ -81,6 +81,14 @@ class Checkout extends BaseApiModel */ protected $paymentOptionChoices = []; + /** + * @var bool + * @OA\Property( + * type="boolean" + * ) + */ + protected $mustSelectPaymentOption = false; + /** * @var bool * @OA\Property( @@ -127,6 +135,10 @@ public function getIsComplete() return false; } + if ($this->isMustSelectPaymentOption() && empty($this->getPaymentOptionChoices())) { + return false; + } + return true; } @@ -145,7 +157,7 @@ public function checkIsValid(): void ); } - if (null === $this->getPaymentModuleId()) { + if (null === $this->getPaymentModuleId() || ($this->isMustSelectPaymentOption() && empty($this->getPaymentOptionChoices()))) { throw new \Exception( Translator::getInstance()->trans( 'You must choose a payment module', @@ -326,4 +338,23 @@ public function setPaymentOptionChoices(?array $paymentOptionChoices = []): Chec $this->paymentOptionChoices = $paymentOptionChoices; return $this; } + + /** + * @return bool + */ + public function isMustSelectPaymentOption(): bool + { + return $this->mustSelectPaymentOption; + } + + /** + * @param bool $mustSelectPaymentOption + */ + public function setMustSelectPaymentOption(?bool $mustSelectPaymentOption = false): Checkout + { + $this->mustSelectPaymentOption = $mustSelectPaymentOption; + return $this; + } + + }