Skip to content

Commit 6a7d40a

Browse files
committed
Sync braintree config with customer's data.
This commit fixes the case when customer navigates back to the shipping step and change address fields.
1 parent 5ed3aa3 commit 6a7d40a

File tree

1 file changed

+22
-3
lines changed
  • app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer

1 file changed

+22
-3
lines changed

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
define([
88
'jquery',
99
'underscore',
10+
'mage/utils/wrapper',
1011
'Magento_Checkout/js/view/payment/default',
1112
'Magento_Braintree/js/view/payment/adapter',
1213
'Magento_Checkout/js/model/quote',
@@ -18,6 +19,7 @@ define([
1819
], function (
1920
$,
2021
_,
22+
wrapper,
2123
Component,
2224
Braintree,
2325
quote,
@@ -218,8 +220,9 @@ define([
218220

219221
/**
220222
* Re-init PayPal Auth Flow
223+
* @param {Function} callback Optional callback
221224
*/
222-
reInitPayPal: function () {
225+
reInitPayPal: function (callback) {
223226
if (Braintree.checkout) {
224227
Braintree.checkout.teardown(function () {
225228
Braintree.checkout = null;
@@ -228,6 +231,18 @@ define([
228231

229232
this.disableButton();
230233
this.clientConfig.paypal.amount = this.grandTotalAmount;
234+
this.clientConfig.paypal.shippingAddressOverride = this.getShippingAddress();
235+
236+
if (callback) {
237+
this.clientConfig.onReady = wrapper.wrap(
238+
this.clientConfig.onReady,
239+
function (original, checkout) {
240+
this.clientConfig.onReady = original;
241+
original(checkout);
242+
callback();
243+
}.bind(this)
244+
);
245+
}
231246

232247
Braintree.setConfig(this.clientConfig);
233248
Braintree.setup();
@@ -404,15 +419,19 @@ define([
404419
* Triggers when customer click "Continue to PayPal" button
405420
*/
406421
payWithPayPal: function () {
407-
if (additionalValidators.validate()) {
422+
this.reInitPayPal(function () {
423+
if (!additionalValidators.validate()) {
424+
return;
425+
}
426+
408427
try {
409428
Braintree.checkout.paypal.initAuthFlow();
410429
} catch (e) {
411430
this.messageContainer.addErrorMessage({
412431
message: $t('Payment ' + this.getTitle() + ' can\'t be initialized.')
413432
});
414433
}
415-
}
434+
}.bind(this));
416435
},
417436

418437
/**

0 commit comments

Comments
 (0)