All Backdrops
Loading products...
'); win.document.close(); win.focus(); setTimeout(function(){ win.print(); }, 600); }; /* ── DELIVERY FORM ── */ window.showDeliveryForm = function(total){ $('right-content').innerHTML = '
' + '
' + '

📦 Delivery Details

' + '

We use these only to ship your order.

' + '
' + '' + '' + '
' + '' + '' + '' + '
' + '' + '' + '
' + '' + '' + '
'; }; window.validateAndPay = function(total){ var name = ($('f-name') ||{}).value||''; var phone = ($('f-phone') ||{}).value||''; var addr = ($('f-addr') ||{}).value||''; var city = ($('f-city') ||{}).value||''; var pin = ($('f-pin') ||{}).value||''; var state = ($('f-state') ||{}).value||''; if(!name.trim()||!addr.trim()||!city.trim()||!state.trim()){ toast('Please fill all required fields'); return; } if(!/^[6-9]\d{9}$/.test(phone.trim())){ toast('Enter valid 10-digit phone number'); return; } if(!/^\d{6}$/.test(pin.trim())){ toast('Enter valid 6-digit pincode'); return; } window._cust = { customer_name: name.trim(), phone: phone.trim(), email: (($('f-email')||{}).value||'').trim(), address: addr.trim(), address2: (($('f-addr2')||{}).value||'').trim(), city: city.trim(), pincode: pin.trim(), state: state.trim() }; processPayment(total); }; window.processPayment = function(total){ $('right-content').innerHTML = '
Creating order…
'; var xhr = new XMLHttpRequest(); xhr.open('POST', PAYMENT_URL, true); xhr.setRequestHeader('Content-Type', 'text/plain'); xhr.timeout = 30000; xhr.ontimeout = function(){ toast('Request timed out.'); showInvoice(total); }; xhr.onerror = function(){ toast('Network error.'); showInvoice(total); }; xhr.onload = function(){ var order; try { order = JSON.parse(xhr.responseText); } catch(e){ toast('Invalid response.'); return; } if(order.error){ toast('Order failed: ' + order.error); return; } var cap = total; var open = function(){ var rzp = new window.Razorpay({ key: RAZORPAY_KEY, amount: order.amount, currency: order.currency||'INR', order_id: order.id, name: 'Backdrop Store', description: 'Backdrop Store Order', handler: function(r){ completeOrder(cap, r.razorpay_payment_id, r.razorpay_order_id); }, prefill: { name:'', email:'', contact:'' }, theme: { color:'#6366f1' }, modal: { ondismiss: function(){ toast('Payment cancelled'); } } }); rzp.open(); }; if(window.Razorpay) open(); else { var s = document.createElement('script'); s.src = 'https://checkout.razorpay.com/v1/checkout.js'; s.onload = open; document.head.appendChild(s); } }; xhr.send(JSON.stringify({ action:'create_order', amount:total })); }; window.completeOrder = function(total, payId, rzpId){ $('right-content').innerHTML = '
Processing…
'; var sub = CART.reduce(function(s,i){ return s + i.price * i.qty; }, 0); var gst = Math.round(sub * 0.18); var xhr = new XMLHttpRequest(); xhr.open('POST', PAYMENT_URL, true); xhr.setRequestHeader('Content-Type', 'text/plain'); xhr.timeout = 30000; xhr.onload = function(){ var r; try{ r = JSON.parse(xhr.responseText); } catch(e){ r = {}; } showSuccess(total, payId, r.awb||''); }; xhr.onerror = function(){ showSuccess(total, payId, ''); }; xhr.ontimeout = function(){ showSuccess(total, payId, ''); }; xhr.send(JSON.stringify(Object.assign({}, window._cust||{}, { action:'complete_order', payment_id:payId, razorpay_order_id:rzpId, items:CART, subtotal:sub, gst:gst, total:total }))); }; function showSuccess(total, payId, awb){ var c = window._cust || {}; $('right-content').innerHTML = '
' + '
' + '

Order Placed!

' + '

Payment successful. Your order is confirmed.

' + '
' + 'Payment ID: ' + payId + '
Amount: ' + fmt(total) + (c.customer_name ? '
Delivering to: ' + c.customer_name + ', ' + (c.city||'') : '') + '
' + (awb ? '
🚚 Tracking AWB: ' + awb + '
' : '') + '' + '
'; CART = []; saveCart(); updateCartBadge(); try{ sessionStorage.removeItem('bs_sess_v4'); }catch(e){} } function updateCartBadge(){ var count = CART.reduce(function(a,b){ return a + b.qty; }, 0); var el = $('cart-nav-count'); if(el){ el.textContent = count; el.style.display = count > 0 ? 'inline' : 'none'; } } function restoreSession(){ var sess = loadSession(); if(sess && sess.pName){ currentSelection = sess; renderSidebar(); applyFilters(); showDetail(sess.cat, sess.sub, sess.pName); } else { clearDetail(); } } /* ── INIT ── */ updateCartBadge(); fetchData(); })(window, document);