Skip to content

Commit

Permalink
Merge pull request #100 from IrinaZhadzinets/issue-4802
Browse files Browse the repository at this point in the history
#4802 - Return only free payment if available
  • Loading branch information
carinadues authored Jul 27, 2022
2 parents 43522b7 + f18dfd8 commit eb724b5
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Model/Resolver/GetPaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
*/
class GetPaymentMethods implements ResolverInterface
{
/**
* Zero Subtotal Checkout payment method
*/
public const FREE_PAYMENT = 'free';

/**
* @var PaymentDetailsFactory
*/
Expand Down Expand Up @@ -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) {
Expand All @@ -120,7 +138,7 @@ function ($payment) {
'title' => $payment->getTitle(),
];
},
$paymentDetails->getPaymentMethods()
$paymentMethods
);
}
}

0 comments on commit eb724b5

Please sign in to comment.