-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ECP-9544] Support all Oney/Facilypay variants (#78)
* [ECP-9544] Create an abstract method renderer for Oney/Facilypay variants * [ECP-9544] Bump the dependency version * [ECP-9544] Remove breakpoints --------- Co-authored-by: Can Demiralp <[email protected]>
- Loading branch information
1 parent
300001a
commit e9a4e51
Showing
3 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
view/frontend/templates/payment/method-renderer/adyen-facilypay-method.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<?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, | ||
}; | ||
} | ||
|
||
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> |