refactor: delete superseded checkout routes and dedupe cart checkout #17

Merged
bermudalamb merged 2 commits from refactor/remove-dead-checkout-routes into main 2026-08-14 17:59:47 -05:00
Owner

Net -173 lines. No behaviour change to any reachable endpoint.

Dead code removed

routes/paypal.ts (156 lines) and routes/demo.ts (39) are the pre-cart single-item checkout flow. Nothing has imported them since the cart flow landed in 9ab689e:

  • app.ts mounts only cartCheckoutRouter and cartCheckoutWebhookRouter
  • the frontend calls only /api/checkout/cart/* (frontend/src/cart/cartApi.ts:76-92)
  • no test references either file

Between them and the live cartCheckout.ts they duplicated PAYPAL_BASE, getAccessToken(), and a second /webhooks/paypal handler — one that treats custom_id as an item ID while the live one treats it as a checkout ID. Only one was ever mounted.

Live duplication extracted

/paypal/create and /demo/purchase each repeated the same shipping-address ownership check, cart lock + empty guard, and checkouts / checkout_items inserts. Now one openCheckout() returning a discriminated union, so callers keep control of the transaction and the response:

const opened = await openCheckout(client, req.customerId as number, shippingAddressId, 'paypal', null);
if (!opened.ok) { await client.query('ROLLBACK'); return res.status(400).json({ error: opened.error }); }
const { checkoutId, cart } = opened;

The call sites now differ only where they genuinely differ: processor name, and whether processor_order_id is known upfront (null for PayPal, set after order creation; demo-${Date.now()} for demo). Added CartItem / LockedCart interfaces to type loadLockedCart, which removed the (it: any) casts. Left client: any alone — typing it as PoolClient would touch completeCheckout too and belongs in its own pass.

Follow-up, not done here

paypal.ts was the only writer of items.reserved_until and items.paypal_order_id. Those columns are now write-dead — admin.ts:155 only nulls them, and the cart flow tracks expiry on cart_items.expires_at. Dropping them wants its own migration.

Verification

  • npx tsc --noEmit — clean
  • Unit tests — 16/16
  • Integration tests — 14/14, including completes a multi-item cart purchase and marks all items sold, which covers the refactored demo path end to end

🤖 Generated with Claude Code

Net **-173 lines**. No behaviour change to any reachable endpoint. ## Dead code removed `routes/paypal.ts` (156 lines) and `routes/demo.ts` (39) are the pre-cart single-item checkout flow. Nothing has imported them since the cart flow landed in 9ab689e: - `app.ts` mounts only `cartCheckoutRouter` and `cartCheckoutWebhookRouter` - the frontend calls only `/api/checkout/cart/*` (`frontend/src/cart/cartApi.ts:76-92`) - no test references either file Between them and the live `cartCheckout.ts` they duplicated `PAYPAL_BASE`, `getAccessToken()`, and a second `/webhooks/paypal` handler — one that treats `custom_id` as an item ID while the live one treats it as a checkout ID. Only one was ever mounted. ## Live duplication extracted `/paypal/create` and `/demo/purchase` each repeated the same shipping-address ownership check, cart lock + empty guard, and `checkouts` / `checkout_items` inserts. Now one `openCheckout()` returning a discriminated union, so callers keep control of the transaction and the response: ```ts const opened = await openCheckout(client, req.customerId as number, shippingAddressId, 'paypal', null); if (!opened.ok) { await client.query('ROLLBACK'); return res.status(400).json({ error: opened.error }); } const { checkoutId, cart } = opened; ``` The call sites now differ only where they genuinely differ: processor name, and whether `processor_order_id` is known upfront (`null` for PayPal, set after order creation; `demo-${Date.now()}` for demo). Added `CartItem` / `LockedCart` interfaces to type `loadLockedCart`, which removed the `(it: any)` casts. Left `client: any` alone — typing it as `PoolClient` would touch `completeCheckout` too and belongs in its own pass. ## Follow-up, not done here `paypal.ts` was the only writer of `items.reserved_until` and `items.paypal_order_id`. Those columns are now write-dead — `admin.ts:155` only nulls them, and the cart flow tracks expiry on `cart_items.expires_at`. Dropping them wants its own migration. ## Verification - `npx tsc --noEmit` — clean - Unit tests — 16/16 - Integration tests — 14/14, including `completes a multi-item cart purchase and marks all items sold`, which covers the refactored demo path end to end 🤖 Generated with [Claude Code](https://claude.com/claude-code)
bermudalamb added 1 commit 2026-08-14 17:21:37 -05:00
refactor: delete superseded checkout routes and dedupe cart checkout
SonarQube Analysis / sonarqube (pull_request) Successful in 8m12s
Tests / backend-unit (pull_request) Successful in 1m1s
Tests / backend-integration (pull_request) Successful in 2m0s
Tests / frontend-e2e (pull_request) Failing after 50s
135cd2364d
routes/paypal.ts and routes/demo.ts were the pre-cart single-item
checkout flow. Nothing has imported them since the cart flow landed:
app.ts mounts only cartCheckout, the frontend calls /api/checkout/cart/*,
and no test touches them. They duplicated PAYPAL_BASE, getAccessToken,
and a second handler for the /webhooks/paypal mount.

Also extract openCheckout() from /paypal/create and /demo/purchase in
cartCheckout.ts, which repeated the same address-ownership check, cart
lock, and checkouts/checkout_items inserts. It returns a discriminated
union so callers keep control of the transaction and the response. Add
CartItem/LockedCart interfaces, dropping the (it: any) casts.

Note: paypal.ts was the only writer of items.reserved_until and
items.paypal_order_id. Those columns are now write-dead; the schema is
left alone for a separate migration.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
bermudalamb added 1 commit 2026-08-14 17:58:58 -05:00
Merge branch 'main' into refactor/remove-dead-checkout-routes
SonarQube Analysis / sonarqube (pull_request) Successful in 6m0s
Tests / backend-unit (pull_request) Successful in 1m2s
Tests / backend-integration (pull_request) Successful in 3m0s
Tests / frontend-e2e (pull_request) Failing after 47s
1848adb7ce
bermudalamb merged commit 96edce5159 into main 2026-08-14 17:59:47 -05:00
bermudalamb deleted branch refactor/remove-dead-checkout-routes 2026-08-14 17:59:49 -05:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: bermudalamb/redefined-designs#17