Skip to content

Commit

Permalink
Merge pull request #64 from presteamshop/presteamshop
Browse files Browse the repository at this point in the history
fix apple/google pay buttons
  • Loading branch information
jimmyn authored Nov 5, 2024
2 parents ac24189 + f545ab7 commit fd51c88
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 40 deletions.
6 changes: 5 additions & 1 deletion monei.php
Original file line number Diff line number Diff line change
Expand Up @@ -1768,12 +1768,16 @@ public function hookDisplayPaymentByBinaries($params)
}

if ($paymentMethodsToDisplay) {
$orderTotal = $this->context->cart->getOrderTotal();

$this->context->smarty->assign([
'paymentMethodsToDisplay' => $paymentMethodsToDisplay,
'moneiAccountId' => $this->moneiAccountId,
'moneiAmount' => Tools::displayPrice($this->context->cart->getOrderTotal()),
'moneiAmount' => $this->getCartAmount(),
'moneiAmountFormatted' => Tools::displayPrice($this->getCartAmount()),
'moneiCreatePaymentUrlController' => $this->context->link->getModuleLink('monei', 'createPayment'),
'moneiToken' => Tools::getToken(false),
'moneiCurrency' => $this->context->currency->iso_code,
]);

return $this->fetch('module:monei/views/templates/hook/displayPaymentByBinaries.tpl');
Expand Down
96 changes: 57 additions & 39 deletions views/templates/hook/displayPaymentByBinaries.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
const moneiAccountId = '{$moneiAccountId|escape:'htmlall':'UTF-8'}';
const moneiCreatePaymentUrlController = '{$moneiCreatePaymentUrlController|escape:'htmlall':'UTF-8'}';
const moneiToken = '{$moneiToken|escape:'htmlall':'UTF-8'}';
const moneiCurrency = '{$moneiCurrency|escape:'htmlall':'UTF-8'}';
const moneiAmount = {$moneiAmount|intval};
{literal}
var moneiTokenHandler = async (parameters = {}) => {
Expand Down Expand Up @@ -144,7 +146,7 @@
{if $paymentOptionName eq 'monei-card'}
<button class="btn btn-primary btn-block" type="submit">
<i class="material-icons">payment</i>
{l s='Pay' mod='monei'}&nbsp;&nbsp;{$moneiAmount|escape:'htmlall':'UTF-8'}
{l s='Pay' mod='monei'}&nbsp;&nbsp;{$moneiAmountFormatted|escape:'htmlall':'UTF-8'}
</button>
{/if}
</form>
Expand Down Expand Up @@ -254,50 +256,66 @@
{elseif $paymentOptionName eq 'monei-googlePay'}
{literal}
<script>
function initMoneiGooglePay() {
const moneiPaymentRequestButtonsContainer = document.getElementById('monei-googlePay-buttons-container');
if (!moneiPaymentRequestButtonsContainer) return;
const moneiPaymentRequestRenderContainer = moneiPaymentRequestButtonsContainer.querySelector('.monei-googlePay_render');
if (!moneiPaymentRequestRenderContainer) return;
monei.PaymentRequest({
accountId: moneiAccountId,
style: moneiPaymentRequestStyle || {},
onBeforeOpen: moneiValidConditions,
onSubmit(result) {
if (result.token) moneiTokenHandler({ paymentToken: result.token });
},
onError(error) {
Swal.fire({ title: `${error.status} (${error.statusCode})`, text: error.message, icon: 'error' });
console.log('onError - Google Pay', error);
}
}).render(moneiPaymentRequestRenderContainer);
if (typeof window.ApplePaySession === 'undefined') {
function initMoneiGooglePay() {
const moneiPaymentRequestButtonsContainer = document.getElementById('monei-googlePay-buttons-container');
if (!moneiPaymentRequestButtonsContainer) return;
const moneiPaymentRequestRenderContainer = moneiPaymentRequestButtonsContainer.querySelector('.monei-googlePay_render');
if (!moneiPaymentRequestRenderContainer) return;
monei.PaymentRequest({
accountId: moneiAccountId,
style: moneiPaymentRequestStyle || {},
amount: moneiAmount,
currency: moneiCurrency,
onBeforeOpen: moneiValidConditions,
onSubmit(result) {
if (result.token) moneiTokenHandler({ paymentToken: result.token });
},
onError(error) {
Swal.fire({ title: `${error.status} (${error.statusCode})`, text: error.message, icon: 'error' });
console.log('onError - Google Pay', error);
}
}).render(moneiPaymentRequestRenderContainer);
}
}
</script>
{/literal}
{elseif $paymentOptionName eq 'monei-applePay'}
{literal}
<script>
function initMoneiApplePay() {
const moneiPaymentRequestButtonsContainer = document.getElementById('monei-applePay-buttons-container');
if (!moneiPaymentRequestButtonsContainer) return;
const moneiPaymentRequestRenderContainer = moneiPaymentRequestButtonsContainer.querySelector('.monei-applePay_render');
if (!moneiPaymentRequestRenderContainer) return;
monei.PaymentRequest({
accountId: moneiAccountId,
style: moneiPaymentRequestStyle || {},
onBeforeOpen: moneiValidConditions,
onSubmit(result) {
if (result.token) moneiTokenHandler({ paymentToken: result.token });
},
onError(error) {
Swal.fire({ title: `${error.status} (${error.statusCode})`, text: error.message, icon: 'error' });
console.log('onError - Apple Pay', error);
}
}).render(moneiPaymentRequestRenderContainer);
if (window.ApplePaySession?.canMakePayments()) {
function initMoneiApplePay() {
const moneiPaymentRequestButtonsContainer = document.getElementById('monei-applePay-buttons-container');
if (!moneiPaymentRequestButtonsContainer) return;
const moneiPaymentRequestRenderContainer = moneiPaymentRequestButtonsContainer.querySelector('.monei-applePay_render');
if (!moneiPaymentRequestRenderContainer) return;
monei.PaymentRequest({
accountId: moneiAccountId,
style: moneiPaymentRequestStyle || {},
amount: moneiAmount,
currency: moneiCurrency,
onBeforeOpen: moneiValidConditions,
onSubmit(result) {
if (result.token) moneiTokenHandler({ paymentToken: result.token });
},
onError(error) {
Swal.fire({ title: `${error.status} (${error.statusCode})`, text: error.message, icon: 'error' });
console.log('onError - Apple Pay', error);
}
}).render(moneiPaymentRequestRenderContainer);
}
} else {
const moneiPaymentOption = document.querySelector('input[name="payment-option"][data-module-name="monei-applePay"]');
if (moneiPaymentOption) {
const moneiPaymentOptionParent = moneiPaymentOption.closest('.payment-option');
if (moneiPaymentOptionParent) {
moneiPaymentOptionParent.style.setProperty('display', 'none', 'important');
}
}
}
</script>
{/literal}
Expand Down

0 comments on commit fd51c88

Please sign in to comment.