The order details page was showing "We could not find details for this order yet" because:
- Orders are saved to Google Sheets via Apps Script (not local JSON file)
- The order details page was trying to read from local JSON file (
data/orders.json) - On Vercel, the filesystem is read-only, so orders can't be saved locally
- Even in local development, orders aren't saved to the local file anymore (they go directly to Apps Script)
- Created API endpoint
/api/order/[orderId]that fetches order data from Google Sheets via Apps Script - Updated Apps Script
doGetfunction to acceptorderIdparameter and fetch from Google Sheets - Updated order details page to fetch from the API endpoint instead of reading from local file
- Fixed file options storage - Apps Script now properly stores file options in Google Sheets
User visits /order/[orderId]
↓
getServerSideProps fetches from /api/order/[orderId]
↓
API endpoint calls Apps Script doGet?orderId=XXX
↓
Apps Script fetches from Google Sheets
↓
Returns order data
↓
Order details page displays order
-
apps-script/Code.gs:- Updated
doGetto acceptorderIdparameter - Added
getOrderFromSheet(orderId)function to fetch order from Google Sheets - Fixed
logToSheetto properly store file options
- Updated
-
pages/api/order/[orderId].ts(NEW):- API endpoint that fetches order from Apps Script
- Calls Apps Script
doGetwithorderIdparameter - Returns order data or 404 if not found
-
pages/order/[orderId].tsx:- Updated to fetch from
/api/order/[orderId]instead of local file - Falls back to local file for local development (if available)
- Updated to fetch from
- Orders are saved to Google Sheets after files are uploaded
- There might be a slight delay between upload completion and order being available in Sheets
- If order is not found immediately, user should refresh the page after a few seconds
- Make sure
SHEET_IDis set in Apps Script - The Sheet must have the correct columns:
- Timestamp
- Order ID
- Status
- Total
- VPA
- Files Count
- File Data (JSON)
- Payment Screenshot Drive ID
- Payment Screenshot Path
- Errors
- Upload files and complete an order
- Note the order ID (format:
PX-<timestamp>-<4hex>) - Visit
/order/[orderId] - Order should be displayed (if saved to Google Sheets)
If order is not found:
- Check Apps Script logs to see if order was saved to Sheet
- Verify
SHEET_IDis set correctly in Apps Script - Check Google Sheets to see if the order row exists
- Verify the order ID format matches (should be
PX-<timestamp>-<4hex>)
If API returns 500:
- Check if
APPS_SCRIPT_WEB_APP_URLis set in Vercel - Check Apps Script logs for errors
- Verify Apps Script is deployed with "Anyone" access
If file options are missing:
- Check if file options are being passed in the upload request
- Verify Apps Script is storing options in the "File Data (JSON)" column
- Check the JSON structure in Google Sheets
- Deploy Apps Script changes - Update the Apps Script code with the new
doGetandgetOrderFromSheetfunctions - Test order retrieval - Upload a test order and verify it appears in the order details page
- Monitor Google Sheets - Check that orders are being saved correctly
- Add retry logic (optional) - Add automatic retry if order is not found immediately
After updating the Apps Script code:
- Save the changes in Apps Script editor
- Deploy as a new version (important!)
- Update the Web App deployment
- Test the order retrieval endpoint:
https://script.google.com/macros/s/YOUR_ID/exec?orderId=PX-1762595077571-60d5
Status: ✅ Fixed - Orders are now fetched from Google Sheets via Apps Script