Skip to content

Commit edd424f

Browse files
author
Ievgen Sentiabov
committed
MAGETWO-44658: All cards are available in Add new card dropdown when only specific allowed for Braintree
- Added subscriber for quote billing address
1 parent db41645 commit edd424f

File tree

3 files changed

+14
-48
lines changed

3 files changed

+14
-48
lines changed

app/code/Magento/Braintree/Model/ConfigProvider.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
class ConfigProvider extends CcGenericConfigProvider
1414
{
15-
const COMPONENT_PROVIDER_NAME = 'checkout.steps.billing-step.payment.payments-list.braintree-form';
1615

1716
/**
1817
* @var string[]
@@ -186,8 +185,7 @@ public function getConfig()
186185
'isCcDetectionEnabled' => $this->config->isCcDetectionEnabled(),
187186
'availableCardTypes' => $this->getCcAvailableCcTypes(),
188187
'braintreeDataJs'=> $this->config->getBraintreeDataJs(),
189-
'ajaxGenerateNonceUrl' => $this->getAjaxGenerateNonceUrl(),
190-
'billingAddressComponentName' => self::COMPONENT_PROVIDER_NAME
188+
'ajaxGenerateNonceUrl' => $this->getAjaxGenerateNonceUrl()
191189
],
192190
],
193191
]);

app/code/Magento/Braintree/Test/Unit/Model/ConfigProviderTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ public function getConfigDataProvider()
263263
'isCcDetectionEnabled' => true,
264264
'availableCardTypes' => $this->availableCardTypes,
265265
'braintreeDataJs'=> 'https://js.braintreegateway.com/v1/braintree-data.js',
266-
'ajaxGenerateNonceUrl' => self::PAYMENT_NONCE_GENERATION_URL,
267-
'billingAddressComponentName' => ConfigProvider::COMPONENT_PROVIDER_NAME
266+
'ajaxGenerateNonceUrl' => self::PAYMENT_NONCE_GENERATION_URL
268267
],
269268
],
270269
]
@@ -339,8 +338,7 @@ public function getConfigDataProvider()
339338
'isCcDetectionEnabled' => true,
340339
'availableCardTypes' => $this->availableCardTypes,
341340
'braintreeDataJs'=> 'https://js.braintreegateway.com/v1/braintree-data.js',
342-
'ajaxGenerateNonceUrl' => self::PAYMENT_NONCE_GENERATION_URL,
343-
'billingAddressComponentName' => ConfigProvider::COMPONENT_PROVIDER_NAME
341+
'ajaxGenerateNonceUrl' => self::PAYMENT_NONCE_GENERATION_URL
344342
],
345343
],
346344
]
@@ -415,8 +413,7 @@ public function getConfigDataProvider()
415413
'isCcDetectionEnabled' => true,
416414
'availableCardTypes' => $this->availableCardTypes,
417415
'braintreeDataJs'=> 'https://js.braintreegateway.com/v1/braintree-data.js',
418-
'ajaxGenerateNonceUrl' => self::PAYMENT_NONCE_GENERATION_URL,
419-
'billingAddressComponentName' => ConfigProvider::COMPONENT_PROVIDER_NAME
416+
'ajaxGenerateNonceUrl' => self::PAYMENT_NONCE_GENERATION_URL
420417
],
421418
],
422419
]
@@ -460,8 +457,7 @@ public function getConfigDataProvider()
460457
'isCcDetectionEnabled' => true,
461458
'availableCardTypes' => $this->availableCardTypes,
462459
'braintreeDataJs'=> 'https://js.braintreegateway.com/v1/braintree-data.js',
463-
'ajaxGenerateNonceUrl' => self::PAYMENT_NONCE_GENERATION_URL,
464-
'billingAddressComponentName' => ConfigProvider::COMPONENT_PROVIDER_NAME
460+
'ajaxGenerateNonceUrl' => self::PAYMENT_NONCE_GENERATION_URL
465461
],
466462
],
467463
]

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/cc-form.js

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ define(
2525
_,
2626
$,
2727
messageList,
28-
$t,
29-
registry,
30-
wrapper
28+
$t
3129
) {
3230
'use strict';
3331
var configBraintree= window.checkoutConfig.payment.braintree;
@@ -66,11 +64,7 @@ define(
6664
availableCardTypes: configBraintree ? configBraintree.availableCardTypes : {},
6765
creditCardExpMonth: null,
6866
creditCardExpYear: null,
69-
billingAddressComponentName: configBraintree.billingAddressComponentName,
70-
lastBillingAddress: null,
71-
imports: {
72-
onIsSameChange: '${ $.billingAddressComponentName }:isAddressSameAsShipping'
73-
}
67+
lastBillingAddress: null
7468
},
7569
initVars: function() {
7670
this.ajaxGenerateNonceUrl = configBraintree ? configBraintree.ajaxGenerateNonceUrl : '';
@@ -95,6 +89,7 @@ define(
9589
* @override
9690
*/
9791
initObservable: function () {
92+
var self = this;
9893
this.initVars();
9994
this._super()
10095
.track('availableCcValues')
@@ -111,8 +106,6 @@ define(
111106
this.selectedCardToken() == '';
112107
}, this);
113108

114-
this.initBillingAddressListening();
115-
116109
if (!this.braintreeDataFrameLoaded && this.isFraudDetectionEnabled) {
117110
$.getScript(this.braintreeDataJs, function () {
118111
self.braintreeDataFrameLoaded = true;
@@ -127,6 +120,11 @@ define(
127120
this.messageContainer.addErrorMessage({'message': $t('Can not initialize PayPal (Braintree)')});
128121
}
129122

123+
// subscribe on billing address update
124+
quote.billingAddress.subscribe(function () {
125+
self.updateAvailableTypeValues();
126+
});
127+
130128
return this;
131129
},
132130
/**
@@ -321,10 +319,10 @@ define(
321319
getCcAvailableTypes: function () {
322320
var availableTypes = configBraintree.availableCardTypes;
323321
var billingAddress = quote.billingAddress();
322+
this.lastBillingAddress = quote.shippingAddress();
324323
if (!billingAddress) {
325324
billingAddress = this.lastBillingAddress;
326325
}
327-
this.lastBillingAddress = billingAddress;
328326
var billingCountryId = billingAddress.countryId;
329327
if (billingCountryId &&
330328
typeof configBraintree.countrySpecificCardTypes[billingCountryId] !== 'undefined'
@@ -385,32 +383,6 @@ define(
385383
*/
386384
updateAvailableTypeValues: function () {
387385
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-
});
414386
}
415387
});
416388
}

0 commit comments

Comments
 (0)