Commit 26ed6556 authored by Marcos Garcia's avatar Marcos Garcia Committed by GitHub

Use Generic Components for Google Pay (#845)

Co-authored-by: default avatarmarcoss <marcos.silvagarcia@adyen.com>
parent 260b1e30
...@@ -1638,3 +1638,15 @@ ...@@ -1638,3 +1638,15 @@
overflow:auto; overflow:auto;
padding-top: 0; padding-top: 0;
} }
/**
* Configuration for Google Pay
*/
#googlePay.disabled {
cursor: pointer;
opacity: 0.75;
}
#googlePay.disabled > * {
pointer-events: none;
}
...@@ -34,7 +34,6 @@ define( ...@@ -34,7 +34,6 @@ define(
'Magento_Checkout/js/model/full-screen-loader', 'Magento_Checkout/js/model/full-screen-loader',
'mage/url', 'mage/url',
'Magento_Vault/js/view/payment/vault-enabler', 'Magento_Vault/js/view/payment/vault-enabler',
'adyenCheckout',
'Adyen_Payment/js/bundle', 'Adyen_Payment/js/bundle',
], ],
function( function(
...@@ -48,17 +47,10 @@ define( ...@@ -48,17 +47,10 @@ define(
fullScreenLoader, fullScreenLoader,
url, url,
VaultEnabler, VaultEnabler,
AdyenCheckout, AdyenComponent
AdyenComponent,
) { ) {
'use strict'; 'use strict';
/**
* Shareble adyen checkout component
* @type {AdyenCheckout}
*/
var checkoutComponent;
return Component.extend({ return Component.extend({
self: this, self: this,
defaults: { defaults: {
...@@ -90,8 +82,8 @@ define( ...@@ -90,8 +82,8 @@ define(
'googlePayAllowed', 'googlePayAllowed',
]); ]);
return this; return this;
}, initialize: function() { },
var self = this; initialize: function() {
this.additionalValidators = additionalValidators; this.additionalValidators = additionalValidators;
this.vaultEnabler = new VaultEnabler(); this.vaultEnabler = new VaultEnabler();
this.vaultEnabler.setPaymentCode(this.getVaultCode()); this.vaultEnabler.setPaymentCode(this.getVaultCode());
...@@ -125,8 +117,7 @@ define( ...@@ -125,8 +117,7 @@ define(
}, },
// Payment // Payment
amount: self.formatAmount(quote.totals().grand_total, amount: self.formatAmount(quote.totals().grand_total, self.getFormat()),
self.getFormat()),
currency: quote.totals().quote_currency_code, currency: quote.totals().quote_currency_code,
totalPriceStatus: 'FINAL', totalPriceStatus: 'FINAL',
...@@ -154,21 +145,19 @@ define( ...@@ -154,21 +145,19 @@ define(
buttonType: 'long', // long/short buttonType: 'long', // long/short
showButton: true, // show or hide the Google Pay button showButton: true, // show or hide the Google Pay button
}); });
var promise = googlepay.isAvailable(); googlepay.isAvailable().then(function() {
promise.then(function(success) {
self.googlePayAllowed(true); self.googlePayAllowed(true);
googlepay.mount(self.googlePayNode); googlepay.mount(self.googlePayNode);
$(self.googlePayNode).find('button').prop('disabled', true); self.googlePayNode.addEventListener('click', function () {
self.validate();
});
}, function(error) { }, function(error) {
console.log(error); console.log(error);
self.googlePayAllowed(false); self.googlePayAllowed(false);
}); });
}, },
isGooglePayAllowed: function() { isGooglePayAllowed: function() {
if (this.googlePayAllowed()) { return !!this.googlePayAllowed();
return true;
}
return false;
}, },
getMerchantAccount: function() { getMerchantAccount: function() {
return window.checkoutConfig.payment.adyenGooglePay.merchantAccount; return window.checkoutConfig.payment.adyenGooglePay.merchantAccount;
...@@ -211,12 +200,12 @@ define( ...@@ -211,12 +200,12 @@ define(
}, },
/** /**
* Return the formatted currency. Adyen accepts the currency in multiple formats. * Return the formatted currency. Adyen accepts the currency in multiple formats.
* @param $amount * @param amount
* @param $currency * @param format
* @return string * @return string
*/ */
formatAmount: function (amount, format) { formatAmount: function (amount, format) {
return Math.round(amount * (Math.pow(10, format))) return Math.round(amount * (Math.pow(10, format))).toString();
}, },
isVaultEnabled: function () { isVaultEnabled: function () {
return this.vaultEnabler.isVaultEnabled(); return this.vaultEnabler.isVaultEnabled();
...@@ -230,8 +219,8 @@ define( ...@@ -230,8 +219,8 @@ define(
getCheckoutEnvironment: function () { getCheckoutEnvironment: function () {
return window.checkoutConfig.payment.adyenGooglePay.checkoutEnvironment; return window.checkoutConfig.payment.adyenGooglePay.checkoutEnvironment;
}, },
onPaymentMethodContentChange: function (data, event) { onPaymentMethodContentChange: function () {
$(this.googlePayNode).find('button').prop('disabled', !this.validate()); $(this.googlePayNode).toggleClass('disabled', !this.validate());
} }
}); });
} }
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<!--/ko--> <!--/ko-->
</div> </div>
<div class="field number googlePay"> <div class="field number googlePay">
<div class="checkout-component-dock" afterRender="renderGooglePay()" data-bind="attr: { id: 'googlePay'}"> <div class="checkout-component-dock disabled" afterRender="renderGooglePay()" data-bind="attr: { id: 'googlePay'}">
<!-- ko ifnot: isGooglePayAllowed() --> <!-- ko ifnot: isGooglePayAllowed() -->
Google Pay is not available Google Pay is not available
<!--/ko--></div> <!--/ko--></div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment