- getCurrency()): // Auto Key Exchange not supported ?>
+
= $block->escapeHtml(__('An unsupported currency is currently selected. ' .
'Please review our configuration guide.')); ?>
@@ -33,7 +34,8 @@
-
+
+
= $block->escapeHtml(
diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js
index 5bf289f52..da6e4ebed 100755
--- a/view/frontend/requirejs-config.js
+++ b/view/frontend/requirejs-config.js
@@ -31,6 +31,9 @@ var config = {
'Magento_Checkout/js/view/shipping-address/address-renderer/default': {
'Amazon_Pay/js/view/shipping-address/address-renderer/default': true
},
+ 'Magento_PurchaseOrder/js/view/checkout/shipping-address/address-renderer/default': {
+ 'Amazon_Pay/js/view/shipping-address/address-renderer/default': true
+ },
'Magento_Checkout/js/view/billing-address': {
'Amazon_Pay/js/view/billing-address': true
},
diff --git a/view/frontend/web/js/amazon-button.js b/view/frontend/web/js/amazon-button.js
index 2a8dae240..578533cbe 100755
--- a/view/frontend/web/js/amazon-button.js
+++ b/view/frontend/web/js/amazon-button.js
@@ -23,7 +23,8 @@ define([
'Magento_Customer/js/customer-data',
'Magento_Checkout/js/model/payment/additional-validators',
'mage/storage',
- 'Magento_Checkout/js/model/error-processor'
+ 'Magento_Checkout/js/model/error-processor',
+ 'Magento_Ui/js/model/messageList',
], function (
ko,
$,
@@ -35,7 +36,8 @@ define([
customerData,
additionalValidators,
storage,
- errorProcessor
+ errorProcessor,
+ globalMessageList
) {
'use strict';
@@ -49,6 +51,7 @@ define([
},
drawing: false,
+ amazonPayButton: null,
_loadButtonConfig: function (callback) {
checkoutSessionConfigLoad(function (checkoutSessionConfig) {
@@ -75,16 +78,43 @@ define([
_loadInitCheckoutPayload: function (callback, payloadType) {
checkoutSessionConfigLoad(function (checkoutSessionConfig) {
+ var self = this;
buttonPayloadLoad(function (buttonPayload) {
- callback({
+ var initCheckoutPayload = {
createCheckoutSessionConfig: {
payloadJSON: buttonPayload[0],
signature: buttonPayload[1],
publicKeyId: checkoutSessionConfig['public_key_id']
}
- });
+ };
+
+ if (payloadType !== 'paynow'
+ && !amazonStorage.isMulticurrencyEnabled
+ && !JSON.parse(buttonPayload[0]).recurringMetadata)
+ {
+ initCheckoutPayload.estimatedOrderAmount = self._getEstimatedAmount();
+ }
+ callback(initCheckoutPayload);
}, payloadType);
+ }.bind(this));
+ },
+
+ _getEstimatedAmount: function () {
+ var currencyCode;
+ var subtotal = parseFloat(customerData.get('cart')().subtotalAmount).toFixed(2);
+
+ checkoutSessionConfigLoad(function (checkoutSessionConfig) {
+ currencyCode = checkoutSessionConfig['currency'];
});
+
+ if (currencyCode === 'JPY') {
+ subtotal = parseFloat(subtotal).toFixed(0);
+ }
+
+ return {
+ amount: subtotal,
+ currencyCode: currencyCode
+ };
},
/**
@@ -138,12 +168,12 @@ define([
this._loadButtonConfig(function (buttonConfig) {
try {
- var amazonPayButton = amazon.Pay.renderButton('#' + $buttonRoot.empty().removeUniqueId().uniqueId().attr('id'), buttonConfig);
+ self.amazonPayButton = amazon.Pay.renderButton('#' + $buttonRoot.empty().removeUniqueId().uniqueId().attr('id'), buttonConfig);
} catch (e) {
console.log('Amazon Pay button render error: ' + e);
return;
}
- amazonPayButton.onClick(function() {
+ self.amazonPayButton.onClick(function() {
if (self.buttonType === 'PayNow' && !additionalValidators.validate()) {
return false;
}
@@ -156,7 +186,7 @@ define([
).done(
function (response) {
if (!response.error) {
- self._initCheckout(amazonPayButton);
+ self._initCheckout();
} else {
errorProcessor.process(response);
}
@@ -167,23 +197,43 @@ define([
}
);
}else{
- self._initCheckout(amazonPayButton);
+ self._initCheckout();
}
});
$('.amazon-button-container .field-tooltip').fadeIn();
self.drawing = false;
+
+ if (self.buttonType === 'PayNow' && self._isPayOnly()) {
+ customerData.get('checkout-data').subscribe(function (checkoutData) {
+ const opacity = checkoutData.selectedBillingAddress ? 1 : 0.5;
+
+ const shadow = $('.amazon-checkout-button > div')[0].shadowRoot;
+ $(shadow).find('.amazonpay-button-view1').css('opacity', opacity);
+ });
+ }
});
}, this);
}
},
- _initCheckout: function (amazonPayButton) {
+ _initCheckout: function () {
+ var self = this;
+
+ if (self.buttonType === 'PayNow' && self._isPayOnly()) {
+ if (!customerData.get('checkout-data')().selectedBillingAddress) {
+ return;
+ } else {
+ var setBillingAddressAction = require('Magento_Checkout/js/action/set-billing-address');
+ setBillingAddressAction(globalMessageList);
+ }
+ }
+
var payloadType = this.buttonType ?
'paynow' :
'checkout';
this._loadInitCheckoutPayload(function (initCheckoutPayload) {
- amazonPayButton.initCheckout(initCheckoutPayload);
+ self.amazonPayButton.initCheckout(initCheckoutPayload);
}, payloadType);
customerData.invalidate('*');
},
@@ -200,6 +250,10 @@ define([
if (!$(self.options.hideIfUnavailable).first().is(':visible')) {
self._draw();
}
+
+ if (self.amazonPayButton && self.buttonType !== 'PayNow') {
+ self.amazonPayButton.updateButtonInfo(self._getEstimatedAmount());
+ }
});
});
},
@@ -209,7 +263,6 @@ define([
}
});
-
var cart = customerData.get('cart'),
customer = customerData.get('customer'),
canCheckoutWithAmazon = false;
diff --git a/view/frontend/web/js/model/storage.js b/view/frontend/web/js/model/storage.js
index b3a7a8333..70afc64d9 100755
--- a/view/frontend/web/js/model/storage.js
+++ b/view/frontend/web/js/model/storage.js
@@ -31,11 +31,13 @@ define([
var isLwaEnabled = amazonPayConfig.getValue('is_lwa_enabled');
var isGuestCheckoutEnabled = amazonPayConfig.getValue('is_guest_checkout_enabled');
+ var isMulticurrencyEnabled = amazonPayConfig.getValue('is_multicurrency_enabled');
return {
isEnabled: isEnabled,
isLwaEnabled: isLwaEnabled,
isGuestCheckoutEnabled: isGuestCheckoutEnabled,
+ isMulticurrencyEnabled: isMulticurrencyEnabled,
/**
* Is checkout using Amazon Pay?
diff --git a/view/frontend/web/js/view/payment/method-renderer/amazon-payment-method.js b/view/frontend/web/js/view/payment/method-renderer/amazon-payment-method.js
index fad122738..06cef8806 100755
--- a/view/frontend/web/js/view/payment/method-renderer/amazon-payment-method.js
+++ b/view/frontend/web/js/view/payment/method-renderer/amazon-payment-method.js
@@ -44,7 +44,7 @@ define(
return Component.extend({
defaults: {
isAmazonCheckout: ko.observable(amazonStorage.isAmazonCheckout()),
- isBillingAddressVisible: ko.observable(false),
+ isBillingAddressVisible: ko.observable(!quote.billingAddress()),
isIosc: ko.observable($('button.iosc-place-order-button').length > 0),
paymentDescriptor: ko.observable(''),
logo: 'Amazon_Pay/images/logo/Black-L.png',