feat(data): add paywall payment APIs
This commit is contained in:
@@ -71,13 +71,19 @@ export class ApiPath {
|
||||
|
||||
// ============ 支付相关 ============
|
||||
/** 创建充值订单 */
|
||||
static readonly paymentCreateOrder = `${ApiPath._payment}/order/create`;
|
||||
static readonly paymentCreateOrder = `${ApiPath._payment}/create-order`;
|
||||
|
||||
/** 查询订单状态 */
|
||||
static readonly paymentOrderStatus = `${ApiPath._payment}/order/status`;
|
||||
static readonly paymentOrderStatus = `${ApiPath._payment}/order-status`;
|
||||
|
||||
/** 获取商品套餐列表 */
|
||||
static readonly paymentProducts = `${ApiPath._payment}/products`;
|
||||
static readonly paymentPlans = `${ApiPath._payment}/plans`;
|
||||
|
||||
/** 查询当前用户 VIP 状态 */
|
||||
static readonly paymentVipStatus = `${ApiPath._payment}/vip-status`;
|
||||
|
||||
/** @deprecated PAYWALL_API 使用 paymentPlans。 */
|
||||
static readonly paymentProducts = ApiPath.paymentPlans;
|
||||
|
||||
/** 申请退款 */
|
||||
static readonly paymentRefund = `${ApiPath._payment}/refund`;
|
||||
@@ -103,6 +109,9 @@ export class ApiPath {
|
||||
/** 上传图片 */
|
||||
static readonly chatUploadImage = `${ApiPath._chat}/upload-image`;
|
||||
|
||||
/** 解锁私密消息 */
|
||||
static readonly chatUnlockPrivate = `${ApiPath._chat}/unlock-private`;
|
||||
|
||||
// ============ 数据看板相关 ============
|
||||
private static readonly _metrics = `${ApiPath._baseUrl}/metrics`;
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ import {
|
||||
SendMessageRequest,
|
||||
SttData,
|
||||
SyncMessage,
|
||||
UnlockPrivateRequest,
|
||||
UnlockPrivateResponse,
|
||||
} from "@/data/dto/chat";
|
||||
|
||||
export class ChatApi {
|
||||
@@ -81,6 +83,24 @@ export class ChatApi {
|
||||
unwrap(env) as Record<string, unknown>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解锁私密消息
|
||||
*/
|
||||
async unlockPrivateMessage(
|
||||
body: UnlockPrivateRequest,
|
||||
): Promise<UnlockPrivateResponse> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(
|
||||
ApiPath.chatUnlockPrivate,
|
||||
{
|
||||
method: "POST",
|
||||
body: body.toJson(),
|
||||
},
|
||||
);
|
||||
return UnlockPrivateResponse.fromJson(
|
||||
unwrap(env) as Record<string, unknown>,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,5 +8,6 @@ export * from "./auth_api";
|
||||
export * from "./chat_api";
|
||||
export * from "./http_client";
|
||||
export * from "./metrics_api";
|
||||
export * from "./payment_api";
|
||||
export * from "./response_helper";
|
||||
export * from "./user_api";
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Payment API
|
||||
*
|
||||
* 付费墙 / 充值相关接口
|
||||
*/
|
||||
import {
|
||||
CreatePaymentOrderRequest,
|
||||
CreatePaymentOrderResponse,
|
||||
PaymentOrderStatusResponse,
|
||||
PaymentPlansResponse,
|
||||
PaymentVipStatusResponse,
|
||||
} from "@/data/dto/payment";
|
||||
|
||||
import { ApiPath } from "./api_path";
|
||||
import { httpClient } from "./http_client";
|
||||
import { ApiEnvelope, unwrap } from "./response_helper";
|
||||
|
||||
export class PaymentApi {
|
||||
/**
|
||||
* 获取套餐列表
|
||||
*/
|
||||
async getPlans(): Promise<PaymentPlansResponse> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.paymentPlans);
|
||||
return PaymentPlansResponse.fromJson(
|
||||
unwrap(env) as Record<string, unknown>,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建支付订单
|
||||
*/
|
||||
async createOrder(
|
||||
body: CreatePaymentOrderRequest,
|
||||
): Promise<CreatePaymentOrderResponse> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(
|
||||
ApiPath.paymentCreateOrder,
|
||||
{
|
||||
method: "POST",
|
||||
body: body.toJson(),
|
||||
},
|
||||
);
|
||||
return CreatePaymentOrderResponse.fromJson(
|
||||
unwrap(env) as Record<string, unknown>,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询支付订单状态
|
||||
*/
|
||||
async getOrderStatus(
|
||||
orderId: string,
|
||||
): Promise<PaymentOrderStatusResponse> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(
|
||||
ApiPath.paymentOrderStatus,
|
||||
{
|
||||
query: { order_id: orderId },
|
||||
},
|
||||
);
|
||||
return PaymentOrderStatusResponse.fromJson(
|
||||
unwrap(env) as Record<string, unknown>,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前用户 VIP 状态
|
||||
*/
|
||||
async getVipStatus(): Promise<PaymentVipStatusResponse> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(
|
||||
ApiPath.paymentVipStatus,
|
||||
);
|
||||
return PaymentVipStatusResponse.fromJson(
|
||||
unwrap(env) as Record<string, unknown>,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局单例
|
||||
*/
|
||||
export const paymentApi = new PaymentApi();
|
||||
Reference in New Issue
Block a user