payment.schema.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { z } from 'zod';
  2. // 支付创建请求Schema
  3. export const PaymentCreateRequestSchema = z.object({
  4. orderId: z.number().int().positive(),
  5. totalAmount: z.number().int().positive(),
  6. description: z.string().min(1).max(128)
  7. });
  8. export type PaymentCreateRequest = z.infer<typeof PaymentCreateRequestSchema>;
  9. // 支付创建响应Schema
  10. export const PaymentCreateResponseSchema = z.object({
  11. paymentId: z.string(),
  12. timeStamp: z.string(),
  13. nonceStr: z.string(),
  14. package: z.string(),
  15. signType: z.string(),
  16. paySign: z.string(),
  17. totalAmount: z.number()
  18. });
  19. export type PaymentCreateResponse = z.infer<typeof PaymentCreateResponseSchema>;
  20. // 支付状态查询响应Schema
  21. export const PaymentStatusResponseSchema = z.object({
  22. paymentStatus: z.enum(['待支付', '支付中', '已支付', '支付失败', '已退款', '已关闭'])
  23. });
  24. export type PaymentStatusResponse = z.infer<typeof PaymentStatusResponseSchema>;
  25. // 支付回调请求Schema
  26. export const PaymentCallbackRequestSchema = z.object({
  27. id: z.string(),
  28. create_time: z.string(),
  29. event_type: z.string(),
  30. resource_type: z.string(),
  31. resource: z.object({
  32. algorithm: z.string(),
  33. ciphertext: z.string(),
  34. associated_data: z.string().optional(),
  35. nonce: z.string()
  36. }),
  37. summary: z.string()
  38. });
  39. export type PaymentCallbackRequest = z.infer<typeof PaymentCallbackRequestSchema>;