Handle malformed affiliate payout JSON#170
Conversation
Greptile SummaryThis PR fixes a crash when the
Confidence Score: 4/5Safe to merge for the malformed-JSON fix itself; the trim mismatch between the SELECT and UPDATE on conversion_id (flagged in a prior review) is still unresolved and could leave a conversion charged but never marked paid. The SELECT now uses conversion_id.trim() but the UPDATE at line 105 still uses the raw conversion_id. If a caller sends a conversion ID with leading/trailing whitespace the select finds the row, internalTransfer fires, but the update matches zero rows — the affiliate gets paid and the conversion record stays in an unpaid state. src/app/api/affiliates/offers/[id]/conversions/pay/route.ts — the UPDATE query on line 105 needs the same .trim() applied to the SELECT on line 50. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Route as POST /conversions/pay
participant DB as Supabase
participant SafeParse as safeParseBody
participant LN as Lightning
Client->>Route: POST with body
Route->>DB: Check affiliate_offers ownership
DB-->>Route: offer or null
alt not owner
Route-->>Client: 403
end
Route->>SafeParse: parse request body
SafeParse-->>Route: typed object or null
alt malformed JSON or non-string conversion_id
Route-->>Client: 400 conversion_id is required
end
Route->>DB: SELECT affiliate_conversions .eq(id.trim())
DB-->>Route: conversion record
alt not found or invalid status
Route-->>Client: 404 or 400
end
Route->>DB: getUserLnWallet (seller and affiliate)
Route->>LN: internalTransfer sats
Route->>DB: UPDATE affiliate_conversions .eq(id)
Route->>DB: INSERT wallet_transactions
Route-->>Client: 200 ok
Reviews (4): Last reviewed commit: "Validate conversion payout id type" | Re-trigger Greptile |
Fixes #169.
Summary
Validation