ALIEZ il y a 1 mois
Parent
commit
b1eebac888

+ 6 - 0
.vscode/settings.json

@@ -0,0 +1,6 @@
+{
+    "i18n-ally.localesPaths": [
+        "messages",
+        "src/i18n"
+    ]
+}

+ 6 - 5
src/app/[locale]/checkout/checkout-form.tsx

@@ -126,12 +126,13 @@ export function CheckoutForm() {
   const handleSubmit = async (e: React.FormEvent) => {
     e.preventDefault();
     if (!user) return;
-    const depositAmountNum = Number(depositAmount);
     const pricedByRate = payAmountWithChannelRate(displayCoursePrice, payRateMultiplier);
-    const finalAmount =
-      Number.isFinite(depositAmountNum) && depositAmountNum > 0
-        ? depositAmountNum
-        : pricedByRate;
+    // 与「支付金额(USDT)」展示同源:始终提交标价×通道汇率后的金额,不依赖输入框字符串解析。
+    const finalAmount = pricedByRate;
+    if (!(finalAmount > 0)) {
+      setMsg("支付金额无效,请重新选择支付通道或付款方式。");
+      return;
+    }
     if (!goodsId) {
       setMsg("商品ID缺失,无法提交订单。");
       return;

+ 19 - 1
src/app/api/xfgpay/pay/[...segments]/route.ts

@@ -10,6 +10,9 @@ type PayRequestBody = {
   goodIds?: string[] | string;
   payName?: string;
   payPhone?: string;
+  amount?: number | string;
+  code?: string;
+  bankCode?: string;
 };
 
 type Params = {
@@ -32,11 +35,26 @@ export async function POST(
       ? [body.goodIds.trim()]
       : [];
 
-  const upstreamBody = {
+  const amountRaw = body.amount;
+  const amount =
+    typeof amountRaw === "number" && Number.isFinite(amountRaw)
+      ? amountRaw
+      : typeof amountRaw === "string" && amountRaw.trim()
+        ? Number(amountRaw)
+        : undefined;
+
+  const upstreamBody: Record<string, unknown> = {
     goodIds,
     payName: typeof body.payName === "string" ? body.payName : "",
     payPhone: typeof body.payPhone === "string" ? body.payPhone : "",
   };
+  if (amount !== undefined && Number.isFinite(amount)) {
+    upstreamBody.amount = amount;
+  }
+  if (typeof body.code === "string" && body.code.trim()) upstreamBody.code = body.code.trim();
+  if (typeof body.bankCode === "string" && body.bankCode.trim()) {
+    upstreamBody.bankCode = body.bankCode.trim();
+  }
 
   const accessToken = request.headers.get("access-token");
   const authorization = request.headers.get("authorization");

+ 6 - 2
src/lib/checkout-api.ts

@@ -165,11 +165,13 @@ function normalizeChannelList(raw: unknown): RemittanceChannel[] {
   return output;
 }
 
-/** 支付展示/提交金额 = 标价 × 通道 `rate`;`rate` 为 null 或非有限数时按 1。 */
+/** 支付展示/提交金额 = 标价 × 通道 `rate`;`rate` 为 null 或非有限数时按 1。金额最多保留两位小数。 */
 export function payAmountWithChannelRate(basePrice: number, rate: number | null): number {
   if (!Number.isFinite(basePrice) || basePrice < 0) return 0;
   const mult = rate != null && Number.isFinite(rate) ? rate : 1;
-  return Math.round(basePrice * mult * 1e8) / 1e8;
+  const product = basePrice * mult;
+  if (!Number.isFinite(product)) return 0;
+  return Math.round(product * 100) / 100;
 }
 
 /**
@@ -278,6 +280,8 @@ export async function submitXfgPayOrder(input: {
         goodIds: input.goodIds,
         payName: input.payName,
         payPhone: input.payPhone,
+        /** 与路径中的金额一致:标价×通道 rate 后的实付额;避免后端只读 body 时落到商品原价。 */
+        amount: input.amount,
       };
   const data = await postRemittance<unknown>(path, body);
   return { raw: data, resultUrl: pickResultUrl(data) };