(function($) { var loader_image = '/portal/images/loader.gif', active_pix = false, pix_expire_time = null; $(document).ready(function () { if($('input[name="order-id-pix-generate"]').length > 0){ var order_id = $('input[name="order-id-pix-generate"]').val(); pix_expire_time = null; active_pix = true; // Intervalo para verificar se expirou setInterval(function() { if(active_pix) { if(pix_expire_time === 0) { pix_expire_time = null; active_pix = false; $('#expired-qr-code').addClass('active'); $('#pix-copy-link').attr('disabled', true); } pix_expire_time--; } }, 1000); } }); $('#generate-qr-code').on('click', function(e) { location.reload(true); }); var elCheckPix = $('meta[name=check_pix_order_id]'); if($(elCheckPix).length > 0) { var orderID = $(elCheckPix).attr('content'), pixCheckInterval = setInterval(pixCheck, 7000); function pixCheck() { if(active_pix) { $.ajax({ url: SITE + '/ajax/pix', type: 'POST', dataType: 'json', data: ({ action: '496a386d4e53633d', orderID: orderID }), success: function(data, textStatus, jqXHR) { if(data.status === 'succeeded') { clearInterval(pixCheckInterval); active_pix = false; $('#paid-out-overlay').addClass('active'); window.location.href = SITE + '/perfil/pedido/' + orderID; } } }); } } } // Copiar link do PIX pelo botão $('#pix-copy-link').on('click', function() { var link = $(this).data('link'); if(link !== '') { var input = document.createElement('input'); input.value = link; input.type = 'text'; $('body').append(input); $(input).get(0).select(); $(input).get(0).setSelectionRange(0, 99999); document.execCommand("copy"); document.body.removeChild(input); } }); if($('.section-show-pix .qrcode-wrapper .remaining-time').length > 0) { var el = $('.section-show-pix .qrcode-wrapper .remaining-time'), futureTime = $(el).data('epoch-time'); var intervalRemainingTime = setInterval(updateRemainingTime, 1000); function updateRemainingTime() { active_pix = true; var now = new Date().toLocaleString(), futureDate = new Date(futureTime * 1e3).toLocaleString(); var splitNow = now.split(' '), splitNowDate = splitNow[0].split('/'), splitNowTime = splitNow[1].split(':'), splitFuture = futureDate.split(' '), splitFutureDate = splitFuture[0].split('/'), splitFutureTime = splitFuture[1].split(':'); var t_now = new Date(splitNowDate[2], splitNowDate[1], splitNowDate[0], splitNowTime[0], splitNowTime[1], splitNowTime[2]).getTime(), t_future = new Date(splitFutureDate[2], splitFutureDate[1], splitFutureDate[0], splitFutureTime[0], splitFutureTime[1], splitFutureTime[2]).getTime(), diff = t_future - t_now, diffSeconds = diff / 1000; var hours = (~~(diffSeconds / 3600)).toString().padStart(2, '0'); var minutes = (~~(diffSeconds % 3600 / 60)).toString().padStart(2, '0'); var seconds = (~~(diffSeconds % 60)).toString().padStart(2, '0'); var formatted = hours + ':' + minutes + ':' + seconds; $(el).find('span').text(formatted); if(diffSeconds <= 0 && diffSeconds >= -30) { clearInterval(intervalRemainingTime); window.location.reload(1); active_pix = false; } } } $('#copyPix').on('click', function(e) { e.preventDefault(); const $btn = $(this); const originalHtml = $btn.html(); const pixCode = $btn.data('pix'); if (!pixCode) return; const showSuccess = () => { $btn.removeClass('copied-success'); $btn.html(' Pix copiado com sucesso!') .addClass('copied-success'); setTimeout(() => { $btn.html(originalHtml).removeClass('copied-success'); }, 2000); }; navigator.clipboard.writeText(pixCode).then(() => { showSuccess(); }).catch(() => { var input = document.createElement('input'); input.value = pixCode; input.type = 'text'; document.body.appendChild(input); input.select(); input.setSelectionRange(0, 99999); document.execCommand("copy"); document.body.removeChild(input); showSuccess(); }); }); })(jQuery);