Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions Model/Total/Quote/BuckarooAlreadyPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,46 @@ 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 All @@ -61,7 +101,7 @@ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Qu
$customTitle = [];
if ($orderId) {
$items = $this->groupTransaction->getGroupTransactionItemsNotRefunded($orderId);

foreach ($items as $giftcard) {
$foundGiftcard = $this->giftcardCollection->getItemByColumnValue(
'servicecode',
Expand All @@ -70,7 +110,7 @@ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Qu

if ($foundGiftcard !== null || $giftcard['servicecode'] === 'buckaroovoucher') {


if ($giftcard['servicecode'] === 'buckaroovoucher') {
$label = __('Voucher');
} else {
Expand Down
11 changes: 6 additions & 5 deletions Model/Total/Quote/BuckarooFee.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ public function collect(
\Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
\Magento\Quote\Model\Quote\Address\Total $total
) {
parent::collect($quote, $shippingAssignment, $total);

if (!$shippingAssignment->getItems()) {
return $this;
}
/**
* @noinspection PhpUndefinedMethodInspection
*/
Expand All @@ -123,11 +127,8 @@ public function collect(
$total->setBaseBuckarooFee(0);

$orderId = $quote->getReservedOrderId();
if ($this->groupTransaction->getAlreadyPaid($orderId) > 0) {
return $this;
}

if (!$shippingAssignment->getItems()) {
if ($this->groupTransaction->getAlreadyPaid($orderId) > 0) {
return $this;
}

Expand Down Expand Up @@ -175,7 +176,7 @@ public function collect(
/**
* @noinspection PhpUndefinedMethodInspection
*/
$total->setGrandTotal($total->getGrandTotal() + $paymentFee);
// $total->setGrandTotal($total->getGrandTotal() + $paymentFee);

return $this;
}
Expand Down
62 changes: 62 additions & 0 deletions Model/Total/Quote/BuckarooFeeHyva.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,68 @@ public function __construct(
$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
) {
parent::collect($quote, $shippingAssignment, $total);

// Ensure that shipping assignment has items, otherwise skip processing.
if (!$shippingAssignment->getItems()) {
return $this;
}

$orderId = $quote->getReservedOrderId();

// Check if already paid amount is affecting the calculation
if ($this->groupTransaction->getAlreadyPaid($orderId) > 0) {
// Optionally, you could log or debug here to ensure no early returns affect the fee calculation.
$this->logging->addDebug('Already paid detected, but continuing to add fee.');
}

// Ensure payment method is set correctly
$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;
}

// Calculate the base payment fee using the getBaseFee method
$basePaymentFee = $this->getBaseFee($methodInstance, $quote);
if ($basePaymentFee < 0.01) {
return $this;
}

// Convert the fee to the store's currency
$paymentFee = $this->priceCurrency->convert($basePaymentFee, $quote->getStore());

// Add fee amounts using addTotalAmount to ensure proper accumulation with other totals
$total->addTotalAmount('buckaroo_fee_hyva', $paymentFee);
$total->addBaseTotalAmount('buckaroo_fee_hyva', $basePaymentFee);

// Set the fee on the total object for further calculations
$total->setBuckarooFee($paymentFee);
$total->setBaseBuckarooFee($basePaymentFee);
$total->setGrandTotal($total->getGrandTotal() + $paymentFee);

return $this;
}

/**
* Add buckaroo fee information to address
*
Expand Down
9 changes: 0 additions & 9 deletions view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@
</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
116 changes: 0 additions & 116 deletions view/frontend/web/js/view/checkout/summary/grand-total.js

This file was deleted.

48 changes: 0 additions & 48 deletions view/frontend/web/js/view/summary/totals.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,54 +165,6 @@ define(
this.getFormattedPrice(buckarooFeeSegment.value) :
false;
},

removeGiftcard: function (transaction_id, servicecode, amount) {
self = this;
if (confirm('Are you sure you want to remove?')) {

$.ajax({
url: url.build("buckaroo/checkout/giftcard"),
type: 'POST',
dataType: 'json',
showLoader: true, //use for display loader
data: {
refund: transaction_id,
card: servicecode,
amount: amount,
}
}).done(function (data) {
if(data.error){
alert({
title: $t('Error'),
content: $t(data.error),
actions: {always: function(){} }
});
}else{
alert({
title: $t('Success'),
content: $t(data.message),
actions: {always: function(){} },
buttons: [{
text: $t(data.message),
class: 'action primary accept',
click: function () {
this.closeModal(true);
}
}]
});
}

var deferred = $.Deferred();
getTotalsAction([], deferred);
// $('.buckaroo_magento2_'+self.currentGiftcard+' input[name="payment[method]"]').click();

});

} else {
console.log('no');
}
}

}
);
}
Expand Down
Loading