Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions packages/server/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,18 @@ export function createHandler(
? await findExistingSettlement(body.paymentPayload, body.paymentRequirements, settlementStore)
: null;

if (existing && existing.status === "confirmed") {
// Only reuse a cached settlement when it was actually confirmed for
// THIS SAME payee/token/amount. The nonce+chain lookup alone isn't
// enough: without this check, any already-confirmed nonce could be
// replayed against different payment requirements and still come
// back as success.
if (
existing &&
existing.status === "confirmed" &&
existing.payee.toLowerCase() === body.paymentRequirements.payTo.toLowerCase() &&
existing.token.toLowerCase() === body.paymentRequirements.asset.toLowerCase() &&
existing.amount === body.paymentRequirements.amount
) {
return Response.json(
{
success: true,
Expand Down Expand Up @@ -168,7 +179,7 @@ async function findExistingSettlement(
payload: PaymentPayload,
requirements: PaymentRequirements,
store: SettlementStore,
): Promise<{ txHash: string; status: string; payer: string } | null> {
): Promise<{ txHash: string; status: string; payer: string; payee: string; token: string; amount: string } | null> {
try {
const p = payload as Record<string, unknown>;
const inner = p.payload as Record<string, unknown> | undefined;
Expand All @@ -182,8 +193,15 @@ async function findExistingSettlement(
const record = await store.findByNonceAndChain(nonce, chainId);
if (!record) return null;

return { txHash: record.txHash, status: record.status, payer: record.payer };
return {
txHash: record.txHash,
status: record.status,
payer: record.payer,
payee: record.payee,
token: record.token,
amount: record.amount,
};
} catch {
return null;
}
}
}