feat(rust-core): buyer confirm-receipt and dispute endpoints - #43
Merged
Merged
Conversation
Add authenticated POST /escrow/confirm-receipt and /escrow/dispute so the app can stop using the process-escrow edge function for these actions. - Verify the caller's Supabase access token via GET /auth/v1/user - Only the buyer of a held transaction can act; others get 404 - Confirm-receipt reuses release_escrow (held checks, payout dedup) - Dispute takes the same in-process lock as release and updates escrow and transaction atomically with status guards - New required env vars: SUPABASE_URL, SUPABASE_ANON_KEY Co-authored-by: Copilot App <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
4 tasks
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Right now confirm-receipt and dispute go through the
process-escrowedge function, which caused tonight's incident (GHSA-xq84-qm9j-hf6p). This PR is step 1 of moving them to Rust before any real money moves. Rust already has the safe payout path (release_escrow), which checks that both rows areheldand asks Fapshi whether a payout already exists, failing closed if it can't tell.What
POST /escrow/confirm-receipt{transaction_id}POST /escrow/dispute{transaction_id, dispute_reason}Authorization: Bearer <Supabase access token>. The token is checked withGET {SUPABASE_URL}/auth/v1/user. An invalid token gets 401; if Supabase Auth itself fails, the endpoint returns 502 with a generic message.heldtransaction can act. Someone else's transaction gets 404, same as one that doesn't exist, so ids can't be probed. A transaction that isn'theldgets 409.InProgressGuard, pulled out ofrelease_escrow). It then updates the escrow and the transaction in one DB transaction, and both updates only apply if the row is stillheld.Deploy notes
SUPABASE_URLandSUPABASE_ANON_KEY. The service won't start without them.release_escrowtoday.Not in this PR (next steps)
confirmReceipt/disputeTransactionat these endpoints.auto-release-escrows-jobcron at/internal/escrow/process-releases, or unschedule it.supabase/functions/process-escrowand remove it from Supabase.Test plan
cargo test: newtests/buyer_tests.rs(13 tests) runs against a mock Supabase Auth server. It covers missing, malformed and invalid tokens, auth running before the body is read, auth outages, a valid token reaching the DB, malformed bodies, reason validation, a dispute during an in-progress payout (409, lock kept), and the lock being released afterwards.cargo clippy --all-targets -- -D warningsis clean.