diff options
| author | Dhruv Dawar <dhruvdawar@Apples-MacBook-Air.local> | 2026-06-13 11:03:32 +0530 |
|---|---|---|
| committer | Dhruv Dawar <dhruvdawar@Apples-MacBook-Air.local> | 2026-06-13 11:03:32 +0530 |
| commit | be47fa9243977f6e342300800ccaab94ceb0aad1 (patch) | |
| tree | 66e5a6afc1697f069a74cc09a7061a58f42695c3 | |
| parent | 2dd292e3d0f26002a8349c05a39e8f8472bb810f (diff) | |
fix: replaced deprecated payment api with native whatsapp checkout hook
| -rw-r--r-- | app.js | 84 |
1 files changed, 30 insertions, 54 deletions
@@ -56,7 +56,7 @@ 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 + // Stringify and escape item data payload safely const stampString = JSON.stringify(stamp).replace(/"/g, '"'); el.innerHTML = ` @@ -68,65 +68,41 @@ function renderGrid(items) { </div> <div> <span class="price">$${stamp.price.toFixed(2)}</span> - <button class="buy-button" onclick="nativeCheckout('${stampString}')">Buy Now</button> + <!-- Invokes our bulletproof custom checkout function --> + <button class="buy-button" onclick="checkout('${stampString}')">Buy Now</button> </div>`; grid.appendChild(el); }); } -// --- Native 100% Dependency-Free Browser Checkout Engine --- -async function nativeCheckout(stampDataRaw) { - playPopSound(); // Trigger your custom synthesized audio reward feedback chime +// --- Native WhatsApp Checkout Hook API --- +function checkout(stampDataRaw) { + playPopSound(); // Retain your custom synthesized audio reward 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); - } + const stamp = JSON.parse(stampDataRaw.replace(/"/g, '"')); + + // 1. Put your real phone number here (with country code, no spaces or '+' symbol) + const MY_PHONE_NUMBER = "919999999999"; + + // 2. Build the template string order message + const messageText = +`👑 *NEW STAMP ORDER - KING OF STAMPS* 👑 +--------------------------------------- +📦 *Product:* ${stamp.name} +🔢 *Scott #:* ${stamp.scott} +✨ *Condition:* ${stamp.condition} +🆔 *SKU/ID:* ${stamp.id} +--------------------------------------- +💰 *Price:* $${stamp.price.toFixed(2)} + +Hello! I want to purchase this stamp from your collection. Please send your payment details/UPI ID so I can complete the transaction!`; + + // 3. Cleanly encode the text layout blocks into web-safe URL coordinates + const encodedMessage = encodeURIComponent(messageText); + const whatsappUrl = `https://whatsapp.com{MY_PHONE_NUMBER}&text=${encodedMessage}`; + + // 4. Force browser window redirect directly to the chat + window.open(whatsappUrl, '_blank'); } window.onload = initStore; |
