From 6dd609b044c8970f4fbc8887bfa1d4625ec39942 Mon Sep 17 00:00:00 2001 From: "a.baraliu" Date: Wed, 21 Aug 2024 16:56:14 +0200 Subject: [PATCH] Improve-coding-for-ImplementationBuckarooFeeHyva.php-File-in-Model-Total-Quote --- Model/Total/Quote/BuckarooFeeHyva.php | 345 -------------------------- etc/sales.xml | 3 - 2 files changed, 348 deletions(-) delete mode 100644 Model/Total/Quote/BuckarooFeeHyva.php diff --git a/Model/Total/Quote/BuckarooFeeHyva.php b/Model/Total/Quote/BuckarooFeeHyva.php deleted file mode 100644 index 1c26a42c4..000000000 --- a/Model/Total/Quote/BuckarooFeeHyva.php +++ /dev/null @@ -1,345 +0,0 @@ -setCode('buckaroo_fee_hyva'); - - $this->configProviderAccount = $configProviderAccount; - $this->configProviderBuckarooFee = $configProviderBuckarooFee; - $this->configProviderMethodFactory = $configProviderMethodFactory; - $this->priceCurrency = $priceCurrency; - $this->catalogHelper = $catalogHelper; - - $this->groupTransaction = $groupTransaction; - $this->logging = $logging; - $this->taxCalculation = $taxCalculation; - } - - /** - * Collect grand total address amount - * - * @param \Magento\Quote\Model\Quote $quote - * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment - * @param \Magento\Quote\Model\Quote\Address\Total $total - * @return $this - * - * @throws \LogicException - */ - public function collect( - \Magento\Quote\Model\Quote $quote, - \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, - \Magento\Quote\Model\Quote\Address\Total $total - ) { - - /** - * @noinspection PhpUndefinedMethodInspection - */ - $total->setBuckarooFee(0); - /** - * @noinspection PhpUndefinedMethodInspection - */ - $total->setBaseBuckarooFee(0); - - $orderId = $quote->getReservedOrderId(); - if ($this->groupTransaction->getAlreadyPaid($orderId) > 0) { - return $this; - } - - if (!$shippingAssignment->getItems()) { - return $this; - } - - $paymentMethod = $quote->getPayment()->getMethod(); - if (!$paymentMethod || strpos($paymentMethod, 'buckaroo_magento2_') !== 0) { - return $this; - } - - $methodInstance = $quote->getPayment()->getMethodInstance(); - if (!$methodInstance instanceof \Buckaroo\Magento2\Model\Method\AbstractMethod) { - return $this; - } - - $basePaymentFeeOLD = $this->getBaseFee($methodInstance, $quote); - $basePaymentFee = $total->getBaseBuckarooFeeInclTax() - $total->getBuckarooFeeBaseTaxAmount(); - - if ($basePaymentFee < 0.01) { - return $this; - } - - $paymentFee = $this->priceCurrency->convert($basePaymentFee, $quote->getStore()); - - /** - * @noinspection PhpUndefinedMethodInspection - */ - $quote->setBuckarooFee($paymentFee); - /** - * @noinspection PhpUndefinedMethodInspection - */ - $quote->setBaseBuckarooFee($basePaymentFee); - - /** - * @noinspection PhpUndefinedMethodInspection - */ - $total->setBuckarooFee($paymentFee); - /** - * @noinspection PhpUndefinedMethodInspection - */ - $total->setBaseBuckarooFee($basePaymentFee); - - /** - * @noinspection PhpUndefinedMethodInspection - */ - $total->setBaseGrandTotal($total->getBaseGrandTotal() + $basePaymentFee); - /** - * @noinspection PhpUndefinedMethodInspection - */ - $total->setGrandTotal($total->getGrandTotal() + $paymentFee); - - return $this; - } - - /** - * Add buckaroo fee information to address - * - * @param \Magento\Quote\Model\Quote $quote - * @param \Magento\Quote\Model\Quote\Address\Total $total - * @return $this - */ - public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) - { - /** - * @noinspection PhpUndefinedMethodInspection - */ - $totals = [ - 'code' => $this->getCode(), - 'title' => $this->getLabel(), - 'buckaroo_fee_hyva' => ['buckaroo_fee' => [$total->getBuckarooFee()]], - 'value' => $total->getBuckarooFee(), - 'base_buckaroo_fee' => $total->getBaseBuckarooFee(), - 'buckaroo_fee_incl_tax' => $total->getBuckarooFeeInclTax(), - 'base_buckaroo_fee_incl_tax' => $total->getBaseBuckarooFeeInclTax(), - 'buckaroo_fee_tax_amount' => $total->getBuckarooFeeTaxAmount(), - 'buckaroo_fee_base_tax_amount' => $total->getBuckarooFeeBaseTaxAmount(), - ]; - - - return $totals; - } - - /** - * @param \Buckaroo\Magento2\Model\Method\AbstractMethod $methodInstance - * @param \Magento\Quote\Model\Quote $quote - * @param bool $inclTax - * - * @return bool|false|float - * @throws \Buckaroo\Magento2\Exception - */ - public function getBaseFee( - \Buckaroo\Magento2\Model\Method\AbstractMethod $methodInstance, - \Magento\Quote\Model\Quote $quote, - $inclTax = false - ) { - $buckarooPaymentMethodCode = $methodInstance->buckarooPaymentMethodCode; - if (!$this->configProviderMethodFactory->has($buckarooPaymentMethodCode)) { - return false; - } - - $configProvider = $this->configProviderMethodFactory->get($buckarooPaymentMethodCode); - $basePaymentFee = trim($configProvider->getPaymentFee($quote->getStore())); - - if (is_numeric($basePaymentFee)) { - if (in_array($buckarooPaymentMethodCode, ['billink','afterpay20','afterpay','paypal'])) { - - $inclTax = $this->configProviderBuckarooFee->getPaymentFeeTax() == - Calculation::DISPLAY_TYPE_INCLUDING_TAX; - - if ($inclTax) { - $request = $this->taxCalculation->getRateRequest(null, null, null, $quote->getStore()); - $taxClassId = $this->configProviderBuckarooFee->getTaxClass($quote->getStore()); - $percent = $this->taxCalculation->getRate($request->setProductClassId($taxClassId)); - if ($percent > 0) { - return $basePaymentFee / (1 + ($percent / 100)); - } - } - return $basePaymentFee; - } else { - if ($inclTax) { - return $basePaymentFee; - } - /** - * Payment fee is a number - */ - return $this->getFeePrice($basePaymentFee); - } - - } elseif (strpos($basePaymentFee, '%') === false) { - /** - * Payment fee is invalid - */ - return false; - } - - /** - * Payment fee is a percentage - */ - $percentage = floatval($basePaymentFee); - if ($quote->getShippingAddress()) { - $address = $quote->getShippingAddress(); - } else { - $address = $quote->getBillingAddress(); - } - - $total = 0; - - $feePercentageMode = $this->configProviderAccount->getFeePercentageMode($quote->getStore()); - - switch ($feePercentageMode) { - case 'subtotal': - $total = $address->getBaseSubtotal(); - break; - case 'subtotal_incl_tax': - $total = $address->getBaseSubtotalTotalInclTax(); - break; - } - - $basePaymentFee = ($percentage / 100) * $total; - - return $basePaymentFee; - } - - /** - * Get payment fee price with correct tax - * - * @param float $price - * @param null $priceIncl - * - * @param \Magento\Framework\DataObject|null $pseudoProduct - * - * @return float - * @throws \Buckaroo\Magento2\Exception - */ - public function getFeePrice($price, $priceIncl = null, \Magento\Framework\DataObject $pseudoProduct = null) - { - if ($pseudoProduct === null) { - $pseudoProduct = new \Magento\Framework\DataObject(); - } - - $pseudoProduct->setTaxClassId($this->configProviderBuckarooFee->getTaxClass()); - - /** - * @noinspection PhpUndefinedMethodInspection - */ - if ($priceIncl === null - && $this->configProviderBuckarooFee->getPaymentFeeTax() == Calculation::DISPLAY_TYPE_INCLUDING_TAX - ) { - $priceIncl = true; - } else { - $priceIncl = false; - } - - $price = $this->catalogHelper->getTaxPrice( - $pseudoProduct, - $price, - false, - null, - null, - null, - null, - $priceIncl - ); - - return $price; - } - - /** - * Get Buckaroo label - * - * @return \Magento\Framework\Phrase - */ - public function getLabel() - { - return __('Fee'); - } -} diff --git a/etc/sales.xml b/etc/sales.xml index a884141fb..efc9fdc18 100644 --- a/etc/sales.xml +++ b/etc/sales.xml @@ -25,9 +25,6 @@ - - -