@@ -25,9 +25,7 @@ define(
25
25
_ ,
26
26
$ ,
27
27
messageList ,
28
- $t ,
29
- registry ,
30
- wrapper
28
+ $t
31
29
) {
32
30
'use strict' ;
33
31
var configBraintree = window . checkoutConfig . payment . braintree ;
@@ -66,11 +64,7 @@ define(
66
64
availableCardTypes : configBraintree ? configBraintree . availableCardTypes : { } ,
67
65
creditCardExpMonth : null ,
68
66
creditCardExpYear : null ,
69
- billingAddressComponentName : configBraintree . billingAddressComponentName ,
70
- lastBillingAddress : null ,
71
- imports : {
72
- onIsSameChange : '${ $.billingAddressComponentName }:isAddressSameAsShipping'
73
- }
67
+ lastBillingAddress : null
74
68
} ,
75
69
initVars : function ( ) {
76
70
this . ajaxGenerateNonceUrl = configBraintree ? configBraintree . ajaxGenerateNonceUrl : '' ;
@@ -95,6 +89,7 @@ define(
95
89
* @override
96
90
*/
97
91
initObservable : function ( ) {
92
+ var self = this ;
98
93
this . initVars ( ) ;
99
94
this . _super ( )
100
95
. track ( 'availableCcValues' )
@@ -111,8 +106,6 @@ define(
111
106
this . selectedCardToken ( ) == '' ;
112
107
} , this ) ;
113
108
114
- this . initBillingAddressListening ( ) ;
115
-
116
109
if ( ! this . braintreeDataFrameLoaded && this . isFraudDetectionEnabled ) {
117
110
$ . getScript ( this . braintreeDataJs , function ( ) {
118
111
self . braintreeDataFrameLoaded = true ;
@@ -127,6 +120,11 @@ define(
127
120
this . messageContainer . addErrorMessage ( { 'message' : $t ( 'Can not initialize PayPal (Braintree)' ) } ) ;
128
121
}
129
122
123
+ // subscribe on billing address update
124
+ quote . billingAddress . subscribe ( function ( ) {
125
+ self . updateAvailableTypeValues ( ) ;
126
+ } ) ;
127
+
130
128
return this ;
131
129
} ,
132
130
/**
@@ -321,10 +319,10 @@ define(
321
319
getCcAvailableTypes : function ( ) {
322
320
var availableTypes = configBraintree . availableCardTypes ;
323
321
var billingAddress = quote . billingAddress ( ) ;
322
+ this . lastBillingAddress = quote . shippingAddress ( ) ;
324
323
if ( ! billingAddress ) {
325
324
billingAddress = this . lastBillingAddress ;
326
325
}
327
- this . lastBillingAddress = billingAddress ;
328
326
var billingCountryId = billingAddress . countryId ;
329
327
if ( billingCountryId &&
330
328
typeof configBraintree . countrySpecificCardTypes [ billingCountryId ] !== 'undefined'
@@ -385,32 +383,6 @@ define(
385
383
*/
386
384
updateAvailableTypeValues : function ( ) {
387
385
this . availableCcValues = this . getCcAvailableTypesValues ( ) ;
388
- } ,
389
-
390
- /**
391
- * Trigger update CC types function
392
- * after Magento_Checkout/js/view/billing-address::isAddressSameAsShipping() was triggered
393
- */
394
- onIsSameChange : function ( ) {
395
- this . updateAvailableTypeValues ( ) ;
396
- } ,
397
-
398
- /**
399
- * Listening Magento_Checkout/js/view/billing-address::updateAddress() function
400
- * and update available CC types values
401
- */
402
- initBillingAddressListening : function ( ) {
403
- var self = this ;
404
- if ( ! registry . has ( [ self . billingAddressComponentName ] ) ) {
405
- throw new Error ( 'Billing Address component not found' ) ;
406
- }
407
- registry . get ( self . billingAddressComponentName , function ( component ) {
408
- // listen updateAddress() function
409
- component . updateAddress = wrapper . wrap ( component . updateAddress , function ( origin ) {
410
- origin ( ) ;
411
- self . updateAvailableTypeValues ( ) ;
412
- } ) ;
413
- } ) ;
414
386
}
415
387
} ) ;
416
388
}
0 commit comments