Skip to content

Commit f06f416

Browse files
author
Stanislav Idolov
authored
ENGCOM-2529: [Forwardport] Fix outdated address data when using Braintree's "Pay with PayPal" button #15133 #15482
2 parents c268006 + 1267280 commit f06f416

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();
@@ -403,15 +418,19 @@ define([
403418
* Triggers when customer click "Continue to PayPal" button
404419
*/
405420
payWithPayPal: function () {
406-
if (additionalValidators.validate()) {
421+
this.reInitPayPal(function () {
422+
if (!additionalValidators.validate()) {
423+
return;
424+
}
425+
407426
try {
408427
Braintree.checkout.paypal.initAuthFlow();
409428
} catch (e) {
410429
this.messageContainer.addErrorMessage({
411430
message: $t('Payment ' + this.getTitle() + ' can\'t be initialized.')
412431
});
413432
}
414-
}
433+
}.bind(this));
415434
},
416435

417436
/**

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)