top of page
Blueo Premium Quality Tempered Glass for iPhone Samsung

import { ok } from "wix-http-functions"; import { getSecret } from "wix-secrets-backend"; import { syncSingleShiprocketOrder, syncShiprocketByAwb } from "backend/shiprocketSync"; // ============================================================ // RESPONSE HELPER // ============================================================ function jsonResponse(data) { return ok({ headers: { "Content-Type": "application/json" }, body: JSON.stringify( data, null, 2 ) }); } // ============================================================ // HELPERS // ============================================================ function cleanOrderNumber(value) { if ( value === undefined || value === null ) { return ""; } return String(value) .replace(/^#/, "") .trim(); } function cleanAwb(value) { if ( value === undefined || value === null ) { return ""; } return String(value) .trim(); } // ============================================================ // HEALTH CHECK // // https://www.blueo.in/_functions/orderTrackingWebhook // ============================================================ export async function get_orderTrackingWebhook() { return jsonResponse({ success: true, message: "Shiprocket → Wix webhook is operational" }); } // ============================================================ // SHIPROCKET WEBHOOK // // FLOW: // // Shiprocket // ↓ // tracking / AWB event // ↓ // Wix webhook // ↓ // authenticated Shiprocket API verification // ↓ // Wix fulfillment // ============================================================ export async function post_orderTrackingWebhook(request) { console.log( "==================================================" ); console.log( ">>> [SHIPROCKET] WEBHOOK RECEIVED" ); console.log( "==================================================" ); try { // ==================================================== // 1. WEBHOOK KEY // ==================================================== const expectedKey = await getSecret( "SHIPROCKET_WEBHOOK_KEY" ); const receivedKey = request.headers?.["x-api-key"] || request.headers?.["X-API-Key"] || request.headers?.["X-Api-Key"] || ""; // Some real Shiprocket webhooks are reaching Wix // without x-api-key. // // Missing key: // allow as trigger, but shiprocketSync.js will query // Shiprocket's authenticated API before modifying Wix. // // Wrong non-empty key: // reject. if (!receivedKey) { console.log( ">>> [SHIPROCKET] No x-api-key supplied - continuing with API verification" ); } else if ( receivedKey !== expectedKey ) { console.log( ">>> [SHIPROCKET] Ignored: invalid x-api-key" ); return jsonResponse({ success: true, action: "IGNORED_INVALID_API_KEY" }); } else { console.log( ">>> [SHIPROCKET] Authentication successful" ); } // ==================================================== // 2. PARSE BODY // ==================================================== let body; try { body = await request.body.json(); } catch (error) { console.error( ">>> [SHIPROCKET] Invalid JSON:", error ); return jsonResponse({ success: false, action: "INVALID_JSON" }); } console.log( ">>> [SHIPROCKET] RAW PAYLOAD:" ); console.log( JSON.stringify( body, null, 2 ) ); const data = body?.data || body; // ==================================================== // 3. CHANNEL / WIX ORDER NUMBER // ==================================================== const rawOrderNumber = data?.channel_order_id || data?.channel_order_number || data?.order_number || data?.wix_order_id || body?.channel_order_id || body?.channel_order_number || body?.order_number || body?.wix_order_id || null; // ==================================================== // 4. SHIPROCKET INTERNAL ORDER ID // // Logging only. // Never use as Wix order number. // ==================================================== const shiprocketOrderId = data?.order_id || body?.order_id || null; // ==================================================== // 5. AWB // ==================================================== const rawAwb = data?.awb || data?.awb_code || data?.awb_number || data?.shipment_awb || data?.tracking_number || body?.awb || body?.awb_code || body?.awb_number || body?.shipment_awb || body?.tracking_number || null; // ==================================================== // 6. COURIER // ==================================================== const courier = data?.courier_name || data?.courier || data?.shipping_provider || body?.courier_name || body?.courier || body?.shipping_provider || null; // ==================================================== // 7. STATUS // ==================================================== const status = data?.current_status || data?.shipment_status || data?.status || body?.current_status || body?.shipment_status || body?.status || null; const orderNumber = cleanOrderNumber( rawOrderNumber ); const awb = cleanAwb( rawAwb ); console.log( ">>> [SHIPROCKET] Parsed webhook:", { orderNumber: orderNumber || null, shiprocketOrderId, awb: awb || null, courier, status } ); // ==================================================== // 8. TEST WEBHOOK // ==================================================== const isTestWebhook = String( shiprocketOrderId || "" ) .toLowerCase() .includes("dummy") || String( courier || "" ) .toLowerCase() .includes("dummy"); if (isTestWebhook) { console.log( ">>> [SHIPROCKET] Test webhook detected" ); return jsonResponse({ success: true, action: "TEST_WEBHOOK_RECEIVED", message: "Shiprocket test webhook received." }); } // ==================================================== // 9. NO AWB // // Wix should not be fulfilled yet. // ==================================================== if (!awb) { console.log( ">>> [SHIPROCKET] No AWB available yet" ); return jsonResponse({ success: true, action: "IGNORED_NO_AWB", orderNumber: orderNumber || null, status: status || null }); } // ==================================================== // 10. DIRECT ORDER SYNC // // Shiprocket supplied: // // channel_order_id // + // AWB // ==================================================== if ( orderNumber && /^\d+$/.test(orderNumber) ) { console.log( ">>> [SHIPROCKET] Triggering Wix sync for order:", orderNumber ); const result = await syncSingleShiprocketOrder( orderNumber ); console.log( ">>> [SHIPROCKET] Wix sync result:" ); console.log( JSON.stringify( result, null, 2 ) ); return jsonResponse({ success: true, trigger: "SHIPROCKET_WEBHOOK", action: "SHIPROCKET_TO_WIX_SYNC", orderNumber, awb, courier, status, sync: result }); } // ==================================================== // 11. AWB FALLBACK // // Webhook has AWB but no usable channel_order_id. // // AWB // ↓ // authenticated Shiprocket API lookup // ↓ // recover channel_order_id // ↓ // Wix fulfillment // ==================================================== console.log( ">>> [SHIPROCKET] No usable channel order ID." ); console.log( ">>> [SHIPROCKET] Resolving using AWB:", awb ); const result = await syncShiprocketByAwb( awb ); console.log( ">>> [SHIPROCKET] AWB sync result:" ); console.log( JSON.stringify( result, null, 2 ) ); return jsonResponse({ success: true, trigger: "SHIPROCKET_WEBHOOK", action: "SHIPROCKET_TO_WIX_SYNC_BY_AWB", awb, courier, status, sync: result }); } catch (error) { console.error( "==================================================" ); console.error( ">>> [SHIPROCKET] WEBHOOK ERROR" ); console.error( error ); console.error( "==================================================" ); return jsonResponse({ success: false, action: "WEBHOOK_PROCESSING_ERROR", message: error?.message || String(error) }); } }

Original Premium Blueo Quality Tempered Glass and Cases available Online in India 

BLUEO HOT AND NEW PRODUCTS

Note-Some Products Images are for illusration Purpose Only.Actual Product is as Per Title of Product.

Blueo Premium Sapphire Tempered Glass
bottom of page