From f18dfd8976117091ba68c0bc54b9fdcc68b231ac Mon Sep 17 00:00:00 2001 From: IrinaZhadzinets Date: Wed, 20 Jul 2022 15:40:17 +0300 Subject: [PATCH] #4802 - Return only free payment if available --- src/Model/Resolver/GetPaymentMethods.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Model/Resolver/GetPaymentMethods.php b/src/Model/Resolver/GetPaymentMethods.php index 1556515..8c7cb3c 100644 --- a/src/Model/Resolver/GetPaymentMethods.php +++ b/src/Model/Resolver/GetPaymentMethods.php @@ -35,6 +35,11 @@ */ class GetPaymentMethods implements ResolverInterface { + /** + * Zero Subtotal Checkout payment method + */ + public const FREE_PAYMENT = 'free'; + /** * @var PaymentDetailsFactory */ @@ -111,6 +116,19 @@ public function resolve( $paymentDetails = $this->paymentDetailsFactory->create(); $paymentDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId)); $paymentDetails->setTotals($this->cartTotalsRepository->get($cartId)); + $paymentMethods = $paymentDetails->getPaymentMethods(); + + /** If Zero Subtotal Checkout is available filter out all the other methods and return only Free Payment */ + foreach ($paymentMethods as $payment) { + if ($payment->getCode() === self::FREE_PAYMENT) { + return [ + [ + 'code' => $payment->getCode(), + 'title' => $payment->getTitle(), + ] + ]; + } + } return array_map( function ($payment) { @@ -120,7 +138,7 @@ function ($payment) { 'title' => $payment->getTitle(), ]; }, - $paymentDetails->getPaymentMethods() + $paymentMethods ); } }