1/** 2 * SofizPay Unified â Checkout method selector + Wallet thank-you page polling 3 */ 4/* global sofizpayWallet, jQuery */ 5(function ($) { 6 'use strict'; 7 8 // ========================================================================= 9 // Checkout: sub-method selector (CIB / Wallet) 10 // ========================================================================= 11 12 function initMethodSelector() { 13 var $selector = $('.sofizpay-method-selector'); 14 if (!$selector.length) return; 15 16 $selector.on('change', 'input[name="sofizpay_sub_method"]', function () { 17 var val = $(this).val(); 18 $selector.find('.sofizpay-method-option').removeClass('selected'); 19 $(this).closest('.sofizpay-method-option').addClass('selected'); 20 21 $('#sofizpay-hint-cib').toggle(val === 'cib'); 22 $('#sofizpay-hint-wallet').toggle(val === 'wallet'); 23 }); 24 } 25 26 // Run on load and after WooCommerce AJAX updates 27 $(document).ready(initMethodSelector); 28 $(document.body).on('updated_checkout', initMethodSelector); 29 30 // ========================================================================= 31 // Thank-you page: wallet payment polling 32 // ========================================================================= 33 34 var box = $('#sofizpay-wallet-payment'); 35 if (!box.length) return; 36 37 // Already confirmed â nothing to poll 38 if (box.find('.sofizpay-confirmed-card').length) return; 39 40 // If we just reloaded after confirmation, don't poll again 41 var reloadKey = 'sofizpay_reloaded_' + box.data('order-id'); 42 if (sessionStorage.getItem(reloadKey)) { 43 sessionStorage.removeItem(reloadKey); 44 return; 45 } 46 47 var orderId = box.data('order-id'); 48 var orderKey = box.data('order-key'); 49 var nonce = box.data('nonce'); 50 51 var statusDiv = $('#sofizpay-wallet-status'); 52 var refreshBtn = $('#sofizpay-wallet-refresh'); 53 54 var pollInterval = null; 55 var pollCount = 0; 56 var MAX_POLLS = 60; 57 58 function setStatus(type, text) { 59 statusDiv 60 .removeClass('sofizpay-status-checking sofizpay-status-confirmed sofizpay-status-pending sofizpay-status-timeout') 61 .addClass('sofizpay-status-' + type); 62 statusDiv.find('.sofizpay-status-text').text(text); 63 } 64 65 function checkPayment(isManual) { 66 if (isManual) { 67 refreshBtn.prop('disabled', true).find('span').text('â¦'); 68 } 69 70 $.post( 71 sofizpayWallet.ajaxUrl, 72 { 73 action: 'sofizpay_wallet_check', 74 order_id: orderId, 75 order_key: orderKey, 76 nonce: nonce 77 }, 78 function (response) { 79 if (!response || !response.success) { 80 if (isManual) { 81 refreshBtn.prop('disabled', false).find('span').text(refreshBtn.data('label') || 'Check'); 82 } 83 return; 84 } 85 86 if (response.data.status === 'confirmed') { 87 if (pollInterval) clearInterval(pollInterval); 88 setStatus('confirmed', sofizpayWallet.confirmed); 89 refreshBtn.hide(); 90 // Set flag and reload once so PHP renders the confirmed state 91 sessionStorage.setItem(reloadKey, '1'); 92 location.reload(); 93 } else { 94 pollCount++; 95 if (isManual) { 96 refreshBtn.prop('disabled', false).find('span').text(refreshBtn.data('label') || 'Check'); 97 setStatus('pending', sofizpayWallet.notYet); 98 if (pollCount < MAX_POLLS) { 99 setTimeout(function () { 100 setStatus('checking', sofizpayWallet.checking); 101 }, 3000); 102 } 103 } 104 if (pollCount >= MAX_POLLS) { 105 if (pollInterval) clearInterval(pollInterval); 106 setStatus('timeout', sofizpayWallet.timeout); 107 } 108 } 109 } 110 ).fail(function () { 111 if (isManual) { 112 refreshBtn.prop('disabled', false).find('span').text(refreshBtn.data('label') || 'Check'); 113 } 114 }); 115 } 116
117 // Copy-to-clipboard 118 box.on('click', '.sofizpay-copy-btn', function () { 119 var btn = $(this); 120 var text = btn.data('copy') + ''; 121 if (!text) return; 122 123 var copiedText = (typeof sofizpayWallet !== 'undefined' && sofizpayWallet.copied) ? sofizpayWallet.copied : 'Copied!'; 124 125 function flash() { 126 var origHtml = btn.find('span').text(); 127 btn.addClass('copied').find('span').text(copiedText); 128 setTimeout(function () { btn.removeClass('copied').find('span').text(origHtml); }, 1500); 129 } 130 131 if (navigator.clipboard && window.isSecureContext) { 132 navigator.clipboard.writeText(text).then(flash); 133 } else { 134 var el = document.createElement('textarea'); 135 el.value = text; 136 el.style.position = 'fixed'; 137 el.style.opacity = '0'; 138 document.body.appendChild(el); 139 el.focus(); 140 el.select(); 141 try { document.execCommand('copy'); flash(); } catch (e) { /* silent */ } 142 document.body.removeChild(el); 143 } 144 }); 145 146 // Manual refresh 147 refreshBtn.on('click', function () { 148 checkPayment(true); 149 }); 150 151 // Store label for restore after loading 152 refreshBtn.data('label', refreshBtn.find('span').text()); 153 154 // Auto-poll 155 checkPayment(false); 156 pollInterval = setInterval(function () { checkPayment(false); }, 10000); 157 158}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.