$('#checkout-confirm').on('submit', function(e) {
  e.preventDefault();
  var $this = $(this),
    dataInfo = $(this)
      .find('[data-info]')
      .data('info');

  var data = $('.container-payment-data').find('select, textarea, input').serialize();
  
  $.ajax({
    type: 'POST',
    url: dataInfo.url,
    data: data,
    dataType : 'json',    
    beforeSend: function() {
      $this.find('.ftr-steps__button').prop('disabled', true);
      $('.ftr-loading-bar').removeClass('ftr-none');
    },
    complete: function() {
      $('.ftr-loading-bar').addClass('ftr-none');
      $this.find('.ftr-steps__button').prop('disabled', false);
    },
    success: function(json) {
      if (json['error']) {
        $('.ftr-field').removeClass('error');
        $('.ftr-field__error').remove();

        $.each(json['error'], function(index, value) {
          $('input[name=' + index + ']')
            .closest('.ftr-field')
            .addClass('error');
          $('input[name=' + index + ']  + .ftr-field__text').after(
            '<span class="ftr-field__error">' + value + '</span>'
          );
        });
      }else{
        window.location = dataInfo.location;
      }

    },
  });
});
