- |
+ getSource()->getBuckarooFeeLabel() ?: __('Payment fee') ?> |
displayPrices($block->getSource()->getBaseBuckarooFee(), $block->getSource()->getBuckarooFee()); ?>
|
diff --git a/view/frontend/web/js/model/buckaroo-fee.js b/view/frontend/web/js/model/buckaroo-fee.js
deleted file mode 100644
index 6742a9f34..000000000
--- a/view/frontend/web/js/model/buckaroo-fee.js
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-/*global define*/
-define(
- [
-
- ],
- function () {
- "use strict";
-
- var buckarooFeeConfig = window.buckarooConfig ?
- window.buckarooConfig.buckarooFee :
- window.checkoutConfig.buckarooFee;
-
- return function (itemId) {
- return {
- itemId: itemId,
-
- /**
- * @param key
- * @returns {*}
- */
- getConfigValue: function (key) {
- return buckarooFeeConfig[key];
- },
-
- /**
- * @returns {window.buckarooConfig.priceFormat|*|mage.configurable.options.priceFormat|.options.priceFormat|priceFormat}
- */
- getPriceFormat: function () {
- return window.buckarooConfig.priceFormat;
- },
-
- /**
- * Get buckaroo fee price display mode.
- *
- * @returns {Boolean}
- */
- displayBothPrices: function () {
- return !!buckarooFeeConfig.cart.displayBuckarooFeeBothPrices;
- },
-
- /**
- * Get buckaroo fee price display mode.
- *
- * @returns {Boolean}
- */
- displayInclTaxPrice: function () {
- return !!buckarooFeeConfig.cart.displayBuckarooFeeInclTax;
- }
- };
- };
- }
-);
diff --git a/view/frontend/web/js/view/checkout/cart/totals/buckaroo_fee.js b/view/frontend/web/js/view/checkout/cart/totals/buckaroo_fee.js
index 3007da192..589d47f7d 100644
--- a/view/frontend/web/js/view/checkout/cart/totals/buckaroo_fee.js
+++ b/view/frontend/web/js/view/checkout/cart/totals/buckaroo_fee.js
@@ -15,17 +15,17 @@ define(
template: 'Buckaroo_Magento2/cart/totals/buckaroo_fee'
},
/**
- * @override
- *
- * @returns {boolean}
- */
+ * @override
+ *
+ * @returns {boolean}
+ */
isDisplayed: function () {
return true;
},
/**
- * @override
- */
+ * @override
+ */
isFullMode: function () {
return true;
}
diff --git a/view/frontend/web/js/view/checkout/summary/already-paid.js b/view/frontend/web/js/view/checkout/summary/already-paid.js
index 189a9e139..46568a317 100644
--- a/view/frontend/web/js/view/checkout/summary/already-paid.js
+++ b/view/frontend/web/js/view/checkout/summary/already-paid.js
@@ -34,9 +34,6 @@ define([
}
return parseFloat(buckarooFeeSegment.value).toFixed(2);
- },
- getFormattedPrice: function (price) {
- return priceUtils.formatPrice(price, quote.getPriceFormat());
}
});
});
diff --git a/view/frontend/web/js/view/checkout/summary/remaining-amount.js b/view/frontend/web/js/view/checkout/summary/remaining-amount.js
index 9a12ae4f2..e79c72142 100644
--- a/view/frontend/web/js/view/checkout/summary/remaining-amount.js
+++ b/view/frontend/web/js/view/checkout/summary/remaining-amount.js
@@ -29,9 +29,6 @@ define([
},
getTitle: function () {
return this.title;
- },
- getFormattedPrice: function (price) {
- return priceUtils.formatPrice(price, quote.getPriceFormat());
}
});
});
diff --git a/view/frontend/web/js/view/summary/totals.js b/view/frontend/web/js/view/summary/totals.js
index 189240767..b4c5957c7 100644
--- a/view/frontend/web/js/view/summary/totals.js
+++ b/view/frontend/web/js/view/summary/totals.js
@@ -3,169 +3,136 @@
* See COPYING.txt for license details.
*/
/*global define*/
-define(
- [
- 'jquery',
- 'Magento_Checkout/js/view/summary/abstract-total',
- 'Magento_Checkout/js/model/quote',
- 'Magento_Checkout/js/model/totals',
- 'Buckaroo_Magento2/js/model/buckaroo-fee',
- 'Magento_Ui/js/model/messageList',
- 'mage/translate',
- 'Magento_Ui/js/modal/alert',
- 'ko',
- 'mage/url'
- ],
- function ($, Component, quote, totals, BuckarooFee, globalMessageList, $t, alert, ko, url) {
- 'use strict';
-
- return Component.extend(
- {
- defaults : {
- template : 'Buckaroo_Magento2/summary/buckaroo_fee'
- },
- totals : quote.getTotals(),
- model : {},
- excludingTaxMessage : '(Excluding Tax)',
- includingTaxMessage : '(Including Tax)',
-
- /**
- * @override
- */
- initialize : function (options) {
- this.model = new BuckarooFee();
-
- window.checkoutConfig.buckarooFee.title = ko.observable(options.title);
-
- return this._super(options);
- },
-
- /**
- * Get buckaroo fee price based on options.
- *
- * @returns {int}
- */
- getValue : function () {
- var price = 0,
- buckarooFeeSegment;
-
- if (this.totals()
- && totals.getSegment('buckaroo_fee')
- && totals.getSegment('buckaroo_fee').hasOwnProperty('extension_attributes')
- ) {
- buckarooFeeSegment = totals.getSegment('buckaroo_fee')['extension_attributes'];
-
- price = buckarooFeeSegment.hasOwnProperty('buckaroo_fee') ?
- buckarooFeeSegment['buckaroo_fee'] :
- 0;
- }
-
- return this.getFormattedPrice(price);
- },
-
- /**
- * Get buckaroo fee price (including tax) based on options.
- *
- * @returns {int}
- */
- getIncludingTaxValue : function () {
- var price = 0,
- buckarooFeeSegment;
-
- if (this.totals()
- && totals.getSegment('buckaroo_fee')
- && totals.getSegment('buckaroo_fee').hasOwnProperty('extension_attributes')
- ) {
- buckarooFeeSegment = totals.getSegment('buckaroo_fee')['extension_attributes'];
-
- price = buckarooFeeSegment.hasOwnProperty('buckaroo_fee_incl_tax') ?
- buckarooFeeSegment['buckaroo_fee_incl_tax'] :
- 0;
- }
-
- return this.getFormattedPrice(price);
- },
-
- /**
- * Check buckaroo fee option availability.
- *
- * @returns {Boolean}
- */
- isAvailable : function () {
- var isAvailable = false;
+define([
+ 'jquery',
+ 'Magento_Checkout/js/view/summary/abstract-total',
+ 'Magento_Checkout/js/model/quote',
+ 'Magento_Checkout/js/model/totals',
+ 'Magento_Ui/js/model/messageList',
+ 'mage/translate',
+ 'Magento_Ui/js/modal/alert',
+ 'ko'
+],
+function ($, Component, quote, totals , globalMessageList, $t, alert, ko) {
+ 'use strict';
+
+ return Component.extend({
+ defaults : {
+ template : 'Buckaroo_Magento2/summary/buckaroo_fee'
+ },
+ totals : quote.getTotals(),
+
+ /**
+ * @override
+ */
+ initialize : function (options) {
+ this._super();
+
+ window.checkoutConfig.buckarooFee.title = ko.observable(options.title);
+
+ quote.paymentMethod.subscribe(this.updateFeeVisibility.bind(this));
+
+ return this;
+ },
+
+ /**
+ * Update visibility of the Buckaroo fee based on payment method.
+ */
+ updateFeeVisibility: function (paymentMethod) {
+ if (!this.hasFee(paymentMethod)) {
+ // Clear the fee segment if the selected payment method has no fee
+ totals.getSegment('buckaroo_fee', null);
+ }
+ totals.isLoading(true); // Force totals to recalculate
+ },
+
+ /**
+ * Determine if the selected payment method includes a fee.
+ */
+ hasFee: function (paymentMethod) {
+ return paymentMethod && paymentMethod.method && paymentMethod.method.includes('buckaroo');
+ },
+
+ /**
+ * Get buckaroo fee price based on options.
+ *
+ * @returns {int}
+ */
+ getValue : function () {
+ var price = 0,
+ buckarooFeeSegment;
+ if (this.totals()
+ && totals.getSegment('buckaroo_fee')
+ && totals.getSegment('buckaroo_fee').hasOwnProperty('extension_attributes')
+ ) {
+ buckarooFeeSegment = totals.getSegment('buckaroo_fee')['extension_attributes'];
+
+ price = buckarooFeeSegment.hasOwnProperty('buckaroo_fee') ?
+ buckarooFeeSegment['buckaroo_fee'] :
+ 0;
+ }
- if (!this.isFullMode()) {
- return false;
- }
+ return this.getFormattedPrice(price);
+ },
+
+ /**
+ * Check buckaroo fee option availability.
+ *
+ * @returns {Boolean}
+ */
+ isAvailable : function () {
+ var isAvailable = false;
+ if (!this.isFullMode()) {
+ return false;
+ }
- if (this.totals()
- && totals.getSegment('buckaroo_fee')
- && totals.getSegment('buckaroo_fee').hasOwnProperty('extension_attributes')
- ) {
- isAvailable = (0 < totals.getSegment('buckaroo_fee')['extension_attributes'].buckaroo_fee);
- }
+ if (this.totals()
+ && totals.getSegment('buckaroo_fee')
+ && totals.getSegment('buckaroo_fee').hasOwnProperty('extension_attributes')
+ ) {
+ isAvailable = (0 < totals.getSegment('buckaroo_fee')['extension_attributes'].buckaroo_fee);
+ }
- return isAvailable;
- },
-
- /**
- * Check if both buckaroo fee prices should be displayed.
- *
- * @returns {Boolean}
- */
- displayBothPrices : function () {
- return (true == this.model.displayBothPrices());
- },
-
- /**
- * Check if buckaroo fee prices should be displayed including tax.
- *
- * @returns {Boolean}
- */
- displayPriceInclTax : function () {
- var displayPriceInclTax = this.model.displayInclTaxPrice();
-
- return displayPriceInclTax && !this.displayBothPrices();
- },
-
- /**
- * Check if buckaroo fee prices should be displayed excluding tax.
- *
- * @returns {Boolean}
- */
- displayPriceExclTax : function () {
- return !this.displayPriceInclTax() && !this.displayBothPrices();
- },
-
- getTitle : function () {
- return window.checkoutConfig.buckarooFee.title();
- },
-
- getAlreadyPayTitle : function () {
- return 'Paid with Giftcard';
- },
-
- getAlreadyPayValue : function () {
- var buckarooFeeSegment = totals.getSegment('buckaroo_already_paid');
- try {
- if (buckarooFeeSegment.title) {
- var items = JSON.parse(buckarooFeeSegment.title);
- if ((typeof items === 'object') && (items.length > 0)) {
- for (var i = 0; i < items.length; i++) {
- items[i].amount = this.getFormattedPrice(items[i].amount);
- }
- return items;
- }
+ return isAvailable;
+ },
+
+ getTitle : function () {
+ return window.checkoutConfig.buckarooFee.title();
+ },
+
+ /**
+ * Title for 'Paid with Giftcard' option.
+ *
+ * @returns {string}
+ */
+ getAlreadyPayTitle: function () {
+ return $t('Paid with Giftcard');
+ },
+
+ /**
+ * Get value for 'Paid with Giftcard'.
+ *
+ * @returns {string|boolean}
+ */
+ getAlreadyPayValue : function () {
+ var buckarooFeeSegment = totals.getSegment('buckaroo_already_paid');
+ try {
+ if (buckarooFeeSegment.title) {
+ var items = JSON.parse(buckarooFeeSegment.title);
+ if ((typeof items === 'object') && (items.length > 0)) {
+ for (var i = 0; i < items.length; i++) {
+ items[i].amount = this.getFormattedPrice(items[i].amount);
}
- } catch (e) {
- // console.log(e);
+ return items;
}
-
- return buckarooFeeSegment.value ?
- this.getFormattedPrice(buckarooFeeSegment.value) :
- false;
- },
+ }
+ } catch (e) {
+ // console.log(e);
}
- );
- }
-);
+
+ return buckarooFeeSegment.value ?
+ this.getFormattedPrice(buckarooFeeSegment.value) :
+ false;
+ },
+ });
+});
diff --git a/view/frontend/web/template/cart/totals/buckaroo_fee.html b/view/frontend/web/template/cart/totals/buckaroo_fee.html
index bd9e933f9..b4feb289b 100644
--- a/view/frontend/web/template/cart/totals/buckaroo_fee.html
+++ b/view/frontend/web/template/cart/totals/buckaroo_fee.html
@@ -1,27 +1,4 @@
-
-