7
7
define ( [
8
8
'jquery' ,
9
9
'underscore' ,
10
+ 'mage/utils/wrapper' ,
10
11
'Magento_Checkout/js/view/payment/default' ,
11
12
'Magento_Braintree/js/view/payment/adapter' ,
12
13
'Magento_Checkout/js/model/quote' ,
@@ -18,6 +19,7 @@ define([
18
19
] , function (
19
20
$ ,
20
21
_ ,
22
+ wrapper ,
21
23
Component ,
22
24
Braintree ,
23
25
quote ,
@@ -218,8 +220,9 @@ define([
218
220
219
221
/**
220
222
* Re-init PayPal Auth Flow
223
+ * @param {Function } callback Optional callback
221
224
*/
222
- reInitPayPal : function ( ) {
225
+ reInitPayPal : function ( callback ) {
223
226
if ( Braintree . checkout ) {
224
227
Braintree . checkout . teardown ( function ( ) {
225
228
Braintree . checkout = null ;
@@ -228,6 +231,18 @@ define([
228
231
229
232
this . disableButton ( ) ;
230
233
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
+ }
231
246
232
247
Braintree . setConfig ( this . clientConfig ) ;
233
248
Braintree . setup ( ) ;
@@ -404,15 +419,19 @@ define([
404
419
* Triggers when customer click "Continue to PayPal" button
405
420
*/
406
421
payWithPayPal : function ( ) {
407
- if ( additionalValidators . validate ( ) ) {
422
+ this . reInitPayPal ( function ( ) {
423
+ if ( ! additionalValidators . validate ( ) ) {
424
+ return ;
425
+ }
426
+
408
427
try {
409
428
Braintree . checkout . paypal . initAuthFlow ( ) ;
410
429
} catch ( e ) {
411
430
this . messageContainer . addErrorMessage ( {
412
431
message : $t ( 'Payment ' + this . getTitle ( ) + ' can\'t be initialized.' )
413
432
} ) ;
414
433
}
415
- }
434
+ } . bind ( this ) ) ;
416
435
} ,
417
436
418
437
/**
0 commit comments