7
7
define ( [
8
8
'jquery' ,
9
9
'underscore' ,
10
- 'mage/utils/wrapper' ,
11
10
'Magento_Checkout/js/view/payment/default' ,
12
11
'Magento_Braintree/js/view/payment/adapter' ,
13
12
'Magento_Checkout/js/model/quote' ,
@@ -19,7 +18,6 @@ define([
19
18
] , function (
20
19
$ ,
21
20
_ ,
22
- wrapper ,
23
21
Component ,
24
22
Braintree ,
25
23
quote ,
@@ -105,6 +103,12 @@ define([
105
103
}
106
104
} ) ;
107
105
106
+ quote . shippingAddress . subscribe ( function ( ) {
107
+ if ( self . isActive ( ) ) {
108
+ self . reInitPayPal ( ) ;
109
+ }
110
+ } ) ;
111
+
108
112
// for each component initialization need update property
109
113
this . isReviewRequired ( false ) ;
110
114
this . initClientConfig ( ) ;
@@ -222,9 +226,8 @@ define([
222
226
223
227
/**
224
228
* Re-init PayPal Auth Flow
225
- * @param {Function } callback - Optional callback
226
229
*/
227
- reInitPayPal : function ( callback ) {
230
+ reInitPayPal : function ( ) {
228
231
if ( Braintree . checkout ) {
229
232
Braintree . checkout . teardown ( function ( ) {
230
233
Braintree . checkout = null ;
@@ -235,17 +238,6 @@ define([
235
238
this . clientConfig . paypal . amount = this . grandTotalAmount ;
236
239
this . clientConfig . paypal . shippingAddressOverride = this . getShippingAddress ( ) ;
237
240
238
- if ( callback ) {
239
- this . clientConfig . onReady = wrapper . wrap (
240
- this . clientConfig . onReady ,
241
- function ( original , checkout ) {
242
- this . clientConfig . onReady = original ;
243
- original ( checkout ) ;
244
- callback ( ) ;
245
- } . bind ( this )
246
- ) ;
247
- }
248
-
249
241
Braintree . setConfig ( this . clientConfig ) ;
250
242
Braintree . setup ( ) ;
251
243
} ,
@@ -428,19 +420,17 @@ define([
428
420
* Triggers when customer click "Continue to PayPal" button
429
421
*/
430
422
payWithPayPal : function ( ) {
431
- this . reInitPayPal ( function ( ) {
432
- if ( ! additionalValidators . validate ( ) ) {
433
- return ;
434
- }
423
+ if ( ! additionalValidators . validate ( ) ) {
424
+ return ;
425
+ }
435
426
436
- try {
437
- Braintree . checkout . paypal . initAuthFlow ( ) ;
438
- } catch ( e ) {
439
- this . messageContainer . addErrorMessage ( {
440
- message : $t ( 'Payment ' + this . getTitle ( ) + ' can\'t be initialized.' )
441
- } ) ;
442
- }
443
- } . bind ( this ) ) ;
427
+ try {
428
+ Braintree . checkout . paypal . initAuthFlow ( ) ;
429
+ } catch ( e ) {
430
+ this . messageContainer . addErrorMessage ( {
431
+ message : $t ( 'Payment ' + this . getTitle ( ) + ' can\'t be initialized.' )
432
+ } ) ;
433
+ }
444
434
} ,
445
435
446
436
/**
0 commit comments