diff options
| author | Dhruv Dawar <dhruvdawar@Apples-MacBook-Air.local> | 2026-06-13 11:00:10 +0530 |
|---|---|---|
| committer | Dhruv Dawar <dhruvdawar@Apples-MacBook-Air.local> | 2026-06-13 11:00:10 +0530 |
| commit | 2dd292e3d0f26002a8349c05a39e8f8472bb810f (patch) | |
| tree | 6d42138ff18837f9bfa17ccf3e9efd8ba57b6617 | |
| parent | 0c69e93d57ffaaee34a672311a4511299d9e9760 (diff) | |
payment migration: purged snipcart and initialized native browser PaymentRequest API
| -rw-r--r-- | app.js | 71 | ||||
| -rw-r--r-- | index.html | 17 | ||||
| -rw-r--r-- | style.css | 92 |
3 files changed, 75 insertions, 105 deletions
@@ -2,6 +2,7 @@ let stampsData = []; let activeFilter = 'all'; let audioCtx = null; +// --- Web Audio API UI Sound Synthesis Core --- function initAudio() { if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)(); } @@ -12,7 +13,7 @@ function playClickSound() { osc.connect(gainNode); gainNode.connect(audioCtx.destination); osc.type = 'triangle'; osc.frequency.setValueAtTime(120, audioCtx.currentTime); osc.frequency.exponentialRampToValueAtTime(40, audioCtx.currentTime + 0.05); - gainNode.gain.setValueAtTime(0.15, audioCtx.currentTime); gainNode.gain.exponentialRampToValueAtTime(0.01, application_time => audioCtx.currentTime + 0.05); + gainNode.gain.setValueAtTime(0.15, audioCtx.currentTime); gainNode.gain.exponentialRampToValueAtTime(0.01, audioCtx.currentTime + 0.05); osc.start(); osc.stop(audioCtx.currentTime + 0.05); } @@ -26,13 +27,14 @@ function playPopSound() { osc.start(); osc.stop(audioCtx.currentTime + 0.12); } +// --- Store Interface Operations Routine --- async function initStore() { try { const res = await fetch('catalog.json'); stampsData = await res.json(); renderGrid(stampsData); document.querySelectorAll('header button').forEach(btn => btn.addEventListener('mousedown', playClickSound)); - } catch (err) { console.error("Asset tracking layout fault:", err); } + } catch (err) { console.error("Asset catalog initialization fault:", err); } } function setFilter(type) { activeFilter = type; filterCatalog(); } @@ -53,6 +55,10 @@ function renderGrid(items) { items.forEach(stamp => { const el = document.createElement('div'); el.className = 'card'; + + // Stringify and escape item data payload to pass it safely into the native API button click listener + const stampString = JSON.stringify(stamp).replace(/"/g, '"'); + el.innerHTML = ` <img src="${stamp.img}" alt="${stamp.name}" loading="lazy"> <div class="card-info"> @@ -62,10 +68,65 @@ function renderGrid(items) { </div> <div> <span class="price">$${stamp.price.toFixed(2)}</span> - <button class="snipcart-add-item" data-item-id="${stamp.id}" data-item-name="${stamp.name}" data-item-price="${stamp.price}" data-item-url="/" data-item-image="${stamp.img}" ${stamp.type === 'individual' ? 'data-item-max-quantity="1"' : ''}>Add to Cart</button> + <button class="buy-button" onclick="nativeCheckout('${stampString}')">Buy Now</button> </div>`; - el.querySelector('.snipcart-add-item').addEventListener('mousedown', playPopSound); grid.appendChild(el); }); } -window.onload = initStore;
\ No newline at end of file + +// --- Native 100% Dependency-Free Browser Checkout Engine --- +async function nativeCheckout(stampDataRaw) { + playPopSound(); // Trigger your custom synthesized audio reward feedback chime + + if (!window.PaymentRequest) { + alert("Your browser does not support native web payments. To test, please access this site via a modern mobile browser (Safari/Chrome)."); + return; + } + + try { + const stamp = JSON.parse(stampDataRaw.replace(/"/g, '"')); + + // 1. Declare Supported Transaction Methods (Visa, Mastercard, Apple Pay/Google Pay tokens) + const supportedMethods = [{ + supportedMethods: 'basic-card', + data: { supportedNetworks: ['visa', 'mastercard', 'amex', 'discover'] } + }]; + + // 2. Define the Active Invoice Pricing Totals + const paymentDetails = { + total: { + label: 'Total Purchase Amount', + amount: { currency: 'USD', value: stamp.price.toString() } + }, + displayItems: [{ + label: `${stamp.name} (Scott #${stamp.scott})`, + amount: { currency: 'USD', value: stamp.price.toString() } + }] + }; + + // 3. User Shipping & Profile Parameters Options + const options = { + requestShipping: true, + requestPayerEmail: true, + requestPayerPhone: true + }; + + // Initialize Request and Invoke the Browser's Native Overlay UI Sheet + const request = new PaymentRequest(supportedMethods, paymentDetails, options); + const paymentResponse = await request.show(); + + // ---> Your Secure Transaction Processing Hooks Happen Here <--- + console.log("Secure Card Details Token:", paymentResponse.details); + console.log("Collector Delivery Address:", paymentResponse.shippingAddress); + console.log("Collector Contact:", paymentResponse.payerEmail, paymentResponse.payerPhone); + + // Close the native browser card drawer UI successfully + await paymentResponse.complete('success'); + alert(`Success! Order for "${stamp.name}" initialized. Detailed transaction records logged to your developer console.`); + + } catch (err) { + console.error("Native transaction request interrupted or closed:", err); + } +} + +window.onload = initStore; @@ -5,11 +5,8 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>King of Stamps | Online Showcase</title> <link rel="stylesheet" href="style.css"> - <!-- Secondary clean body text typography from Bunny Fonts CDN --> + <!-- Fetching secondary clean body text typography from Bunny Fonts CDN --> <link href="https://bunny.net" rel="stylesheet"> - <link rel="preconnect" href="https://snipcart.com"> - <link rel="preconnect" href="https://snipcart.com"> - <link rel="stylesheet" href="https://snipcart.com/themes/v3.4.1/default/snipcart.css"> </head> <body> @@ -43,16 +40,6 @@ <main id="stamp-grid"></main> - <!-- Snipcart Checkout Middleware Engine --> - <script async src="https://snipcart.com/themes/v3.4.1/default/snipcart.js"></script> - <script> - window.SnipcartSettings = { - publicApiKey: 'NmRmNDU0ZGEtYTE3Yy00MTYzLTgzNDctMjE3OGU3YmZjZThiNjM5MTY4ODE3ODk3Njg4ODU2', - loadStrategy: 'on-user-interaction', - }; - - (()=>{var c,d;(d=(c=window.SnipcartSettings).version)!=null||(c.version="3.0");var s,S;(S=(s=window.SnipcartSettings).timeoutDuration)!=null||(s.timeoutDuration=2750);var l,p;(p=(l=window.SnipcartSettings).domain)!=null||(l.domain="cdn.snipcart.com");var w,u;(u=(w=window.SnipcartSettings).protocol)!=null||(w.protocol="https");var f=window.SnipcartSettings.version.includes("v3.0.0-ci")||window.SnipcartSettings.version!="3.0"&&window.SnipcartSettings.version.localeCompare("3.4.0",void 0,{numeric:!0,sensitivity:"base"})===-1,m=["focus","mouseover","touchmove","scroll","keydown"];window.LoadSnipcart=o;document.readyState==="loading"?document.addEventListener("DOMContentLoaded",r):r();function r(){window.SnipcartSettings.loadStrategy?window.SnipcartSettings.loadStrategy==="on-user-interaction"&&(m.forEach(t=>document.addEventListener(t,o)),setTimeout(o,window.SnipcartSettings.timeoutDuration)):o()}var a=!1;function o(){if(a)return;a=!0;let t=document.getElementsByTagName("head")[0],e=document.querySelector("#snipcart"),i=document.querySelector(`src[src^="${window.SnipcartSettings.protocol}://${window.SnipcartSettings.domain}"][src$="snipcart.js"]`),n=document.querySelector(`link[href^="${window.SnipcartSettings.protocol}://${window.SnipcartSettings.domain}"][href$="snipcart.css"]`);e||(e=document.createElement("div"),e.id="snipcart",e.setAttribute("hidden","true"),document.body.appendChild(e)),v(e),i||(i=document.createElement("script"),i.src=`${window.SnipcartSettings.protocol}://${window.SnipcartSettings.domain}/themes/v${window.SnipcartSettings.version}/default/snipcart.js`,i.async=!0,t.appendChild(i)),n||(n=document.createElement("link"),n.rel="stylesheet",n.type="text/css",n.href=`${window.SnipcartSettings.protocol}://${window.SnipcartSettings.domain}/themes/v${window.SnipcartSettings.version}/default/snipcart.css`,t.prepend(n)),m.forEach(g=>document.removeEventListener(g,o))}function v(t){!f||(t.dataset.apiKey=window.SnipcartSettings.publicApiKey,window.SnipcartSettings.addProductBehavior&&(t.dataset.configAddProductBehavior=window.SnipcartSettings.addProductBehavior),window.SnipcartSettings.modalStyle&&(t.dataset.configModalStyle=window.SnipcartSettings.modalStyle),window.SnipcartSettings.currency&&(t.dataset.currency=window.SnipcartSettings.currency),window.SnipcartSettings.templatesUrl&&(t.dataset.templatesUrl=window.SnipcartSettings.templatesUrl))}})(); -</script> <script src="app.js"></script> </body> -</html>
\ No newline at end of file +</html> @@ -1,7 +1,7 @@ /* --- 1. Custom Typography Import Engine (Ortland OTF mapping) --- */ @font-face { font-family: 'Ortland'; - src: url('fonts/ortland.otf') format('opentype'); /* Configured specifically for your .otf binary asset */ + src: url('fonts/ortland.otf') format('opentype'); /* Configured specifically for your local .otf asset binary */ font-weight: 900; font-style: normal; font-display: swap; @@ -225,8 +225,8 @@ header button:hover { background-color: var(--neon-white); color: var(--bg-color .price { font-family: var(--heavy-font); font-size: 2rem; color: var(--neon-white); margin: 15px 0 10px 0; display: block; } -/* --- 3D Cart Action Trigger Triggers --- */ -.snipcart-add-item { +/* --- Native 3D Buy Button Trigger --- */ +.buy-button { width: 100%; background: var(--stamp-border); color: var(--neon-white); @@ -238,11 +238,11 @@ header button:hover { background-color: var(--neon-white); color: var(--bg-color text-transform: uppercase; padding: 16px; cursor: pointer; - transition: transform 0.05s ease, border-bottom-width 0.05s ease; + transition: transform 0.05s ease, border-bottom-width 0.05s ease, background-color 0.1s ease; user-select: none; } -.snipcart-add-item:hover { background: #ff5c8a; } -.snipcart-add-item:active { transform: translateY(6px); border-bottom-width: 0px; } +.buy-button:hover { background: #ff5c8a; } +.buy-button:active { transform: translateY(6px); border-bottom-width: 0px; } .no-results { grid-column: 1/-1; text-align: center; font-family: var(--heavy-font); color: #333; font-size: 2rem; text-transform: uppercase; padding: 80px 0; } @@ -255,7 +255,7 @@ header button:hover { background-color: var(--neon-white); color: var(--bg-color } /* ========================================================================== - 4. Mobile Breakpoint Media Queries (Unifies structural mobile mechanics) + 3. Mobile Breakpoint Media Queries (Unifies structural mobile mechanics) ========================================================================== */ @media (max-width: 820px) { body { padding: 0 20px 20px 20px; } @@ -301,81 +301,3 @@ header button:hover { background-color: var(--neon-white); color: var(--bg-color #stamp-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px; } } -/* ========================================================================== - 5. Custom Snipcart Overrides (Matches Your Brutalist Theme) - ========================================================================== */ - -/* Change the main backdrop overlay behind the sliding cart panel */ -#snipcart .snipcart-modal { - background-color: rgba(0, 0, 0, 0.85) !important; - backdrop-filter: blur(4px); -} - -/* Force the checkout sidebar to use your pitch black theme colors */ -#snipcart .snipcart-cart, -#snipcart .snipcart-layout { - background-color: #000000 !important; - color: #ffffff !important; - font-family: 'Space Grotesk', sans-serif !important; -} - -/* Stylize checkout headings with your bold Ortland display style */ -#snipcart .snipcart__title, -#snipcart .snipcart-cart-header__title { - font-family: 'Ortland', 'Impact', sans-serif !important; - text-transform: uppercase !important; - color: #ffffff !important; - letter-spacing: -0.5px !important; -} - -/* Turn Snipcart item list frames into dark charcoal blocks */ -#snipcart .snipcart-item-line, -#snipcart .snipcart-layout__sidebar { - background-color: #111111 !important; - border: 2px solid #222222 !important; - border-radius: 16px !important; - margin-bottom: 15px !important; - padding: 15px !important; -} - -/* Make checkout form input fields thick and 3D */ -#snipcart .snipcart-input__input { - background-color: #1a1a1a !important; - border: 2px solid #ffffff !important; - color: #ffffff !important; - border-radius: 12px !important; - font-weight: 700 !important; -} -#snipcart .snipcart-input__input:focus { - border-color: #ff3366 !important; -} - -/* Turn standard buttons into chunky 3D electric pink buttons */ -#snipcart .snipcart-base-button { - background-color: #ff3366 !important; - color: #ffffff !important; - font-family: 'Ortland', sans-serif !important; - font-size: 1.1rem !important; - text-transform: uppercase !important; - border-radius: 16px !important; - border-bottom: 5px solid #b30030 !important; /* Satisfying 3D button floor base */ - transition: transform 0.05s ease, border-bottom-width 0.05s ease !important; -} - -#snipcart .snipcart-base-button:hover { - background-color: #ff5c8a !important; -} - -#snipcart .snipcart-base-button:active { - transform: translateY(4px) !important; - border-bottom-width: 0px !important; -} - -/* Highlight total prices and active links in electric pink */ -#snipcart .snipcart-summary-fees__amount, -#snipcart .snipcart-cart-summary__total-number, -#snipcart .snipcart-item-line__price { - color: #ff3366 !important; - font-family: 'Space Grotesk', sans-serif !important; - font-weight: 700 !important; -} |
