Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ describe("POST /api/bounties/[id]/submissions/[sid]/pay", () => {
payout_status: "unpaid",
pay_url: null,
coinpay_invoice_id: null,
metadata: {},
metadata: {
expired_coinpay_invoice_id: "cp-pay-expired-1",
expired_at: "2026-05-22T12:00:00Z",
reviewer_note_id: "review-note-1",
},
Comment on lines +59 to +63
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The regression fixture only contains non-conflicting metadata keys (expired_coinpay_invoice_id, expired_at, reviewer_note_id). The PR description states "new payment details take precedence," but no assertion verifies that a stale payment_address or expires_at carried in existingMetadata is actually overridden by the new payment values. Adding one conflicting key (e.g., an old payment_address) would make this guarantee explicit and guard against future refactors that accidentally flip the spread order.

Suggested change
metadata: {
expired_coinpay_invoice_id: "cp-pay-expired-1",
expired_at: "2026-05-22T12:00:00Z",
reviewer_note_id: "review-note-1",
},
metadata: {
expired_coinpay_invoice_id: "cp-pay-expired-1",
expired_at: "2026-05-22T12:00:00Z",
reviewer_note_id: "review-note-1",
// Stale payment field from the previous invoice — should be overridden
payment_address: "stale-address-should-be-overridden",
},

},
});

Expand Down Expand Up @@ -99,6 +103,9 @@ describe("POST /api/bounties/[id]/submissions/[sid]/pay", () => {
coinpay_invoice_id: "cp-pay-bounty-1",
pay_url: "https://coinpayportal.com/pay/cp-pay-bounty-1",
metadata: expect.objectContaining({
expired_coinpay_invoice_id: "cp-pay-expired-1",
expired_at: "2026-05-22T12:00:00Z",
reviewer_note_id: "review-note-1",
payment_address: "So11111111111111111111111111111111111111112",
amount_crypto: 0.5,
payment_currency: "sol",
Expand Down
5 changes: 5 additions & 0 deletions src/app/api/bounties/[id]/submissions/[sid]/pay/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ export async function POST(
paymentResult.expires_at || (cpPayment.expires_at as string | undefined) || null;
const responseCurrency =
paymentResult.currency || (cpPayment.currency as string | undefined) || paymentCurrency;
const existingMetadata =
submission.metadata && typeof submission.metadata === "object" && !Array.isArray(submission.metadata)
? (submission.metadata as Record<string, unknown>)
: {};

if (!paymentId || !paymentAddress) {
return NextResponse.json(
Expand All @@ -119,6 +123,7 @@ export async function POST(
coinpay_invoice_id: paymentId,
pay_url: checkoutUrl,
metadata: {
...existingMetadata,
payment_address: paymentAddress,
amount_crypto: amountCrypto,
payment_currency: responseCurrency,
Expand Down