Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECP-9544] Support all Oney/Facilypay variants #78

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "1.2.2",
"license": "MIT",
"require": {
"adyen/module-payment": "^9.6.1",
"adyen/module-payment": "^9.12.0",
"hyva-themes/magento2-default-theme": "^1.3",
"hyva-themes/magento2-hyva-checkout": "^1.1"
},
Expand Down
4 changes: 4 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<item name="adyen_affirm" xsi:type="string">adyen-affirm-method.phtml</item>
<item name="adyen_amazonpay" xsi:type="string">adyen-amazonpay-method.phtml</item>
<item name="adyen_facilypay_3x" xsi:type="string">adyen-facilypay-3x-method.phtml</item>
<item name="adyen_facilypay_4x" xsi:type="string">adyen-facilypay-method.phtml</item>
<item name="adyen_facilypay_6x" xsi:type="string">adyen-facilypay-method.phtml</item>
<item name="adyen_facilypay_10x" xsi:type="string">adyen-facilypay-method.phtml</item>
<item name="adyen_facilypay_12x" xsi:type="string">adyen-facilypay-method.phtml</item>
</argument>
<argument name="customMagewireClasses" xsi:type="array">
<item name="adyen_cc" xsi:type="object">Adyen\Hyva\Magewire\Payment\Method\CreditCard</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use Magento\Framework\View\Element\Template;
/** @var Template $block */
/** @var Escaper $escaper */

/**
* @deprecated This file will be removed on V2. Use `adyen-facilypay-method.phtml` instead.
*/
?>

<div>
Expand Down Expand Up @@ -81,6 +84,8 @@ use Magento\Framework\View\Element\Template;
};
}

debugger;

return baseComponentConfiguration;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php
use Adyen\Hyva\Magewire\Payment\Method\AbstractPaymentMethodWire;
use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;

/** @var AbstractPaymentMethodWire $magewire */
/** @var Template $block */
/** @var Escaper $escaper */

?>

<div>

<div id="<?= $escaper->escapeHtml($magewire->getContainerName()) ?>ActionContainer" wire:ignore></div>

<script>
class facilypayComponentHandler extends componentHandler {
constructor(paymentMethodCode, wire, elementLabel) {
super(paymentMethodCode, wire, elementLabel);
}

buildConfiguration(paymentMethod, paymentMethodsExtraInfo) {
let baseComponentConfiguration = super.buildConfiguration(paymentMethod, paymentMethodsExtraInfo);

let formattedShippingAddress = {};
let formattedBillingAddress = {};
let shopperDateOfBirth = '';
let email = '';

const shippingAddress = this.wire.get('shippingAddress');
const billingAddress = this.wire.get('billingAddress');
const quoteData = this.wire.get('quoteData');
const customerData = this.wire.get('customerData');


if (customerData) {
const parsedCustomerData = JSON.parse(customerData);
shopperDateOfBirth = parsedCustomerData.shopper_date_of_birth || '';
email = parsedCustomerData.email || '';
}

if (!email && quoteData) {
const parsedQuoteData = JSON.parse(quoteData);
email = parsedQuoteData.shopper_email || '';
}

if (shippingAddress) {
formattedShippingAddress = this.getFormattedAddress(JSON.parse(shippingAddress));
}

if (billingAddress) {
formattedBillingAddress = this.getFormattedAddress(JSON.parse(billingAddress));
}

baseComponentConfiguration.data = {};

if (formattedShippingAddress) {
baseComponentConfiguration.data.deliveryAddress = {
city: formattedShippingAddress.city,
country: formattedShippingAddress.country,
houseNumberOrName: formattedShippingAddress.houseNumber,
postalCode: formattedShippingAddress.postalCode,
street: formattedShippingAddress.street
};
}

if (formattedBillingAddress) {
baseComponentConfiguration.data.personalDetails = {
firstName: formattedBillingAddress.firstName,
lastName: formattedBillingAddress.lastName,
telephoneNumber: formattedBillingAddress.telephone,
shopperEmail: email,
dateOfBirth: shopperDateOfBirth,
};
baseComponentConfiguration.data.billingAddress = {
city: formattedBillingAddress.city,
country: formattedBillingAddress.country,
houseNumberOrName: formattedBillingAddress.houseNumber,
postalCode: formattedBillingAddress.postalCode,
street: formattedBillingAddress.street,
};
}

debugger;

return baseComponentConfiguration;
}
}

window.addEventListener('checkout:payment:method-list-boot', async (event) => {
unmountAdyenComponent();
await init(event.detail.method);
});

window.addEventListener('checkout:payment:method-activate', async (event) => {
await init(event.detail.method);
});

window.addEventListener('checkout:init:evaluation', event => {
hyvaCheckout.evaluation.registerValidator('validate-adyen-component-state', (element, component) => {
let isValid;
if (!window.AdyenPaymentHandler.actionComponent.isValid) {
window.AdyenPaymentHandler.actionComponent.showValidation();
isValid = false;
} else {
isValid = true;
}
return isValid;
});
});

async function init(methodCode) {
try {
let wire = Magewire.find('checkout.payment.methods.' + methodCode);

wire.refreshProperties()
.then(() => {
let methodHandler = new facilypayComponentHandler(
methodCode,
wire,
'<?= $escaper->escapeHtml($magewire->getContainerName()) ?>ActionContainer'
);
window.AdyenPaymentHandler = methodHandler;
if (methodCode !== '<?= $escaper->escapeHtml($magewire->getMethodCode()) ?>') {
methodHandler.renderMethodUnavailableMessage();
return;
}
if (wire.get('requiresShipping')) {
methodHandler.renderMessage('Please select shipping method.');
} else {
let rawResponse = wire.get('paymentResponse');
let paymentMethods = JSON.parse(rawResponse);
methodHandler.activatePaymentMethod(
methodCode,
paymentMethods,
'<?= $escaper->escapeHtml($magewire->getContainerName()) ?>ActionContainer'
);
showPrimaryButton();
}
}).catch(() => {
console.error(`Error occurred during ${methodCode} component load`);
});
} catch (e) {
console.error('Error in init function:', e);
}
}
</script>
</div>
Loading