Skip to content

Commit e9fd476

Browse files
author
Cristian Partica
committed
MAGETWO-39881: [Tech Debt] Enable CC auto-detection for Braintree
- show detection if the the config is enabled
1 parent 95f198e commit e9fd476

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

app/code/Magento/Braintree/Model/Config/Cc.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Cc extends \Magento\Braintree\Model\Config
3030
const KEY_CC_TYPES = 'cctypes';
3131
const KEY_ACTIVE = 'active';
3232
const KEY_FRAUD_PROTECTION = 'fraudprotection';
33+
const KEY_AUTO_DETECTION = 'enable_cc_detection';
3334

3435
/**
3536
* @var string
@@ -176,6 +177,17 @@ public function isFraudDetectionEnabled()
176177
return (bool)(int)$this->getConfigData(self::KEY_ADVANCED_FRAUD_PROTECTION, $this->storeId);
177178
}
178179

180+
/**
181+
* If Credit Card Auto Detection is enabled
182+
*
183+
* @return bool
184+
*/
185+
public function isCcDetectionEnabled()
186+
{
187+
return (bool)(int)$this->getConfigData(self::KEY_AUTO_DETECTION, $this->storeId);
188+
}
189+
190+
179191
/**
180192
* Get Advanced Fraud JS
181193
*

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public function getConfig()
182182
'creditCardExpYear' => (int)$this->dataHelper->getTodayYear(),
183183
'countrySpecificCardTypes' => $this->config->getCountrySpecificCardTypeConfig(),
184184
'isFraudDetectionEnabled' => $this->config->isFraudDetectionEnabled(),
185+
'isCcDetectionEnabled' => $this->config->isCcDetectionEnabled(),
185186
'availableCardTypes' => $this->getCcAvailableCcTypes(),
186187
'braintreeDataJs'=> $this->config->getBraintreeDataJs(),
187188
'ajaxGenerateNonceUrl' => $this->getAjaxGenerateNonceUrl(),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ define(
238238
configBraintree.useVault :
239239
false;
240240
},
241+
isCcDetectionEnabled: function() {
242+
return configBraintree ?
243+
configBraintree.isCcDetectionEnabled :
244+
false;
245+
},
241246
getStoredCards: function() {
242247
var availableTypes = this.getCcAvailableTypes();
243248
var storedCards = this.storedCards();

app/code/Magento/Braintree/view/frontend/web/template/payment/cc-form.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,21 @@
3737
</select>
3838
</div>
3939
</div>
40-
<!-- /ko -->
4140
<div>&nbsp;</div>
41+
<!-- /ko -->
4242
<div class="field type required" data-bind="visible: isCcFormShown">
4343
<label data-bind="attr: {for: getCode() + '_cc_type'}" class="label">
4444
<span><!-- ko text: $t('Credit Card Type')--><!-- /ko --></span>
4545
</label>
4646
<div class="control">
47+
<!-- ko if: (!isCcDetectionEnabled())-->
48+
<select name="payment[cc_type]" class="select"
49+
data-bind="attr: {id: getCode() + '_cc_type', 'data-container': getCode() + '-cc-type', 'data-validate': JSON.stringify({required:true, 'validate-cc-type-select':'#' + getCode() + '_cc_number'})},
50+
mageInit: {creditCardType:{creditCardTypeContainer:'#' + getCode() + '_cc_type_ss_div'}},
51+
enable: true, options: getCcAvailableTypesValues(), optionsValue: 'value', optionsText: 'type', optionsCaption: $t('--Please Select--'), value: creditCardType">
52+
</select>
53+
<!-- /ko -->
54+
<!-- ko if: (isCcDetectionEnabled())-->
4755
<ul class="credit-card-types">
4856
<!-- ko foreach: {data: getCcAvailableTypesValues(), as: 'item'} -->
4957
<li class="item" data-bind="css: {_active: $parent.selectedCardType() == item.value} ">
@@ -65,6 +73,7 @@
6573
data-bind="attr: {id: getCode() + '_cc_type', 'data-container': getCode() + '-cc-type'},
6674
value: creditCardType
6775
">
76+
<!-- /ko -->
6877
</div>
6978
</div>
7079
<div class="field number required" data-bind="visible: isCcFormShown">

0 commit comments

Comments
 (0)