From 6a7d40a772729b20880c143b87f8cbcc9abc5212 Mon Sep 17 00:00:00 2001 From: Vova Yatsyuk Date: Thu, 10 May 2018 14:19:07 +0300 Subject: [PATCH 1/4] Sync braintree config with customer's data. This commit fixes the case when customer navigates back to the shipping step and change address fields. --- .../js/view/payment/method-renderer/paypal.js | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js index 9804ee8489625..0f4928d56ce1d 100644 --- a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js +++ b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js @@ -7,6 +7,7 @@ define([ 'jquery', 'underscore', + 'mage/utils/wrapper', 'Magento_Checkout/js/view/payment/default', 'Magento_Braintree/js/view/payment/adapter', 'Magento_Checkout/js/model/quote', @@ -18,6 +19,7 @@ define([ ], function ( $, _, + wrapper, Component, Braintree, quote, @@ -218,8 +220,9 @@ define([ /** * Re-init PayPal Auth Flow + * @param {Function} callback Optional callback */ - reInitPayPal: function () { + reInitPayPal: function (callback) { if (Braintree.checkout) { Braintree.checkout.teardown(function () { Braintree.checkout = null; @@ -228,6 +231,18 @@ define([ this.disableButton(); this.clientConfig.paypal.amount = this.grandTotalAmount; + this.clientConfig.paypal.shippingAddressOverride = this.getShippingAddress(); + + if (callback) { + this.clientConfig.onReady = wrapper.wrap( + this.clientConfig.onReady, + function (original, checkout) { + this.clientConfig.onReady = original; + original(checkout); + callback(); + }.bind(this) + ); + } Braintree.setConfig(this.clientConfig); Braintree.setup(); @@ -404,7 +419,11 @@ define([ * Triggers when customer click "Continue to PayPal" button */ payWithPayPal: function () { - if (additionalValidators.validate()) { + this.reInitPayPal(function () { + if (!additionalValidators.validate()) { + return; + } + try { Braintree.checkout.paypal.initAuthFlow(); } catch (e) { @@ -412,7 +431,7 @@ define([ message: $t('Payment ' + this.getTitle() + ' can\'t be initialized.') }); } - } + }.bind(this)); }, /** From 8712f3e749afd72d2f8d658bd1906c22e99df73a Mon Sep 17 00:00:00 2001 From: Vova Yatsyuk Date: Fri, 11 May 2018 10:03:18 +0300 Subject: [PATCH 2/4] JSDoc fix --- .../view/frontend/web/js/view/payment/method-renderer/paypal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js index 0f4928d56ce1d..253f3530701bc 100644 --- a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js +++ b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js @@ -220,7 +220,7 @@ define([ /** * Re-init PayPal Auth Flow - * @param {Function} callback Optional callback + * @param {Function} callback - Optional callback */ reInitPayPal: function (callback) { if (Braintree.checkout) { From d6ba03c4f6a41d69675bc8855ae9a4dc066ace0e Mon Sep 17 00:00:00 2001 From: Vova Yatsyuk Date: Fri, 11 May 2018 10:03:38 +0300 Subject: [PATCH 3/4] Fixed failed test --- .../js/view/payment/method-renderer/paypal.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js index a9987f5e01ba8..57aa5c0c5f342 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js @@ -27,7 +27,18 @@ define([ }) }, 'Magento_Braintree/js/view/payment/adapter': { + config: {}, + /** Stub */ + onReady: function () {}, + setConfig: function (config) { + this.config = config; + }, + setup: function () { + this.config.onReady(this.checkout); + }, checkout: { + /** Stub */ + teardown: function () {}, paypal: { /** Stub */ initAuthFlow: function () {} From ebd8af4cb0ab2b9d9b43ad8c3bb2249140ee4e9f Mon Sep 17 00:00:00 2001 From: Vova Yatsyuk Date: Fri, 11 May 2018 16:07:22 +0300 Subject: [PATCH 4/4] ESLint and JSCS fixes --- .../frontend/js/view/payment/method-renderer/paypal.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js index 57aa5c0c5f342..bcfaecd277754 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js @@ -28,14 +28,20 @@ define([ }, 'Magento_Braintree/js/view/payment/adapter': { config: {}, + /** Stub */ onReady: function () {}, + + /** Stub */ setConfig: function (config) { this.config = config; }, + + /** Stub */ setup: function () { this.config.onReady(this.checkout); }, + checkout: { /** Stub */ teardown: function () {},