![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/vendor/magento/module-quote/Model/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Quote\Model; use Magento\Framework\Exception\State\InvalidTransitionException; /** * Class PaymentMethodManagement */ class PaymentMethodManagement implements \Magento\Quote\Api\PaymentMethodManagementInterface { /** * @var \Magento\Quote\Api\CartRepositoryInterface */ protected $quoteRepository; /** * @var \Magento\Payment\Model\Checks\ZeroTotal */ protected $zeroTotalValidator; /** * @var \Magento\Payment\Model\MethodList */ protected $methodList; /** * Constructor * * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository * @param \Magento\Payment\Model\Checks\ZeroTotal $zeroTotalValidator * @param \Magento\Payment\Model\MethodList $methodList */ public function __construct( \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, \Magento\Payment\Model\Checks\ZeroTotal $zeroTotalValidator, \Magento\Payment\Model\MethodList $methodList ) { $this->quoteRepository = $quoteRepository; $this->zeroTotalValidator = $zeroTotalValidator; $this->methodList = $methodList; } /** * {@inheritdoc} */ public function set($cartId, \Magento\Quote\Api\Data\PaymentInterface $method) { /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->get($cartId); $quote->setTotalsCollectedFlag(false); $method->setChecks([ \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, ]); if ($quote->isVirtual()) { $address = $quote->getBillingAddress(); } else { $address = $quote->getShippingAddress(); // check if shipping address is set if ($address->getCountryId() === null) { throw new InvalidTransitionException( __('The shipping address is missing. Set the address and try again.') ); } $address->setCollectShippingRates(true); } $paymentData = $method->getData(); $payment = $quote->getPayment(); $payment->importData($paymentData); $address->setPaymentMethod($payment->getMethod()); if (!$this->zeroTotalValidator->isApplicable($payment->getMethodInstance(), $quote)) { throw new InvalidTransitionException(__('The requested Payment Method is not available.')); } $quote->save(); return $quote->getPayment()->getId(); } /** * {@inheritdoc} */ public function get($cartId) { /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->get($cartId); $payment = $quote->getPayment(); if (!$payment->getId()) { return null; } return $payment; } /** * {@inheritdoc} */ public function getList($cartId) { /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->get($cartId); return $this->methodList->getAvailableMethods($quote); } }