From 9e28ea4c8200ec2c75126ab8f414bef78f98ff8d Mon Sep 17 00:00:00 2001 From: "v.carkaxhija" Date: Fri, 20 Sep 2024 09:10:21 +0200 Subject: [PATCH] remove credit card --- Model/Total/Quote/BuckarooAlreadyPay.php | 40 ------ view/frontend/layout/checkout_index_index.xml | 16 ++- view/frontend/web/js/action/place-order.js | 16 ++- .../js/view/checkout/summary/grand-total.js | 116 ++++++++++++++++++ 4 files changed, 139 insertions(+), 49 deletions(-) create mode 100644 view/frontend/web/js/view/checkout/summary/grand-total.js diff --git a/Model/Total/Quote/BuckarooAlreadyPay.php b/Model/Total/Quote/BuckarooAlreadyPay.php index d9f0024e5..c7bb6ccf5 100644 --- a/Model/Total/Quote/BuckarooAlreadyPay.php +++ b/Model/Total/Quote/BuckarooAlreadyPay.php @@ -47,46 +47,6 @@ public function __construct( $this->giftcardCollection = $giftcardCollection; } - /** - * 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 - ) { - parent::collect($quote, $shippingAssignment, $total); - - // Ensure that shipping assignment has items, otherwise skip processing. - if (!$shippingAssignment->getItems()) { - return $this; - } - - $orderId = $quote->getReservedOrderId(); - $alreadyPaidAmount = $this->groupTransaction->getAlreadyPaid($orderId); - - // Ensure totals are properly initialized. - $total->setTotalAmount($this->getCode(), 0); - $total->setBaseTotalAmount($this->getCode(), 0); - - // Adjust the grand total only if the already paid amount is greater than zero. - if ($alreadyPaidAmount > 0) { - $total->addTotalAmount($this->getCode(), -$alreadyPaidAmount); - $total->addBaseTotalAmount($this->getCode(), -$alreadyPaidAmount); - - } - - return $this; - } - - /** * Add buckaroo fee information to address * diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index 7f1b64222..2fd41041a 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -51,6 +51,15 @@ + + Buckaroo_Magento2/js/view/checkout/summary/grand-total + + Order Total Excl. Tax + Order Total Incl. Tax + You will be charged for + Order Total + + @@ -133,13 +142,13 @@ true - true + true true - true + true @@ -200,9 +209,6 @@ true - - true - diff --git a/view/frontend/web/js/action/place-order.js b/view/frontend/web/js/action/place-order.js index 94abd5983..598174558 100644 --- a/view/frontend/web/js/action/place-order.js +++ b/view/frontend/web/js/action/place-order.js @@ -119,10 +119,18 @@ define( }] }); $('.' + paymentData.method).remove(); - } else if (redirectOnSuccess) { - window.location.replace(url.build('checkout/onepage/success/')); + } else { + if (jsonResponse.buckaroo_response) { + window.checkoutConfig.payment.buckaroo.response = jsonResponse.buckaroo_response; + } else { + window.checkoutConfig.payment.buckaroo.response = jsonResponse; + } + + if (redirectOnSuccess) { + window.location.replace(url.build('checkout/onepage/success/')); + } } - window.checkoutConfig.payment.buckaroo.response = jsonResponse.buckaroo_response; + fullScreenLoader.stopLoader(); } ).fail( @@ -143,4 +151,4 @@ define( ); }; } -); \ No newline at end of file +); diff --git a/view/frontend/web/js/view/checkout/summary/grand-total.js b/view/frontend/web/js/view/checkout/summary/grand-total.js new file mode 100644 index 000000000..3c1c89431 --- /dev/null +++ b/view/frontend/web/js/view/checkout/summary/grand-total.js @@ -0,0 +1,116 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +/** + * @api + */ + +define([ + 'Magento_Checkout/js/view/summary/abstract-total', + 'Magento_Checkout/js/model/quote', + 'Magento_Catalog/js/price-utils', + 'Magento_Checkout/js/model/totals' +], function (Component, quote, priceUtils, totals) { + 'use strict'; + + return Component.extend({ + defaults: { + isFullTaxSummaryDisplayed: window.checkoutConfig.isFullTaxSummaryDisplayed || false, + template: 'Buckaroo_Magento2/checkout/summary/grand-total' + }, + totals: quote.getTotals(), + isTaxDisplayedInGrandTotal: window.checkoutConfig.includeTaxInGrandTotal || false, + + /** + * @return {*} + */ + isDisplayed: function () { + return this.isFullMode(); + }, + + /** + * @return {*|String} + */ + getValue: function () { + var price = 0; + + if (this.totals()) { + price = totals.getSegment('grand_total').value; + + if(!isNaN(parseFloat(this.getAlreadyPayTotal()))){ + price = parseFloat(price) - parseFloat(this.getAlreadyPayTotal()); + } + } + + return this.getFormattedPrice(price); + }, + + /** + * @return {*|String} + */ + getBaseValue: function () { + var price = 0; + + if (this.totals()) { + price = this.totals()['base_grand_total']; + } + + return priceUtils.formatPriceLocale(price, quote.getBasePriceFormat()); + }, + + /** + * @return {*} + */ + getGrandTotalExclTax: function () { + var total = this.totals(), + amount; + + if (!total) { + return 0; + } + + amount = total['grand_total'] - total['tax_amount']; + + if (amount < 0) { + amount = 0; + } + + return this.getFormattedPrice(amount); + }, + + /** + * @return {Boolean} + */ + isBaseGrandTotalDisplayNeeded: function () { + var total = this.totals(); + + if (!total) { + return false; + } + + return total['base_currency_code'] != total['quote_currency_code']; //eslint-disable-line eqeqeq + }, + + getAlreadyPayTotal : function () { + var buckarooFeeSegment = totals.getSegment('buckaroo_already_paid'); + try { + if (buckarooFeeSegment.title) { + var items = JSON.parse(buckarooFeeSegment.title); + var total = 0; + if ((typeof items === 'object') && (items.length > 0)) { + for (var i = 0; i < items.length; i++) { + total = parseFloat(total) + parseFloat(items[i].serviceamount); + } + return parseFloat(total).toFixed(2); + } + } + } catch (e) { + // console.log(e); + } + + return parseFloat(buckarooFeeSegment.value).toFixed(2); + } + }); +});