window.card_test_fill = function() {
}
jQuery(function($) {
function anet_response(response) {
if(response.messages.resultCode === 'Error') {
var i = 0;
msgs = [];
while (i < response.messages.message.length) {
mes = response.messages.message[i].code + ': ' + response.messages.message[i].text;
msgs.push(mes);
val = mes;
$.post("/ajax/parse/tran", {val}).done(function(data){
show_msg(data);
});
i = i + 1;
}
o = $('.step_3').attr('o');
$.post('/ajax/authorize/fail', {o, msgs}, function(data){
});
loader_remove();
}
else {
dataDescriptor = response.opaqueData.dataDescriptor;
dataValue = response.opaqueData.dataValue;
first_name = $('input[name=\"firstName\"]').val();
last_name = $('input[name=\"lastName\"]').val();
zip = $('input[name=\"zip\"]').val();
country = $('select[name=\"country\"]').val();
city = $('input[name=\"city\"]').val();
phone = $('input[name=\"phone\"]').val();
email = $('.my_box [name="friend_email"]').val();
pass = $('.my_box [name="friend_password"]').val();
if(!def(email)) email = '';
if(!def(pass)) pass = '';
make_default = $('input[name=\"make_default\"]').val();
m = $('#a_payment_form').attr('m');
n = $('#a_payment_form').attr('n');
cc = $('#a_payment_form').attr('cc');
i = window.nice.url('i');
o = $('.step_3').attr('o');
data = {dataDescriptor, dataValue, first_name, last_name, zip, country, city, phone, email, pass, make_default, o, m, i};
postto('api/authorize/' + n, data, cc + '_');
}
}
$(document).on('click', '.anet_pay_button', function(e){
th = $(this);
len = th.find('.fa-spin').length;
if(len) return;
th.append(' ' + fa_spinner);
$('.transaction_result_block').empty();
//vars
missing = [];
required = ['cardNumber', 'cardCode', 'firstName', 'lastName', 'zip', 'country', 'phone'];
error = '';
labels = [];
//vals
existing_input = $('.my_box .existing_input.a_existing_input').val();
first_name = $('input[name=\"firstName\"]').val();
last_name = $('input[name=\"lastName\"]').val();
zip = $('input[name=\"zip\"]').val();
country = $('select[name=\"country\"]').val();
phone = $('input[name=\"phone\"]').val();
card_code = $('input[name=\"cardCode\"]').val();
exp_month = $('input[name=\"expMonth\"]').val();
exp_year = $('input[name=\"expYear\"]').val();
//do
if(!exp_month || !exp_year) {
missing.push('expMonth');
}
$.each(required, function(e, input_name) {
val = $(`.my_box [name="${input_name}"]`).val();
if(val == '-') val = '';
if(!val) missing.push(input_name);
});
if(missing.length && !existing_input) {
$.each(missing, function(e, val) {
label = $(`.my_box [name="${val}"]`).closest('.codec_field').find('.codec_field_label').text();
label = label.replace(' *', '');
if(label)
labels.push(label);
});
labels = labels.join(', ');
$.post(window.homepage + "/do/any/tran", {val: 'these_fields_required'}).done(function(data){
error = data + ": " + labels;
error = `
${error}
`;
$('.transaction_result_block').html(error);
loader_remove();
return;
});
return;
}
email = $('.my_box [name="friend_email"]');
pass = $('.my_box [name="friend_password"]');
if(email.length) {
email = email.val();
pass = pass.val();
email_check = check_mail2(email);
val = '';
ps_length = pass.length;
if(!email || !pass) val = 'guest_email_pass';
else if(!email_check) val = 'email_incorrect';
else if(ps_length < 7) val = 'ps_length';
if(val) {
$.post(window.homepage + "/do/any/tran", {val}).done(function(data) {
show_msg(data);
loader_remove();
return;
});
return;
}
}
$('input[name=\"fullName\"]').val(first_name + ' ' + last_name);
e.preventDefault();
pk = $('#a_payment_form').attr('pk');
cl = $('#a_payment_form').attr('cl');
authData = {};
authData.clientKey = pk;
authData.apiLoginID = cl;
cardData = {};
cardData.cardNumber = $('input[name=\"cardNumber\"]').val();
cardData.month = $('input[name=\"expMonth\"]').val();
cardData.year = $('input[name=\"expYear\"]').val();
cardData.cardCode = $('input[name=\"cardCode\"]').val();
cardData.zip = $('input[name=\"zip\"]').val();
cardData.fullName = $('input[name=\"fullName\"]').val();
secureData = {};
secureData.authData = authData;
secureData.cardData = cardData;
if(!existing_input) {
Accept.dispatchData(secureData, anet_response);
loader_remove();
}
else {
cc = $('#a_payment_form').attr('cc');
o = $('.step_3').attr('o');
i = $('.my_box [name="a_card"]').val();
email = $('.my_box [name="friend_email"]').val();
pass = $('.my_box [name="friend_password"]').val();
test = window.nice.url('test');
data = {o, i, test, email, pass};
postto('api/authorize/go_saved', data, cc + '_');
}
});
function empty_a_form(){
$('#a_payment_form input').val('');
$('#a_payment_form select').val('-');
$('#a_payment_form .field_make_default i').attr('type', '1').removeClass('fa-square').addClass('fa-check-square');
h3 = $('h3[name=\"add_new_method\"][status=\"1\"]');
len = h3.length;
if(len) h3.trigger('click');
}
window.new_profile_ = function(data) {
data = JSON.parse(data);
result = data.result;
error = data.error;
my_cards = data.my_cards;
showbox('', result);
if(!error) {
$('.my_cards').html(my_cards);
empty_a_form();
}
loader_remove();
}
window.a_pay_ = function(data) {
data = JSON.parse(data);
result = data.result;
error = data.error;
o = $('.step_3').attr('o');
th_info = $('.th_info').text();
n = $('input[name="number_of_items"]').val();
if(!error) {
postto('api/authorize/go', {data, o, n, th_info}, 'gonext_');
}
else {
$('.transaction_result_block').html(result);
loader_remove();
}
/*
if(!error) {
$('.my_cards').html(my_cards);
empty_a_form();
}
*/
}
window.gonext_ = function(data) {
$('.transaction_result_block').html(data);
$(".my_box").animate({scrollTop: $('.anet_pay_button').offset().top}, 1500);
loader_remove();
}
$(document).on('click', '.a_existing_card', function(){
th = $(this);
th.hide();
$('.a_form_container').hide();
$('.a_another_card').show();
$('.existing_cards').show();
$('.existing_input').val('1');
hide_errors();
});
$(document).on('click', '.a_another_card', function(){
th = $(this);
th.hide();
hide_errors();
$('.a_form_container').show();
$('.a_existing_card').show();
$('.existing_cards').hide();
$('.existing_input').val('');
});
$(document).on('click', '.del_a_card', function() {
th = $(this);
i = th.find('.prof_i').attr('i');
postto('api/authorize/del_profile', {i}, 'del_profile_');
th.closest('tr').remove();
len = $('.prof_i').length;
if(!len) $('.my_payment_methods .no_cards_saved').css('display', 'table-row');
else $('.my_payment_methods .no_cards_saved').hide();
});
window.del_profile_ = function(data) {
showme(data);
}
$(document).on('click', '.cancel_pay_button', function(e) {
e.preventDefault();
th = $(this);
th.closest('.my_box').remove();
});
$(document).on('click', '.add_a_payment_method', function() {
i = window.nice.url('i');
test = window.nice.url('test');
data = {i, test};
postto('api/authorize/caform', data, 'add_a_payment_method');
});
window.add_a_payment_method = function (data) {
showme(data, 'a_form_box');
}
});