/** * Payment API * * 套餐目录、订单创建与订单状态接口。 */ import { CreatePaymentOrderRequest, CreatePaymentOrderResponse, CreatePaymentOrderResponseSchema, CommercialOfferResponse, CommercialOfferResponseSchema, GiftProductsResponse, GiftProductsResponseSchema, PaymentOrderStatusResponse, PaymentOrderStatusResponseSchema, PaymentPlansResponse, PaymentPlansResponseSchema, TipMessageRequest, TipMessageResponse, TipMessageResponseSchema, } from "@/data/schemas/payment"; import { ApiPath } from "./api_path"; import { httpClient } from "./http_client"; import { ApiEnvelope, unwrap } from "./response_helper"; export class PaymentApi { /** 获取 VIP 与 Top-up 套餐列表。 */ async getPlans( commercialOfferId?: string, supportCharacterId?: string, ): Promise { const env = await httpClient>(ApiPath.paymentPlans, { ...(commercialOfferId || supportCharacterId ? { query: { ...(commercialOfferId ? { commercialOfferId } : {}), ...(supportCharacterId ? { supportCharacterId } : {}), }, } : {}), }); return PaymentPlansResponseSchema.parse( unwrap(env) as Record, ); } /** 用户确认后激活一份后端签发的专属优惠。 */ async acceptCommercialOffer(offerId: string): Promise { const env = await httpClient>( ApiPath.paymentCommercialOfferAccept(offerId), { method: "POST" }, ); return CommercialOfferResponseSchema.parse( unwrap(env) as Record, ); } /** 一次获取当前角色的完整礼物目录。 */ async getGiftProducts(characterId: string): Promise { const env = await httpClient>( ApiPath.paymentGiftProducts, { query: { characterId } }, ); return GiftProductsResponseSchema.parse( unwrap(env) as Record, ); } /** 创建 VIP、Top-up 或 Tip 订单。 */ 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, ); } /** 获取已支付礼物订单的稳定感谢文案。 */ async getTipMessage(body: TipMessageRequest): Promise { const env = await httpClient>( ApiPath.paymentTipMessage, { method: "POST", body, }, ); return TipMessageResponseSchema.parse( unwrap(env) as Record, ); } } /** * 全局单例 */ export const paymentApi = new PaymentApi();