Skip to content

Commit

Permalink
Revision: 54 - Fix problem with the order confirmation button
Browse files Browse the repository at this point in the history
Additionally, validation is performed to create a new payment intention in the event that the payment has been pending and with a payment method association.
  • Loading branch information
presteamshop committed Oct 10, 2024
1 parent b07967c commit 4f0fda2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion monei.php
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ public function createPayment(bool $tokenizeCard = false, int $moneiCardId = 0)
$moneiPaymentId = $this->context->cookie->{'monei_payment_' . $cartAmount . '_' . $cart->id_address_invoice};
if (!$tokenizeCard && !$moneiCardId && !empty($moneiPaymentId)) {
$moneiPayment = $this->moneiClient->payments->getPayment($moneiPaymentId);
if ($moneiPayment && $moneiPayment->getStatus() === MoneiPaymentStatus::PENDING) {
if ($moneiPayment && $moneiPayment->getStatus() === MoneiPaymentStatus::PENDING && empty($moneiPayment->getPaymentMethod())) {
return $moneiPayment;
} else {
$this->removeMoneiPaymentCookie();
Expand Down
38 changes: 30 additions & 8 deletions views/templates/hook/displayPaymentByBinaries.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
window.moneiShippingData = {$shippingData|json_encode nofilter};
{literal}
var moneiTokenHandler = async (paymentToken, cardholderName, paymentButton) => {
var moneiTokenHandler = async (paymentToken, cardholderName) => {
// support module onepagecheckoutps - v4 - PresTeamShop
const customerEmail = document.getElementById('customer_email');
if (customerEmail) {
Expand Down Expand Up @@ -93,6 +93,23 @@
}
return true;
};
var moneiEnableButton = (moneiButton) => {
if (moneiButton) {
// In some PS versions, the handler fails to disable the button because of the timing.
setTimeout(() => {
moneiButton.classList.remove('disabled');
moneiButton.disabled = false;
}, 0);
}
};
var moneiDisableButton = (moneiButton) => {
if (moneiButton) {
moneiButton.classList.add('disabled');
moneiButton.disabled = true;
}
};
{/literal}
</script>
Expand All @@ -101,6 +118,7 @@
class="js-payment-binary js-payment-monei js-payment-{$paymentOptionName|escape:'htmlall':'UTF-8'} mt-1 disabled">
<div id="{$paymentOptionName|escape:'htmlall':'UTF-8'}-buttons-container">
<form action="https://secure.monei.com/payments/{$moneiPaymentId|escape:'htmlall':'UTF-8'}/confirm" method="post">
<input type="hidden" name="option" value="binary">
<div class="{$paymentOptionName|escape:'htmlall':'UTF-8'}_render"></div>
{if $paymentOptionName eq 'monei-card'}
<button class="btn btn-primary btn-block" type="submit">
Expand Down Expand Up @@ -145,6 +163,9 @@
{literal}
<script>
function initMoneiCard() {
const sectionMoneiCard = document.querySelector('.js-payment-monei-card');
if (!sectionMoneiCard) return;
const moneiCardButtonsContainer = document.getElementById('monei-card-buttons-container');
if (!moneiCardButtonsContainer) return;
Expand Down Expand Up @@ -184,25 +205,26 @@
e.preventDefault();
e.stopPropagation();
if (!moneiPaymentForm.checkValidity() || !validateMoneiCardHolderName(moneiCardHolderName.value)) return;
moneiDisableButton(moneiCardButton);
moneiCardButton.disabled = true;
if (!moneiPaymentForm.checkValidity() || !validateMoneiCardHolderName(moneiCardHolderName.value)) {
moneiEnableButton(moneiCardButton);
return;
}
try {
const { token, error } = await monei.createToken(moneiCardInput);
if (!token) {
moneiCardErrors.innerHTML = `<div class="alert alert-warning">${error}</div>`;
moneiCardButton.classList.remove('disabled');
moneiCardButton.disabled = false;
moneiEnableButton(moneiCardButton);
return;
}
moneiCardErrors.innerHTML = '';
await moneiTokenHandler(token, moneiCardHolderName.value, moneiCardButton);
await moneiTokenHandler(token, moneiCardHolderName.value);
} catch (error) {
moneiCardErrors.innerHTML = `<div class="alert alert-warning">${error.message}</div>`;
moneiCardButton.classList.remove('disabled');
moneiCardButton.disabled = false;
moneiEnableButton(moneiCardButton);
console.log('createToken - Card Input - error', error);
}
});
Expand Down

0 comments on commit 4f0fda2

Please sign in to comment.