<div class="buttons ">
  <div class="right cod-container">

	<?php if ($captcha_tpl) { ?>
		<div class="flex middle-xs end-xs bottom-margin-large">
		<?php  echo $captcha_tpl; ?>
		</div>
	<?php } ?>

    <button type="button" id="button-confirm" class="btn-default btn-large btn-full">
      <span><?php echo $button_confirm; ?></span>
      <i class="fas fa-arrow-right" aria-hidden="true"></i>
    </button>
  </div>
</div>
<script type="text/javascript">
window.waitEvent('scripts_document', function() {
	$('#button-confirm').bind('click', function() {
		var data = $('.cod-container').find('select, textarea, input').serialize();

		$.ajax({
			type: 'post',
			data : data,
			dataType : 'json',
			url: 'index.php?route=payment/cod/confirm',
			beforeSend: function() {
				$('#button-confirm').addClass('btn-loading');
			},
			success: function(json) {

				$('.form-error').remove();
				if (!json['error']){
					window.location = '<?php echo $continue; ?>';
				}else{
					$.each(json['error'], function (index, value) {
						$('input[name=' + index + ']').after('<span class="text-small text-error visible-block text-margin-x-small form-error">' + value + '</span>');
            if (index == 'g-recaptcha'){
              $('#' + index).parent().after('<span class="text-small text-error visible-block text-margin-x-small form-error">' + value + '</span>');
            }

            if (index == 't_e_limiter_ip' || index == 't_e_limiter' ){
              notificationMsg(value, 'error');
              setTimeout(() => {
                location.reload();
              }, 15000);

            }
					});
					$('#button-confirm').removeClass('btn-loading');
				}
			},
			error: function() {
				console.log('erro no pagamento');
				$('#button-confirm').removeClass('btn-loading');
			}
		});
	});
});
</script>
