feat: accept domestic payment selection in checkout
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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<typeof ConfirmCheckoutParamsSchema>;
|
||||
|
||||
Reference in New Issue
Block a user