From 663d6be506a7fdc65cabaef340068cc5cae1ca9e Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Fri, 13 Mar 2026 12:20:01 +0800 Subject: [PATCH] feat: Add API routes for creating, confirming, and submitting payment intents, and verifying wallets. --- .../intents/[intentId]/confirm/route.ts | 7 +++---- .../intents/[intentId]/submit/route.ts | 7 +++---- frontend/app/api/payments/intents/route.ts | 7 +++---- .../app/api/payments/wallets/verify/route.ts | 20 ++++++++++++++----- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/frontend/app/api/payments/intents/[intentId]/confirm/route.ts b/frontend/app/api/payments/intents/[intentId]/confirm/route.ts index 0c971561..6da70365 100644 --- a/frontend/app/api/payments/intents/[intentId]/confirm/route.ts +++ b/frontend/app/api/payments/intents/[intentId]/confirm/route.ts @@ -20,14 +20,13 @@ export async function POST( try { const body = await req.json(); const auth = await buildBackendRequestHeaders(req); + const proxiedHeaders = new Headers(auth.headers); + proxiedHeaders.set("Content-Type", "application/json"); const res = await fetch( `${API_BASE}/api/payments/intents/${encodeURIComponent(intentId)}/confirm`, { method: "POST", - headers: { - ...auth.headers, - "Content-Type": "application/json", - }, + headers: proxiedHeaders, body: JSON.stringify(body ?? {}), cache: "no-store", }, diff --git a/frontend/app/api/payments/intents/[intentId]/submit/route.ts b/frontend/app/api/payments/intents/[intentId]/submit/route.ts index 58e10b09..e6679d5f 100644 --- a/frontend/app/api/payments/intents/[intentId]/submit/route.ts +++ b/frontend/app/api/payments/intents/[intentId]/submit/route.ts @@ -20,14 +20,13 @@ export async function POST( try { const body = await req.json(); const auth = await buildBackendRequestHeaders(req); + const proxiedHeaders = new Headers(auth.headers); + proxiedHeaders.set("Content-Type", "application/json"); const res = await fetch( `${API_BASE}/api/payments/intents/${encodeURIComponent(intentId)}/submit`, { method: "POST", - headers: { - ...auth.headers, - "Content-Type": "application/json", - }, + headers: proxiedHeaders, body: JSON.stringify(body ?? {}), cache: "no-store", }, diff --git a/frontend/app/api/payments/intents/route.ts b/frontend/app/api/payments/intents/route.ts index 812b646d..0178c142 100644 --- a/frontend/app/api/payments/intents/route.ts +++ b/frontend/app/api/payments/intents/route.ts @@ -16,12 +16,11 @@ export async function POST(req: NextRequest) { try { const body = await req.json(); const auth = await buildBackendRequestHeaders(req); + const proxiedHeaders = new Headers(auth.headers); + proxiedHeaders.set("Content-Type", "application/json"); const res = await fetch(`${API_BASE}/api/payments/intents`, { method: "POST", - headers: { - ...auth.headers, - "Content-Type": "application/json", - }, + headers: proxiedHeaders, body: JSON.stringify(body ?? {}), cache: "no-store", }); diff --git a/frontend/app/api/payments/wallets/verify/route.ts b/frontend/app/api/payments/wallets/verify/route.ts index d7e7e6cd..55100957 100644 --- a/frontend/app/api/payments/wallets/verify/route.ts +++ b/frontend/app/api/payments/wallets/verify/route.ts @@ -16,19 +16,29 @@ export async function POST(req: NextRequest) { try { const body = await req.json(); const auth = await buildBackendRequestHeaders(req); + const proxiedHeaders = new Headers(auth.headers); + proxiedHeaders.set("Content-Type", "application/json"); const res = await fetch(`${API_BASE}/api/payments/wallets/verify`, { method: "POST", - headers: { - ...auth.headers, - "Content-Type": "application/json", - }, + headers: proxiedHeaders, body: JSON.stringify(body ?? {}), cache: "no-store", }); if (!res.ok) { const raw = await res.text(); const response = NextResponse.json( - { error: `Backend returned ${res.status}`, detail: raw.slice(0, 350) }, + { + error: `Backend returned ${res.status}`, + detail: raw.slice(0, 350), + proxy_debug: { + has_authorization: proxiedHeaders.has("authorization"), + has_entitlement: proxiedHeaders.has("x-polyweather-entitlement"), + has_forwarded_user_id: proxiedHeaders.has( + "x-polyweather-auth-user-id", + ), + has_forwarded_email: proxiedHeaders.has("x-polyweather-auth-email"), + }, + }, { status: res.status }, ); return applyAuthResponseCookies(response, auth.response);