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
} ,
@@ -429,19 +421,17 @@ define([
429
421
* Triggers when customer click "Continue to PayPal" button
430
422
*/
431
423
payWithPayPal : function ( ) {
432
- this . reInitPayPal ( function ( ) {
433
- if ( ! additionalValidators . validate ( ) ) {
434
- return ;
435
- }
424
+ if ( ! additionalValidators . validate ( ) ) {
425
+ return ;
426
+ }
436
427
437
- try {
438
- Braintree . checkout . paypal . initAuthFlow ( ) ;
439
- } catch ( e ) {
440
- this . messageContainer . addErrorMessage ( {
441
- message : $t ( 'Payment ' + this . getTitle ( ) + ' can\'t be initialized.' )
442
- } ) ;
443
- }
444
- } . bind ( this ) ) ;
428
+ try {
429
+ Braintree . checkout . paypal . initAuthFlow ( ) ;
430
+ } catch ( e ) {
431
+ this . messageContainer . addErrorMessage ( {
432
+ message : $t ( 'Payment ' + this . getTitle ( ) + ' can\'t be initialized.' )
433
+ } ) ;
434
+ }
445
435
} ,
446
436
447
437
/**
0 commit comments