PageSourceSearch

https://ail-lab-sistema-cristales.web.app/js/payment-config.js?v=20260427

js ail-lab-sistema-cristales.web.app collected 2026-10-03 12:16:05 UTC 5,267 bytes, 94 lines download raw bytes

1// Configuración de pagos (frontend)
2// Opción rápida: pegar un link de pago fijo de Mercado Pago en checkoutLink.
3// Opción avanzada: usar createPreferenceUrl para generar link dinámico por pedido.
4window.PAYMENT_CONFIG = {
5    provider: 'mercadopago',
6    checkoutLink: '', // Ej: 'https://link.mercadopago.cl/tu-link'
7    createPreferenceUrl: 'https://us-central1-ail-lab-sistema-cristales.cloudfunctions.net/createPaymentPreference',
8    /** Tras abonar crédito (panel empresa); misma región que createPaymentPreference. */
9    finalizeAbonoCreditoUrl: 'https://us-central1-ail-lab-sistema-cristales.cloudfunctions.net/finalizeAbonoCredito',
10    checkPaymentStatusUrl: 'https://us-central1-ail-lab-sistema-cristales.cloudfunctions.net/checkPaymentStatus',
11    emitirFacturaBsaleUrl: 'https://us-central1-ail-lab-sistema-cristales.cloudfunctions.net/emitirFacturaBsale',
12    // Producción: solo se usa init_point de Mercado Pago (no sandbox).
13    useProductionCheckout: true,
14    successMessage: 'Abre Mercado Pago y completa el pago. Luego vuelve para confirmar.',
15    /* Botones rápidos Pago $10.000 / $20.000 / $30.000 desactivados en la interfaz B2B (óptica / encargado). */
16    quickPaymentPlans: []
17};
18
19(function applyStoredPaymentConfig() {
20    try {
21        const raw = localStorage.getItem('ail_payment_config');
22        if (!raw) return;
23        const o = JSON.parse(raw);
24        if (typeof o.checkoutLink === 'string') window.PAYMENT_CONFIG.checkoutLink = o.checkoutLink;
25        if (typeof o.createPreferenceUrl === 'string') window.PAYMENT_CONFIG.createPreferenceUrl = o.createPreferenceUrl;
26        if (typeof o.finalizeAbonoCreditoUrl === 'string') window.PAYMENT_CONFIG.finalizeAbonoCreditoUrl = o.finalizeAbonoCreditoUrl;
27        if (typeof o.checkPaymentStatusUrl === 'string') window.PAYMENT_CONFIG.checkPaymentStatusUrl = o.checkPaymentStatusUrl;
28        if (typeof o.useProductionCheckout === 'boolean') window.PAYMENT_CONFIG.useProductionCheckout = o.useProductionCheckout;
29    } catch (e) {
30        console.warn('No se pudo aplicar ail_payment_config:', e);
31    }
32})();
33
34document.addEventListener('DOMContentLoaded', function () {
35    const prefEl = document.getElementById('mp-pref-url');
36    const linkEl = document.getElementById('mp-link-url');
37    const saveBtn = document.getElementById('mp-save-payment-config');
38    const clearBtn = document.getElementById('mp-clear-payment-config');
39    const quickButtonsContainer = document.getElementById('quick-payment-buttons');
40
41    function renderQuickButtons() {
42        if (!quickButtonsContainer) return;
43        const plans = Array.isArray(window.PAYMENT_CONFIG.quickPaymentPlans) ? window.PAYMENT_CONFIG.quickPaymentPlans : [];
44        if (plans.length === 0) {
45            quickButtonsContainer.remove();
46            return;
47        }
48        const buttons = quickButtonsContainer.querySelectorAll('button');
49        plans.slice(0, 3).forEach((plan, index) => {
50            const button = buttons[index];
51            if (!button) return;
52            const amount = Number(plan.amount) || 0;
53            button.textContent = `${plan.label || `Pago ${index + 1}`} - $${amount.toLocaleString('es-CL')}`;
54        });
55    }
56
57    if (prefEl) prefEl.value = window.PAYMENT_CONFIG.createPreferenceUrl || '';
58    if (linkEl) linkEl.value = window.PAYMENT_CONFIG.checkoutLink || '';
59    renderQuickButtons();
60
61    if (saveBtn) {
62        saveBtn.addEventListener('click', function () {
63            const createPreferenceUrl = prefEl ? prefEl.value.trim() : '';
64            const checkoutLink = linkEl ? linkEl.value.trim() : '';
65            const payload = {
66                createPreferenceUrl,
67                finalizeAbonoCreditoUrl: window.PAYMENT_CONFIG.finalizeAbonoCreditoUrl,
68                checkPaymentStatusUrl: window.PAYMENT_CONFIG.checkPaymentStatusUrl,
69                checkoutLink,
70                useProductionCheckout: true,
71                quickPaymentPlans: []
72            };
73            localStorage.setItem('ail_payment_config', JSON.stringify(payload));
74            Object.assign(window.PAYMENT_CONFIG, payload);
75            renderQuickButtons();
76            alert('Configuración de pago guardada en este navegador.');
77        });
78    }
79    if (clearBtn) {
80        clearBtn.addEventListener('click', function () {
81            localStorage.removeItem('ail_payment_config');
82            window.PAYMENT_CONFIG.checkoutLink = '';
83            window.PAYMENT_CONFIG.createPreferenceUrl = 'https://us-central1-ail-lab-sistema-cristales.cloudfunctions.net/createPaymentPreference';
84            window.PAYMENT_CONFIG.finalizeAbonoCreditoUrl = 'https://us-central1-ail-lab-sistema-cristales.cloudfunctions.net/finalizeAbonoCredito';
85            window.PAYMENT_CONFIG.checkPaymentStatusUrl = 'https://us-central1-ail-lab-sistema-cristales.cloudfunctions.net/checkPaymentStatus';
86            window.PAYMENT_CONFIG.useProductionCheckout = true;
87            window.PAYMENT_CONFIG.quickPaymentPlans = [];
88            if (prefEl) prefEl.value = window.PAYMENT_CONFIG.createPreferenceUrl;
89            if (linkEl) linkEl.value = '';
90            renderQuickButtons();
91            alert('Se restauró la configuración por defecto (solo en esta pestaña).');
92        });
93    }
94});

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.