diff --git a/server/tests/unit/domestic-payments/domestic-payment-action-schema.test.ts b/server/tests/unit/domestic-payments/domestic-payment-action-schema.test.ts index 4cd2297ec..88e3713ca 100644 --- a/server/tests/unit/domestic-payments/domestic-payment-action-schema.test.ts +++ b/server/tests/unit/domestic-payments/domestic-payment-action-schema.test.ts @@ -1,6 +1,7 @@ import { describe, expect, test } from "bun:test"; import { BillingResponseSchema, + ConfirmCheckoutParamsSchema, DomesticPaymentProvider, } from "@autumn/shared"; @@ -66,4 +67,25 @@ describe("domestic payment action schema", () => { expect(result.success).toBe(false); }); + + test("accepts WeChat Native payment selection in checkout confirm params", () => { + const parsed = ConfirmCheckoutParamsSchema.parse({ + payment_provider: "wechatpay", + payment_method_type: "wechatpay_native", + }); + + expect(parsed).toEqual({ + payment_provider: DomesticPaymentProvider.WeChatPay, + payment_method_type: "wechatpay_native", + }); + }); + + test("rejects Alipay provider with WeChat Native method", () => { + expect(() => + ConfirmCheckoutParamsSchema.parse({ + payment_provider: "alipay", + payment_method_type: "wechatpay_native", + }), + ).toThrow(); + }); }); diff --git a/shared/internal/checkout/confirmCheckoutParams.ts b/shared/internal/checkout/confirmCheckoutParams.ts index 7904c4835..a01d993ff 100644 --- a/shared/internal/checkout/confirmCheckoutParams.ts +++ b/shared/internal/checkout/confirmCheckoutParams.ts @@ -1,17 +1,36 @@ import { FeatureOptionsSchema } from "@models/cusProductModels/cusProductModels"; +import { DomesticPaymentProvider } from "@models/domesticPaymentModels/domesticPaymentModels"; import { z } from "zod/v4"; import { AttachDiscountSchema } from "../../api/billing/attachV2/attachDiscount"; -export const ConfirmCheckoutParamsSchema = z.object({ - feature_quantities: z - .array( - FeatureOptionsSchema.pick({ - feature_id: true, - quantity: true, - }), - ) - .optional(), - discounts: z.array(AttachDiscountSchema).optional(), -}); +export const ConfirmCheckoutParamsSchema = z + .object({ + feature_quantities: z + .array( + FeatureOptionsSchema.pick({ + feature_id: true, + quantity: true, + }), + ) + .optional(), + discounts: z.array(AttachDiscountSchema).optional(), + payment_provider: z + .enum([DomesticPaymentProvider.WeChatPay, DomesticPaymentProvider.Alipay]) + .optional(), + payment_method_type: z.enum(["wechatpay_native"]).optional(), + }) + .refine( + (value) => { + if (!value.payment_provider && !value.payment_method_type) return true; + return ( + value.payment_provider === DomesticPaymentProvider.WeChatPay && + value.payment_method_type === "wechatpay_native" + ); + }, + { + message: + "payment_provider and payment_method_type must be a supported domestic payment pair", + }, + ); export type ConfirmCheckoutParams = z.infer;