Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop' into BP-3772-Support-Buckaroo-Hoste…
Browse files Browse the repository at this point in the history
…d-Fields-for-credit-debitcards
  • Loading branch information
vegimcarkaxhija committed Nov 6, 2024
2 parents b7f814a + 0201542 commit d9409c7
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 100 deletions.
33 changes: 31 additions & 2 deletions Magewire/Payment/Method/Giftcards.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Buckaroo\Magento2\Model\Giftcard\Response\Giftcard as GiftcardResponse;
use Buckaroo\Magento2\Model\Giftcard\Request\GiftcardInterface as GiftcardRequest;
use Buckaroo\Magento2\Model\ConfigProvider\Method\Giftcards as MethodConfigProvider;
use Magento\Framework\Pricing\Helper\Data as PricingHelper;

class Giftcards extends Component\Form implements EvaluationInterface
{
Expand All @@ -34,6 +35,7 @@ class Giftcards extends Component\Form implements EvaluationInterface
protected GiftcardResponse $giftcardResponse;

protected Log $logger;
protected $pricingHelper;

public function __construct(
UrlInterface $urlBuilder,
Expand All @@ -42,7 +44,8 @@ public function __construct(
MethodConfigProvider $methodConfigProvider,
GiftcardRequest $giftcardRequest,
GiftcardResponse $giftcardResponse,
Log $logger
Log $logger,
PricingHelper $pricingHelper
) {
$this->urlBuilder = $urlBuilder;
$this->sessionCheckout = $sessionCheckout;
Expand All @@ -51,6 +54,7 @@ public function __construct(
$this->giftcardRequest = $giftcardRequest;
$this->giftcardResponse = $giftcardResponse;
$this->logger = $logger;
$this->pricingHelper = $pricingHelper;
}

/**
Expand Down Expand Up @@ -150,7 +154,32 @@ public function applyGiftcard(
}
}

/**
* Convert and format price value for current store
*
* @param float $price
* @return float|string
*/
public function getFormattedPrice($price)
{
return $this->pricingHelper->currency($price, true, false);
}

public function getRemainingAmount()
{
$quote = $this->sessionCheckout->getQuote();

$grandTotal = round(floatval($quote->getGrandTotal()), 2);

// Get the amount already paid through group transactions
$alreadyPaid = $this->groupTransaction->getAlreadyPaid($quote->getReservedOrderId());

// Calculate the remaining amount
$remainingAmount = $grandTotal - $alreadyPaid;

// Ensure the remaining amount is never negative
$this->emit("remainingAmount", $this->getFormattedPrice($remainingAmount));
}
protected function getGiftcardResponse(Quote $quote, $response)
{
$this->giftcardResponse->set($response, $quote);
Expand Down Expand Up @@ -183,8 +212,8 @@ protected function getGiftcardResponse(Quote $quote, $response)
$this->giftcardResponse->getCurrency()
);
}

return [
'remainder_amount_currency' => $this->getFormattedPrice($remainingAmount),
'remainder_amount' => $remainingAmount,
'already_paid' => $this->giftcardResponse->getAlreadyPaid($quote),
'remaining_amount_message' => $buttonMessage,
Expand Down
85 changes: 0 additions & 85 deletions Magewire/Payment/Method/Giropay.php

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Buckaroo has developed a cutting-edge Hyvä Checkout module as an extension for
<br>

## Requirements
* [Buckaroo Magento 2 plugin](https://github.com/buckaroo-it/Magento2/releases) version 1.46 or higher
* [Buckaroo Magento 2 plugin](https://github.com/buckaroo-it/Magento2/releases) version 1.50.1 or higher
* Hyvä Checkout version 1.1.8 or higher
<br>

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "buckaroo/magento2-hyva-checkout",
"description": "Buckaroo Magento 2 hyva checkout extension",
"require": {
"php": ">=8.1"
"php": ">=8.1",
"buckaroo/magento2": ">=1.50.1"
},
"type": "magento2-module",
"license": "CC-BY-NC-ND-3.0",
Expand All @@ -20,7 +21,7 @@
"docs": "https://support.buckaroo.nl"
},
"homepage": "https://www.buckaroo.nl",
"version" : "v1.1.3",
"version" : "v1.2.0",
"minimum-stability": "stable",
"autoload": {
"files": [
Expand Down
3 changes: 1 addition & 2 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<item name="buckaroo_magento2_afterpay20" xsi:type="object">\Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService</item>
<item name="buckaroo_magento2_billink" xsi:type="object">\Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService</item>
<item name="buckaroo_magento2_capayablein3" xsi:type="object">\Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService</item>
<item name="buckaroo_magento2_giropay" xsi:type="object">\Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService</item>
<item name="buckaroo_magento2_tinka" xsi:type="object">\Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService</item>
<item name="buckaroo_magento2_sepadirectdebit" xsi:type="object">\Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService</item>
<item name="buckaroo_magento2_payperemail" xsi:type="object">\Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService</item>
Expand All @@ -41,7 +40,7 @@
</argument>
</arguments>
</type>
<type name="Hyva\Checkout\Model\Form\EntityFormFieldFactory">
<type name="Hyva\Checkout\Model\Form\EntityFormFieldFactory">
<arguments>
<!-- Hide idin customer fields -->
<argument name="customFields" xsi:type="array">
Expand Down
6 changes: 6 additions & 0 deletions view/frontend/layout/hyva_checkout_cart_index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="buckaroo_magento2.checkout.cart.ideal.fast.checkout" remove="true" />
</body>
</page>
3 changes: 3 additions & 0 deletions view/frontend/layout/hyva_checkout_components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@
class="Buckaroo\HyvaCheckout\Block\Totals\AlreadyPaid"
as="buckaroo_already_paid"
template="Buckaroo_HyvaCheckout::total-segments/already-paid.phtml"/>
<block name="price-summary.total-segment.remaining_amount"
as="remaining_amount"
template="Buckaroo_HyvaCheckout::checkout/summary/remaining-amount.phtml"/>
</referenceBlock>
</body>
</page>
2 changes: 1 addition & 1 deletion view/frontend/layout/hyva_checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
</block>
</referenceContainer>
</body>
</page>
</page>
29 changes: 29 additions & 0 deletions view/frontend/templates/checkout/summary/remaining-amount.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);


/** @var Template $block */
/** @var FormatterViewModel $formatterViewModel */
/** @var ViewModelRegistry $viewModels */
/** @var Escaper $escaper */

use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;
use Hyva\Checkout\ViewModel\Checkout\Formatter as FormatterViewModel;
use Hyva\Theme\Model\ViewModelRegistry;

$formatterViewModel = $viewModels->require(FormatterViewModel::class);
$segment = $block->getSegment();
if ($segment['value'] != 0) {
?>
<div class="flex gap-4 justify-between border-t border-gray-400 pt-4 mt-4 md:gap-0">
<span class="label font-bold text-xl">
<?= $block->escapeHtml($segment['title']) ?>
</span>
<span class="value text-right font-bold">
<?= /* @noEscape */ $formatterViewModel->currency($segment['value'] ?? 0) ?>
</span>
</div>
<?php
}
42 changes: 35 additions & 7 deletions view/frontend/templates/component/payment/after.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
function updatePosition() {
// Select the elements by their class names
const alreadyPaidElement = document.querySelector('.remaining_amount');
const grandTotalElement = document.querySelector('.grand_total');

// Ensure both elements exist before trying to move them
if (alreadyPaidElement && grandTotalElement) {
// Move the 'already-paid' block after the 'grand-total' block
grandTotalElement.insertAdjacentElement('afterend', alreadyPaidElement);
}
}

updatePosition();

document.querySelectorAll('input[name="payment-method-option"]').forEach((input) => {
input.addEventListener('change', function() {
setTimeout(function() {
updatePosition();
}, 2000);
});
});
});


var buckaroo = {
modal() {
Expand All @@ -71,7 +95,7 @@
title: '<?= $escaper->escapeHtml(__('Success')); ?>',
content: '',
showClose: true,
buttons:[],
buttons: [],
close() {
this.showModal = false;
},
Expand All @@ -82,28 +106,29 @@
this.showModal = true;
Object.keys(event.detail.data).forEach((key) => {
this[key] = event.detail.data[key];
})
});
}
});

window.addEventListener('buckaroo-modal-hide', () => {
this.close();
});
}
}
};
},
start() {
const addTask = function() {
hyvaCheckout.navigation.addTask(async () => {
if (window.buckarooTask) {
await window.buckarooTask();
}
})
}
});
};
addTask();
window.addEventListener('checkout:navigation:success', (event) => {
if (event.detail.route === 'payment')
if (event.detail.route === 'payment') {
addTask();
}
});


Expand Down Expand Up @@ -427,6 +452,9 @@
} else if (response.remainder_amount != 0) {
this.displaySuccess(response);
}
setTimeout(function () {
updatePosition();
}, 2000);
})
},
register() {
Expand Down Expand Up @@ -566,4 +594,4 @@
}
}

</script>
</script>

0 comments on commit d9409c7

Please sign in to comment.