Gostaria de saber se terei problemas com o anti-fraude da Vindi se alterar campos do cartão de crédito via jQuery.
Adicionei esse script para selecionar a bandeira de cartão de acordo com o número de cartão informado:
var types = [
{
type: 'american_express',
pattern: /^3([47]\d*)?$/,
},
{
type: 'diners_club',
pattern: /^(3(0[0-5]|095|6|[8-9]))\d*$/,
},
{
type: 'elo',
pattern: {test: function(n) {var bin, binI; return 6 === (bin = n.substring(0, 6)).length && (
_.includes([401178, 401179, 431274, 438935, 451416, 457393, 457631, 457632, 504175, 627780,
636297, 636368, 636369], binI = parseInt(bin))
|| _.find([[506699, 506778],[509000, 509999],[650031, 650033],[650035, 650051],[650405, 650439],[650485, 650538],[650541, 650598],[650700, 650718],[650720, 650727],[650901, 650920],[651652, 651679],[655000, 655019],[655021, 655058]], function(r) {return binI >= r[0] && binI <= r[1];})
);}}
},
{
type: 'hipercard',
pattern: /^(606282\d{10}(\d{3})?)|(3841(0|4|6)0\d{13})$/
},
{
type: 'mastercard',
pattern: /^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$/,
},
{
type: 'visa',
pattern: /^4\d*$/,
}
/*,{
type: 'discover',
pattern: /^(6011(0|[2-4]|74|7[7-9]|8[6-9]|9)|6(4[4-9]|5))\d*$/,
},
{
type: 'itau_hiper',
pattern: /^(637095|637612|637599|637609|637568)\d{10}$/
},
{
type: 'jcb',
pattern: /^35(2[8-9]|[3-8])\d*$/,
},
{
type: 'maestro_domestic',
pattern: /^6759(?!24|38|40|6[3-9]|70|76)|676770|676774\d*$/,
},
{
type: 'maestro_international',
pattern: /^(5(0|[6-9])|63|67(?!59|6770|6774))\d*$/,
},
{
type: 'union_pay',
pattern: /^(622(1(2[6-9]|[3-9])|[3-8]|9([[0-1]|2[0-5]))|62[4-6]|628([2-8]))\d*?$/,
}*/
];
function getCardType(n) {
var card_number = n.replace(/\s/g, '');
var result = false;
for (var i = 0; i < types.length; ++i) {
var type = types[i];
if (type.pattern.test(card_number)){
result = type.type;
break;
}
}
return result;
}
function selecionarBandeira(numero){
var type = getCardType(numero);
if (type != false){
jQuery('select[name=vindi_cc_paymentcompany]').val(type);
}
}
$(document).on( 'keypress', 'input[name=vindi_cc_number]', function(event){
selecionarBandeira(jQuery(this).val() + String.fromCharCode(event.charCode));
});
$(document).on( 'change blur', 'input[name=vindi_cc_number]', function(event){
selecionarBandeira(jQuery(this).val());
});