feat: Add API routes for creating, confirming, and submitting payment intents, and verifying wallets.

This commit is contained in:
2569718930@qq.com
2026-03-13 12:20:01 +08:00
parent 2de083d53a
commit 663d6be506
4 changed files with 24 additions and 17 deletions
@@ -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",
},
@@ -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",
},
+3 -4
View File
@@ -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",
});
@@ -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);