Skip to content

Commit 94759da

Browse files
ENGCOM-1513: Fix outdated address data when using Braintree's "Pay with PayPal" button #15133
2 parents c920e3e + 0b786fe commit 94759da

File tree

2 files changed

+39
-3
lines changed
  • app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer
  • dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer

2 files changed

+39
-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
/**

dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,24 @@ define([
2727
})
2828
},
2929
'Magento_Braintree/js/view/payment/adapter': {
30+
config: {},
31+
32+
/** Stub */
33+
onReady: function () {},
34+
35+
/** Stub */
36+
setConfig: function (config) {
37+
this.config = config;
38+
},
39+
40+
/** Stub */
41+
setup: function () {
42+
this.config.onReady(this.checkout);
43+
},
44+
3045
checkout: {
46+
/** Stub */
47+
teardown: function () {},
3148
paypal: {
3249
/** Stub */
3350
initAuthFlow: function () {}

0 commit comments

Comments
 (0)