Spamworldpro Mini Shell
Spamworldpro


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/Ecombricks/InventoryCheckout/Plugin/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/Ecombricks/InventoryCheckout/Plugin/Model/GuestPaymentInformationManagement.php
<?php
/**
 * Copyright © eComBricks. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Ecombricks\InventoryCheckout\Plugin\Model;

/**
 * Guest payment information management plugin
 */
class GuestPaymentInformationManagement
{
    
    /**
     * Payment method management
     * 
     * @var \Magento\Quote\Api\PaymentMethodManagementInterface
     */
    protected $paymentMethodManagement;
    
    /**
     * Quote ID mask factory
     * 
     * @var \Magento\Quote\Model\QuoteIdMaskFactory
     */
    protected $quoteIdMaskFactory;
    
    /**
     * Cart repository
     * 
     * @var \Magento\Quote\Api\CartRepositoryInterface
     */
    protected $cartRepository;
    
    /**
     * Payment rate limiter
     * 
     * @var \Magento\Checkout\Api\PaymentProcessingRateLimiterInterface
     */
    protected $paymentRateLimiter;
    
    /**
     * Product metadata
     * 
     * @var \Magento\Framework\App\ProductMetadata 
     */
    protected $productMetadata;
    
    /**
     * Constructor
     * 
     * @param \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement
     * @param \Magento\Quote\Model\QuoteIdMaskFactory $quoteIdMaskFactory
     * @param \Magento\Quote\Api\CartRepositoryInterface $cartRepository
     * @param \Magento\Framework\App\ProductMetadata $productMetadata
     * @return void
     */
    public function __construct(
        \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement,
        \Magento\Quote\Model\QuoteIdMaskFactory $quoteIdMaskFactory,
        \Magento\Quote\Api\CartRepositoryInterface $cartRepository,
        \Magento\Framework\App\ProductMetadata $productMetadata
    )
    {
        $this->paymentMethodManagement = $paymentMethodManagement;
        $this->quoteIdMaskFactory = $quoteIdMaskFactory;
        $this->cartRepository = $cartRepository;
        $this->productMetadata = $productMetadata;
        if (
            version_compare($this->productMetadata->getVersion(), '2.4.1', '>=') || 
            (
                version_compare($this->productMetadata->getVersion(), '2.3.6', '>=') && 
                version_compare($this->productMetadata->getVersion(), '2.4.0', '<')
            )
        ) {
            $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
            $this->paymentRateLimiter = $objectManager->get(\Magento\Checkout\Api\PaymentProcessingRateLimiterInterface::class);
        }
    }
    
    /**
     * Save payment information
     * 
     * @param integer $cartId
     * @param string $email
     * @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
     * @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress
     * @return int
     * @throws \Magento\Framework\Exception\CouldNotSaveException
     */
    public function savePaymentInformation(
        $cartId,
        $email,
        \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
        \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
    )
    {
        if (
            version_compare($this->productMetadata->getVersion(), '2.4.1', '>=') || 
            (
                version_compare($this->productMetadata->getVersion(), '2.3.6', '>=') && 
                version_compare($this->productMetadata->getVersion(), '2.4.0', '<')
            )
        ) {
            $this->paymentRateLimiter->limit();
        }
        $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
        $quote = $this->cartRepository->getActive($quoteIdMask->getQuoteId());
        if ($billingAddress) {
            $billingAddress->setEmail($email);
            $quote->removeAddress($quote->getBillingAddress()->getId());
            $quote->setBillingAddress($billingAddress);
            $quote->setDataChanges(true);
        } else {
            $quote->getBillingAddress()->setEmail($email);
        }
        $shippingAddress = $quote->getShippingAddress();
        $shippingMethods = ($shippingAddress) ? $shippingAddress->getShippingMethod() : [];
        if (!empty($shippingMethods)) {
            $limitCarriers = [];
            foreach ($shippingMethods as $sourceCode => $shippingMethod) {
                $sourceShippingRate = $shippingAddress->getSourceShippingRateByCode($sourceCode, $shippingMethod);
                $limitCarriers[$sourceCode] = $sourceShippingRate->getCarrier();
            }
            $shippingAddress->setLimitCarrier($limitCarriers);
        }
        $this->paymentMethodManagement->set($quoteIdMask->getQuoteId(), $paymentMethod);
        return true;
    }
    
    
    /**
     * Around save payment information
     * 
     * @param \Magento\Checkout\Model\GuestPaymentInformationManagement $subject
     * @param \Closure $proceed
     * @param integer $cartId
     * @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
     * @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress
     * @return int
     * @throws \Magento\Framework\Exception\CouldNotSaveException
     */
    public function aroundSavePaymentInformation(
        \Magento\Checkout\Model\GuestPaymentInformationManagement $subject,
        \Closure $proceed,
        $cartId,
        $email,
        \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
        \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
    )
    {
        return $this->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress);
    }
    
}

Spamworldpro Mini