Skip to content

Commit

Permalink
Add Klarna support
Browse files Browse the repository at this point in the history
  • Loading branch information
nickyrvvup committed Dec 4, 2024
1 parent a4f805e commit e252da8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Magewire/Checkout/Payment/KlarnaProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Rvvup\PaymentsHyvaCheckout\Magewire\Checkout\Payment;

class KlarnaProcessor extends AbstractProcessor
{
public function getMethodCode(): string
{
return 'rvvup_KLARNA';
}

public function placeOrder(): void
{
$this->loadPaymentActions();
$redirectUrl = $this->getRedirectUrl();
$this->redirect($redirectUrl);
}
}
11 changes: 11 additions & 0 deletions src/view/frontend/layout/hyva_checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@
</arguments>
</block>

<block name="checkout.payment.method.rvvup.klarna-processor"
as="rvvup.klarna-processor"
template="Rvvup_PaymentsHyvaCheckout::component/payment/klarna-processor.phtml"
after="hyva.checkout.main">
<arguments>
<argument name="magewire" xsi:type="object">
Rvvup\PaymentsHyvaCheckout\Magewire\Checkout\Payment\KlarnaProcessor
</argument>
</arguments>
</block>

<block name="checkout.payment.method.rvvup.assets"
as="rvvup.assets"
template="Rvvup_PaymentsHyvaCheckout::component/payment/assets.phtml"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);

use Magento\Framework\View\Element\Template;
use Magento\Framework\Escaper;

/** @var Template $block */
/** @var Escaper $escaper */
/** @var \Rvvup\PaymentsHyvaCheckout\Magewire\Checkout\Payment\ClearpayProcessor $magewire */
?>
<div wire:ignore>
<script>
(() => {
window.addEventListener('checkout:payment:method-activate', event => {
if (event.detail.method !== 'rvvup_KLARNA') {
return;
}

const component = Magewire.find('<?= $escaper->escapeJs($block->getNameInLayout()) ?>');
hyvaCheckout.payment.activate('rvvup_KLARNA', {
placeOrderViaJs() {
return document.querySelector('[wire\\:key="rvvup_KLARNA"].active') !== null;
},

placeOrder() {
return component.placeOrder();
}
}, document.querySelector('[wire\\:key="rvvup_KLARNA"].active'));
});
})();
</script>
</div>

0 comments on commit e252da8

Please sign in to comment.