Skip to content

Commit

Permalink
Refactor Pre-Select
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolorenz committed Jan 24, 2024
1 parent 0c93116 commit 78520f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
11 changes: 0 additions & 11 deletions src/Core/ViewConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,6 @@ public function isAdyenLoggingActive(): bool
return $this->getModuleSettingsSrvc()->isLoggingActive();
}

/**
* @return bool
*/
public function isAdyenPaymentOxChecked(): bool
{
/** @var Payment $oPayment */
$oPayment = oxNew(Payment::class);
$oPayment->load('oscadyencreditcard');
return (bool)$oPayment->oxpayments__oxchecked->value;
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
Expand Down
33 changes: 19 additions & 14 deletions views/frontend/tpl/payment/adyen_assets.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
let submitForm, submitLink;
[{if $oViewConf->getTopActiveClassName() == 'payment'}]
[{assign var="isPaymentPage" value=true}]
[{assign var="paymentID" value=$oView->getCheckedPaymentId()}]
submitForm = document.getElementById('payment');
submitLink = document.getElementById('orderStep');
const nextStepEl = document.getElementById('paymentNextStepBottom');
Expand Down Expand Up @@ -59,22 +60,32 @@
console.log(checkout.paymentMethodsResponse);
[{/if}]
[{if $isPaymentPage && $oView->isAvailablePayment($adyenCreditCard)}]
const cardComponent = checkout.create('card').mount('#[{$adyenCreditCard}]-container');
cardComponent.paymentIdViewEl = undefined;
const cardComponent = checkout.create(
'card',
{
onFieldValid : function() {
const paymentIdEl = document.getElementById('payment_[{$adyenCreditCard}]');
paymentIdEl.checked = true;
nextStepEl.disabled = true;
},
}
).mount('#[{$adyenCreditCard}]-container');
cardComponent.paymentIdViewEl = document.getElementById('payment_[{$adyenCreditCard}]').parentElement;
[{elseif $isOrderPage}]
[{if $orderPaymentApplePay}]
const applePayComponent = checkout.create('[{$templateCheckoutCreateId}]', configuration);
applePayComponent.isAvailable()
.then(() => {
[{if $isLog}]
console.log('mount checkout component')
console.log('mount checkout component');
[{/if}]
applePayComponent.mount('#[{$templatePayButtonContainerId}]');
})
.catch(e => {
[{if $isLog}]
console.error('Apple Pay not available')
console.error(e)
console.error('Apple Pay not available');
console.error(e);
[{/if}]
});
[{else}]
Expand All @@ -93,14 +104,6 @@
});
};
const setPaymentIdEl = (component, nextStepElDisabled) => {
const paymentIdEl = document.getElementById(component._node.attributes.getNamedItem('data-paymentid').value);
paymentIdEl.checked = [{if $oViewConf->isAdyenPaymentOxChecked()}]true[{else}]false[{/if}];
nextStepEl.disabled = nextStepElDisabled;
nextStepEl.dataset.adyensubmit = '';
return paymentIdEl;
};
const makeDetailsCall = data =>
httpPost('details', data)
.then(response => {
Expand Down Expand Up @@ -147,11 +150,13 @@
e.preventDefault();
this.disabled = true;
if (this.dataset.adyensubmit === '[{$adyenCreditCard}]') {
cardComponent.paymentIdViewEl = document.getElementById('payment_[{$adyenCreditCard}]').parentElement;
cardComponent.submit();
}
}
}, false);
[{if $paymentID === $adyenCreditCard}]
nextStepEl.disabled = true;
[{/if}]
[{/if}]
}
// Call adyenAsync
Expand Down
9 changes: 7 additions & 2 deletions views/frontend/tpl/payment/adyen_assets_configuration.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ const configuration = {
},
onChange: (state, component) => {
if (isPaymentPage) {
var paymentIdEl = setPaymentIdEl(component, !state.isValid);
if (state.isValid) {
const paymentIdEl = document.getElementById(component._node.attributes.getNamedItem('data-paymentid').value);
nextStepEl.dataset.adyensubmit = paymentIdEl.value;
nextStepEl.disabled = false;
}
else {
nextStepEl.dataset.adyensubmit = '';
}
}
if (isLog) {
Expand Down Expand Up @@ -53,7 +57,8 @@ const configuration = {
makeDetailsCall(state.data)
.then(response => {
if (isPaymentPage) {
setPaymentIdEl(component, true);
nextStepEl.dataset.adyensubmit = '';
nextStepEl.disabled = true;
}
if (isLog) {
console.log('makeDetailsCall:', response);
Expand Down

0 comments on commit 78520f2

Please sign in to comment.