PageSourceSearch

https://aromafragrance.us/wp-content/plugins/direct-payments-for-w…/js/popup/payment-methods.js?ver=1789830319

js aromafragrance.us collected 2026-10-09 22:04:56 UTC 15,225 bytes, 352 lines download raw bytes

1
2jQuery(document).ready(function ($) {
3    let latestPopupRecords = {};
4    let popupFeeRequest = null;
5    let lastPopupFeeSelection = '';
6
7    function syncOrderContext() {
8        if (typeof window.digagesApplyOrderContext === "function") {
9            window.digagesApplyOrderContext();
10        }
11    }
12
13    function getPopupOrderId() {
14        const contextId = window.digagesDirectPaymentContext && window.digagesDirectPaymentContext.orderId;
15        const displayedId = $('.orderNumberDisplay').first().text().replace(/[^0-9]/g, '');
16        return String(contextId || displayedId || '');
17    }
18
19    function getPopupOrderKey() {
20        if (window.digagesOrderKey) return window.digagesOrderKey;
21        if (window.digagesDirectPaymentContext && window.digagesDirectPaymentContext.orderKey) {
22            return window.digagesDirectPaymentContext.orderKey;
23        }
24        try {
25            return new URLSearchParams(window.location.search).get('key') || '';
26        } catch (error) {
27            return '';
28        }
29    }
30
31    function getActivePopupRecord(records) {
32        const $activeTab = $('.nav-linkt.active').first();
33        const activeId = $activeTab.attr('id') || '';
34        let list = [];
35        let selectedId = '';
36
37        if (activeId === 'tab-bank') {
38            list = records.bankTransfers || [];
39            selectedId = $('#bankTransferSelect').val();
40        } else if (activeId === 'tab-mobile') {
41            list = records.mobileMoney || [];
42            selectedId = $('#mobileMoneySelect').val();
43        } else if (activeId === 'tab-crypto') {
44            list = records.cryptoMoney || [];
45            selectedId = $('#cryptoMoneySelect').val();
46        } else if (activeId.indexOf('tab-p2p-') === 0) {
47            list = records.p2pPayments || [];
48            const label = $activeTab.find('.tumaz_mob_tab_menu').clone().children().remove().end().text().trim().toLowerCase();
49            return list.find(function (record) {
50                return String(record.name || '').trim().toLowerCase() === label;
51            }) || null;
52        }
53
54        return list.find(function (record) { return String(record.id) === String(selectedId); }) || list[0] || null;
55    }
56
57    function updatePopupOrderTotal(data) {
58        const amountString = String(data.amount || '0');
59        const amountNumber = parseFloat(amountString.replace(/,/g, ''));
60        const context = window.digagesDirectPaymentContext || {};
61
62        context.amount = amountString;
63        if (data.currency) context.currency = data.currency;
64        window.digagesDirectPaymentContext = context;
65
66        if (typeof window.digagesApplyOrderContext === 'function') {
67            window.digagesApplyOrderContext();
68        } else if (!isNaN(amountNumber)) {
69            $('.digages-woodp-order-amount').text(amountNumber.toLocaleString());
70            $('.digages-woodp-order-amount-simplified, .digages-woodp-order-amount-simplifiedqq').text(amountString);
71            if (data.currency) $('.digages-woodp-order-currency').text(data.currency);
72        }
73
74        if (data.formattedTotal) {
75            const formattedAmountHtml = $(data.formattedTotal).first().html();
76            if (formattedAmountHtml) {
77                $('.woocommerce-checkout-review-order-table tr.order-total .woocommerce-Price-amount.amount').html(formattedAmountHtml);
78            }
79        }
80        $(document).trigger('digages:popup-total-updated', [data]);
81    }
82
83    function syncActivePopupFee(records) {
84        latestPopupRecords = records || latestPopupRecords;
85        const orderId = getPopupOrderId();
86        const record = getActivePopupRecord(latestPopupRecords);
87
88        if (!orderId || !record || !record.recordId || !window.ajax_object || !ajax_object.ajaxurl) return;
89
90        const selectionKey = orderId + ':' + record.recordId;
91        if (selectionKey === lastPopupFeeSelection) return;
92        lastPopupFeeSelection = selectionKey;
93
94        if (popupFeeRequest && popupFeeRequest.abort) popupFeeRequest.abort();
95        popupFeeRequest = $.ajax({
96            url: ajax_object.ajaxurl,
97            method: 'POST',
98            data: {
99                action: 'digages_woodp_select_popup_record',
100                nonce: ajax_object.nonce,
101                order_id: orderId,
102                order_key: getPopupOrderKey(),
103                record_id: record.recordId
104            }
105        }).done(function (response) {
106            if (response && response.success && response.data) {
107                updatePopupOrderTotal(response.data);
108            } else if (selectionKey === lastPopupFeeSelection) {
109                lastPopupFeeSelection = '';
110            }
111        }).fail(function (xhr, status) {
112            if (status !== 'abort' && selectionKey === lastPopupFeeSelection) {
113                lastPopupFeeSelection = '';
114            }
115        }).always(function () {
116            popupFeeRequest = null;
117        });
118    }
119
120    function removeEmptyQr(scope) {
121        $(scope).find('.digages_woodp_qrcimgBox').each(function () {
122            const $box = $(this);
123            const src = String($box.find('.digages_woodp_qrcmyImg').first().attr('src') || '').trim();
124
125            if (src) {
126                return;
127            }
128
129            const $section = $box.parent();
130            $section.find('.digages-qrcodepop').remove();
131            $section.find('.digages-actdetailpop').hide();
132            $section.find('.digages-detailspopshow').show();
133            $box.remove();
134        });
135    }
136
137    // Function to populate the select dropdown
138    function populateSelect(id, data) {
139        const $select = $(id);
140        const records = Array.isArray(data) ? data : [];
141        $select.empty(); // Clear previous options
142        records.forEach((record) => {
143            $select.append(new Option(record.name, record.id)); // Add new options
144        });
145    }
146
147    // Function to populate the record container
148    function populateRecords(id, data) {
149        const $container = $(id);
150        const records = Array.isArray(data) ? data : [];
151        $container.empty(); // Clear previous records
152        if (records.length > 0) {
153            const firstRecord = records[0]; // Display the first record's details by default
154            $container.html(firstRecord.details || '');
155            removeEmptyQr($container);
156            syncOrderContext();
157        }
158    }
159
160    // Function to update record details when the select changes
161    function showRecordDetails(selectId, containerId, data) {
162        const records = Array.isArray(data) ? data : [];
163
164        $(selectId).off('change.digages').on('change.digages', function () {
165            const selectedId = $(this).val();
166            const record = records.find(r => r.id == selectedId); // Find the selected record by ID
167            $(containerId).html(record ? (record.details || '') : 'No details available');
168            removeEmptyQr(containerId);
169            syncOrderContext();
170            syncActivePopupFee(latestPopupRecords);
171        });
172    }
173
174    function applyCheckoutContextVisibility(records) {
175        const context = (window.digagesDirectPaymentContext && window.digagesDirectPaymentContext.selectedRecord) || $('input[name="payment_method"]:checked').val() || '';
176        if (!context) return;
177
178        const availability = {
179            bank: Array.isArray(records.bankTransfers) && records.bankTransfers.length > 0,
180            mobile: Array.isArray(records.mobileMoney) && records.mobileMoney.length > 0,
181            crypto: Array.isArray(records.cryptoMoney) && records.cryptoMoney.length > 0
182        };
183        ['bank', 'mobile', 'crypto'].forEach(function (type) {
184            $('#tab-' + type).closest('.digages-woodp-nav-linktbg').toggle(availability[type]);
185            $('#' + type).toggle(availability[type]);
186        });
187
188        const p2pNames = (records.p2pPayments || []).map(function (record) { return String(record.name || '').trim().toLowerCase(); });
189        $('.nav-linkt[id^="tab-p2p-"]').each(function () {
190            const visible = p2pNames.indexOf($(this).text().trim().toLowerCase()) !== -1;
191            $(this).closest('.digages-woodp-nav-linktbg').toggle(visible);
192            $($(this).attr('href')).toggle(visible);
193        });
194
195        const $active = $('.nav-linkt:visible').first();
196        if ($active.length) {
197            $('.nav-linkt').removeClass('active').attr('aria-selected', 'false');
198            $('.tab-pane').removeClass('show active').attr('aria-hidden', 'true');
199            $active.addClass('active').attr('aria-selected', 'true');
200            $($active.attr('href')).addClass('show active').attr('aria-hidden', 'false').show();
201        }
202    }
203
204    // Function to fetch data and populate the relevant sections
205    function fetchData() {
206        $.ajax({
207            url: ajax_object.ajaxurl, // Fetch data from server via AJAX
208            method: 'POST',
209            data: {
210                action: 'digages_fetch_payment_methods', // Server-side action to get the data
211                nonce: ajax_object.nonce, // Nonce for security
212                payment_gateway: $('input[name="payment_method"]:checked').val() || '',
213                record_id: (window.digagesDirectPaymentContext && window.digagesDirectPaymentContext.selectedRecord) || '',
214                order_id: (window.digagesDirectPaymentContext && window.digagesDirectPaymentContext.orderId) || '',
215                order_key: window.digagesOrderKey || (window.digagesDirectPaymentContext && window.digagesDirectPaymentContext.orderKey) || ''
216            },
217            success: function (response) {
218                if (response.success) {
219                    const records = response.data || {};
220
221                    applyCheckoutContextVisibility(records);
222
223                    // Populate and bind events for Bank Transfers
224                    populateSelect('#bankTransferSelect', records.bankTransfers);
225                    populateRecords('#bankTransferRecords', records.bankTransfers);
226                    showRecordDetails('#bankTransferSelect', '#bankTransferRecords', records.bankTransfers);
227
228                    // Populate and bind events for Mobile Money
229                    populateSelect('#mobileMoneySelect', records.mobileMoney);
230                    populateRecords('#mobileMoneyRecords', records.mobileMoney);
231                    showRecordDetails('#mobileMoneySelect', '#mobileMoneyRecords', records.mobileMoney);
232
233                    // Populate and bind events for Crypto
234                    populateSelect('#cryptoMoneySelect', records.cryptoMoney);
235                    populateRecords('#cryptoMoneyRecords', records.cryptoMoney);
236                    showRecordDetails('#cryptoMoneySelect', '#cryptoMoneyRecords', records.cryptoMoney);
237
238                    // Populate and bind events for P2P Payments
239                    populateSelect('#p2pSelect', records.p2pPayments);
240                    populateRecords('#p2pRecords', records.p2pPayments);
241                    showRecordDetails('#p2pSelect', '#p2pRecords', records.p2pPayments);
242                    syncActivePopupFee(records);
243                } else {
244                    
245                }
246            },
247            error: function (xhr, status, error) {
248
249                
250            }
251        });
252    }
253
254    // Remove an empty inline QR block (for example, the P2P method) and then
255    // fetch the dynamically rendered payment-method records.
256    removeEmptyQr(document);
257
258    // Fetch data on page load
259    fetchData();
260
261    $(document).on('digages:order-context-ready', fetchData);
262
263    // Refresh the popup data if the customer switches between a combined
264    // Direct Payments option and a record shown as its own gateway.
265    $(document.body).on('change', 'input[name="payment_method"]', fetchData);
266
267    $(document).on('shown.bs.tab', '.nav-linkt', function () {
268        syncActivePopupFee(latestPopupRecords);
269    });
270    $(document).on('click touchend', '.nav-linkt', function () {
271        window.setTimeout(function () { syncActivePopupFee(latestPopupRecords); }, 0);
272    });
273    $('#exampleModal').on('shown.bs.modal', function () {
274        syncActivePopupFee(latestPopupRecords);
275    });
276
277    // Handle screenshot upload
278    $('#uploadScreenshot').on('click', function () {
279        const file = $('#screenshotFile')[0].files[0];
280        if (file) {
281            // Add your logic to handle file upload here
282            alert('Screenshot uploaded: ' + file.name);
283            $('#screenshotModal').modal('hide');
284        } else {
285            alert('Please select a screenshot file.');
286        }
287    });
288
289    // Handle confirm buttons for various payment methods
290    $('#confirmBankTransfer').on('click', function () {
291        alert('Bank Transfer Confirmed');
292    });
293
294    $('#confirmMobileMoney').on('click', function () {
295        alert('Mobile Money Confirmed');
296    });
297
298    $('#confirmP2P').on('click', function () {
299        alert('Peer-to-Peer Payment Confirmed');
300    });
301
302    
303        // Update this event handler to send mail when the div is clicked
304        $(document).on('click', '.sendmail', function(e) {
305            e.preventDefault(); // Prevent default action
306    
307            let selectedMethodTitle = $('.nav-link.active').first().text().trim();
308            let orderId = $('.orderNumberDisplay').text().trim();
309            let selectedDetails = $('.tab-pane.active .record-container').html();
310            let customerFullName = $('input[name="billing_full_name"]').val(); // Assuming this field exists
311            let paymentDate = new Date().toISOString();
312    
313            // console.log('Collected data:', {
314            //     selectedMethodTitle,
315            //     orderId,
316            //     selectedDetails,
317            //     customerFullName,
318            //     paymentDate
319            // }); // For debugging
320    
321            // Perform AJAX request to send the email
322            $.ajax({
323                url: ajax_object.ajaxurl,
324                method: 'POST',
325                data: {
326                    action: 'send_payment_details_email',
327                    nonce: ajax_object.nonce,
328                    order_id: orderId,
329                    payment_method: selectedMethodTitle,
330                    payment_details: selectedDetails,
331                    customer_name: customerFullName,
332                    payment_date: paymentDate
333                },
334                success: function(response) {
335                    //console.log('AJAX response:', response); // Debugging
336                    if (response.success) {
337                        alert('Payment details sent successfully!');
338                        // You can add more logic here if needed, like redirect or UI update
339                    } else {
340                        alert('Failed to send payment details. Please try again.');
341                    }
342                },
343                error: function(xhr, status, error) {
344                    console.error('AJAX Error:', error);
345                    alert('An error occurred. Please try again later.');
346                }
347            });
348        });
349    
350            
351        
352});

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.