From d53184a58593b01aac2530b1ce64bd28b08bff16 Mon Sep 17 00:00:00 2001 From: Ivascu Madalin Date: Tue, 4 Jul 2023 11:44:48 +0000 Subject: [PATCH 1/2] BP-2693 Credit Management / Paylink + Giftcards --- .../CreateCombinedInvoice.php | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Service/CreditManagement/ServiceParameters/CreateCombinedInvoice.php b/Service/CreditManagement/ServiceParameters/CreateCombinedInvoice.php index 48b4928a2..8c927013a 100644 --- a/Service/CreditManagement/ServiceParameters/CreateCombinedInvoice.php +++ b/Service/CreditManagement/ServiceParameters/CreateCombinedInvoice.php @@ -165,12 +165,49 @@ private function getAllowedServices($payment): string { $allowedServices = $this->configProvider->getPaymentMethod(); - if($payment->getMethod() === PayPerEmail::PAYMENT_METHOD_CODE) { - return str_replace("p24,","",$allowedServices); + if (!is_string($allowedServices)) { + return ''; } + + $allowedServices = $this->appendGiftcards($allowedServices); + + if ($payment->getMethod() === PayPerEmail::PAYMENT_METHOD_CODE) { + return str_replace("p24,", "", $allowedServices); + } + return $allowedServices; } + private function appendGiftcards(string $allowedServices): string + { + $services = explode(',', $allowedServices); + if (!in_array('giftcard', $services)) { + return $allowedServices; + } + $services = array_filter($services, function ($service) { + return $service !== 'giftcard'; + }); + + $allowedServices = implode(",", $services); + + /** @var \Buckaroo\Magento2\Model\ConfigProvider\Method\Giftcards */ + $giftcardConfig = $this->configProviderMethodFactory->get('giftcards'); + + if (!method_exists($giftcardConfig, 'getAllowedCards')) { + return $allowedServices; + } + $activeGiftcardIssuers = $giftcardConfig->getAllowedCards(); + + if (!is_string($activeGiftcardIssuers) || strlen(trim($activeGiftcardIssuers)) === 0) { + return $allowedServices; + } + + if(strlen($allowedServices) > 0) { + return $allowedServices . "," . $activeGiftcardIssuers; + } + return $activeGiftcardIssuers; + } + /** * @param OrderPaymentInterface|InfoInterface $payment * From 692b968b85cf7d09eaa32e438f56e50ef96d04a4 Mon Sep 17 00:00:00 2001 From: Ivascu Madalin Date: Tue, 4 Jul 2023 11:46:24 +0000 Subject: [PATCH 2/2] added comment --- .../ServiceParameters/CreateCombinedInvoice.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Service/CreditManagement/ServiceParameters/CreateCombinedInvoice.php b/Service/CreditManagement/ServiceParameters/CreateCombinedInvoice.php index 8c927013a..3008a2acc 100644 --- a/Service/CreditManagement/ServiceParameters/CreateCombinedInvoice.php +++ b/Service/CreditManagement/ServiceParameters/CreateCombinedInvoice.php @@ -178,6 +178,13 @@ private function getAllowedServices($payment): string return $allowedServices; } + /** + * Append active giftcards if giftcard is enabled + * + * @param string $allowedServices + * + * @return string + */ private function appendGiftcards(string $allowedServices): string { $services = explode(',', $allowedServices);