/** * Payment API * * 付费墙 / 充值相关接口 */ import { CreatePaymentOrderRequest, CreatePaymentOrderResponse, CreatePaymentOrderResponseSchema, PaymentOrderStatusResponse, PaymentOrderStatusResponseSchema, PaymentPlansResponse, PaymentPlansResponseSchema, TipPaymentPlansResponse, TipPaymentPlansResponseSchema, } from "@/data/schemas/payment"; import { ApiPath } from "./api_path"; import { httpClient } from "./http_client"; import { ApiEnvelope, unwrap } from "./response_helper"; export class PaymentApi { /** * 获取套餐列表 */ async getPlans(): Promise { const env = await httpClient>(ApiPath.paymentPlans); return PaymentPlansResponseSchema.parse( unwrap(env) as Record, ); } /** 获取咖啡打赏套餐列表。 */ async getTipPlans(): Promise { const env = await httpClient>(ApiPath.paymentTipPlans); return TipPaymentPlansResponseSchema.parse( unwrap(env) as Record, ); } /** * 创建支付订单 */ async createOrder( body: CreatePaymentOrderRequest, ): Promise { const env = await httpClient>( ApiPath.paymentCreateOrder, { method: "POST", body, }, ); return CreatePaymentOrderResponseSchema.parse( unwrap(env) as Record, ); } /** * 查询支付订单状态 */ async getOrderStatus(orderId: string): Promise { const env = await httpClient>( ApiPath.paymentOrderStatus, { query: { order_id: orderId }, }, ); return PaymentOrderStatusResponseSchema.parse( unwrap(env) as Record, ); } } /** * 全局单例 */ export const paymentApi = new PaymentApi();