Skip to content

Commit

Permalink
Merge pull request #1059 from buckaroo-it/BP-3778-The-transaction-cal…
Browse files Browse the repository at this point in the history
…culations-are-not-being-compiled-properly

BP-3778-The-transaction-calculations-are-not-being-compiled-properly
  • Loading branch information
vegimcarkaxhija authored Sep 20, 2024
2 parents e1f7ed4 + 9e28ea4 commit 5223fc9
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 49 deletions.
40 changes: 0 additions & 40 deletions Model/Total/Quote/BuckarooAlreadyPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
16 changes: 11 additions & 5 deletions view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
</item>
</item>
</item>
<item name="grand-total" xsi:type="array">
<item name="component" xsi:type="string">Buckaroo_Magento2/js/view/checkout/summary/grand-total</item>
<item name="config" xsi:type="array">
<item name="exclTaxLabel" xsi:type="string" translate="true">Order Total Excl. Tax</item>
<item name="inclTaxLabel" xsi:type="string" translate="true">Order Total Incl. Tax</item>
<item name="basicCurrencyMessage" xsi:type="string" translate="true">You will be charged for</item>
<item name="title" xsi:type="string" translate="true">Order Total</item>
</item>
</item>
</item>
</item>
</item>
Expand Down Expand Up @@ -133,13 +142,13 @@
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
<item name="buckaroo_magento2_eps" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
<item name="buckaroo_magento2_giftcards" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
<item name="children" xsi:type="array">
<item name="buckaroo_magento2_vvvgiftcard" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
</item>
</item>
Expand Down Expand Up @@ -200,9 +209,6 @@
<item name="buckaroo_magento2_knaken" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
<item name="buckaroo_magento2_blik" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
</item>
</item>
</item>
Expand Down
16 changes: 12 additions & 4 deletions view/frontend/web/js/action/place-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -143,4 +151,4 @@ define(
);
};
}
);
);
116 changes: 116 additions & 0 deletions view/frontend/web/js/view/checkout/summary/grand-total.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
});

0 comments on commit 5223fc9

Please sign in to comment.