Skip to content

feat: Add pending status for Amazon orders awaiting shipment#8

Closed
eshaffer321 wants to merge 10 commits intomainfrom
feat/pending-order-status
Closed

feat: Add pending status for Amazon orders awaiting shipment#8
eshaffer321 wants to merge 10 commits intomainfrom
feat/pending-order-status

Conversation

@eshaffer321
Copy link
Owner

Summary

Orders that haven't shipped yet (no bank charges) are now tracked as "pending" instead of "failed". This provides clearer status reporting and ensures these orders are retried on subsequent syncs.

Problem: When an Amazon order is placed but hasn't shipped yet, there are no bank transactions to match. Previously this was logged as an ERROR and recorded as "failed", which was misleading since the order isn't actually broken - it's just not ready yet.

Solution:

  • Added ErrPaymentPending sentinel error for orders awaiting shipment
  • Amazon handler detects this and returns a skip with reason "payment pending"
  • Orchestrator records as status="pending" (not "failed") and logs at INFO level
  • Orders with pending status will be retried on subsequent syncs

Changes

  • internal/adapters/providers/amazon/order.go - Add ErrPaymentPending error and improved GetFinalCharges() logic
  • internal/adapters/providers/amazon/order_test.go - Add tests for pending scenarios
  • internal/adapters/providers/amazon/provider_test.go - Update existing tests
  • internal/application/sync/handlers/amazon.go - Detect pending and return skip
  • internal/application/sync/orchestrator.go - Handle pending in handleResult()
  • internal/application/sync/recording.go - Add recordPending() function
  • web/src/app/(app)/orders/page.tsx - Add "Pending" to status filter dropdown

Test plan

  • All Go tests pass (go test ./...)
  • UI already supports pending status with amber badge
  • Manual test: Run sync with an unshipped Amazon order - should show INFO log and pending status

- Add /sync page with form to configure and start sync jobs
- Support provider selection (Walmart, Costco, Amazon)
- Add lookback days, max orders, and order ID configuration
- Include dry run, force, and verbose options
- Display real-time job progress with polling
- Add job cancellation support
- Fix SyncJob type to match API response (dry_run at top level)
- Add Playwright e2e tests for sync page (9 tests)
- Add sync API client functions (startSync, getSyncJobs, etc.)
- Update navigation to include Sync link
- Fix memory leak by wrapping loadActiveJobs in useCallback
- Add confirmation dialog before canceling sync jobs
- Improve API error handling to parse server error messages
Brand Designer Fixes:
- Use cyan for progress bar and running status (brand color)
- Change Amazon badge to orange (official brand color)
- Add shadow/depth to progress bar
- Tighter table gutters

Product Designer Fixes:
- Prominent Dry Run toggle with warning styling when disabled
- Help text on all form fields
- Collapsible Advanced Options section (Force, Verbose)
- Auto-dismiss success/error messages after 5 seconds
- Save provider preference to localStorage
- Mobile card view for job table (responsive)
- 4-column form layout on large screens
- Last updated timestamp on job list
- Improved empty state with icon
- Full-width button on mobile
- ARIA labels on status badges
- Fix Button component type error by using inline red text styling
  instead of color prop with plain prop (not allowed by component types)
- Add eslint-disable comment for intentional missing dependency in
  useEffect (loadActiveJobs only needed on mount, not as dependency)
Create brand-aligned SVG icons with sync arrows and receipt/transaction
symbolism to represent retail order synchronization:

- Add monarch-sync.svg sidebar icon with outer ring, sync arrows, and receipt
- Add favicon.svg with simplified design for browser tabs
- Update layout to reference new favicon
- Update sidebar to use custom brand icon
- Include accessibility tags (title, desc) for screen readers

Design validated by Brand Designer: A grade (96/100)
Rename from 'Monarch Sync' to 'Retail Sync' to avoid trademark issues with
the third-party Monarch Money service. This commit also addresses feedback
from expert reviews:

- Add desc tag to favicon for WCAG accessibility compliance
- Standardize SVG stroke widths to 1.5px for visual consistency
- Add immutable cache headers (1 year) for static SVG assets
- Update all UI references to new brand name
Fixes branding inconsistency where Quick Start page still referenced
'Monarch Sync' while the rest of the UI uses 'Retail Sync'.
…tracking

Tracks payment method charges, refunds, and gift cards for Walmart orders.
Provides API endpoints to view ledger history by order ID with filtering
by provider, state (pending/charged/partial_refund), and pagination.
Enables starting, cancelling, and monitoring sync jobs via the REST API.
Includes job tracking, progress reporting, and concurrent provider handling.
Orders that haven't shipped yet (no bank charges) are now tracked as
"pending" instead of "failed". This provides clearer status reporting
and ensures these orders are retried on subsequent syncs.

Changes:
- Add ErrPaymentPending sentinel error for orders not yet charged
- Amazon handler detects pending orders and returns skip with reason
- Orchestrator records pending status (not error) and logs at INFO level
- UI already supports pending status with amber badge; added filter option

The pending status is recorded in the database but doesn't block retries
since IsProcessed() only checks for status='success'.
}

// Get total count
countQuery := fmt.Sprintf("SELECT COUNT(*) FROM order_ledgers %s", where)

Check failure

Code scanning / gosec

SQL string formatting Error

SQL string formatting
Comment on lines +970 to +978
query := fmt.Sprintf(`
SELECT id, order_id, sync_run_id, provider, fetched_at, ledger_state,
ledger_version, ledger_json, total_charged, charge_count,
payment_method_types, has_refunds, is_valid, validation_notes
FROM order_ledgers
%s
ORDER BY fetched_at DESC
LIMIT ? OFFSET ?
`, where)

Check failure

Code scanning / gosec

SQL string formatting Error

SQL string formatting
@eshaffer321 eshaffer321 closed this Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant