mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-30 02:23:47 +00:00
feat: add gift subscription API client and feature flag
This commit is contained in:
87
src/api/gift.ts
Normal file
87
src/api/gift.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import apiClient from './client';
|
||||
|
||||
// Types
|
||||
|
||||
export interface GiftTariffPeriod {
|
||||
days: number;
|
||||
price_kopeks: number;
|
||||
price_label: string;
|
||||
original_price_kopeks: number | null;
|
||||
discount_percent: number | null;
|
||||
}
|
||||
|
||||
export interface GiftTariff {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string | null;
|
||||
traffic_limit_gb: number;
|
||||
device_limit: number;
|
||||
periods: GiftTariffPeriod[];
|
||||
}
|
||||
|
||||
export interface GiftPaymentMethodSubOption {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface GiftPaymentMethod {
|
||||
method_id: string;
|
||||
display_name: string;
|
||||
description: string | null;
|
||||
icon_url: string | null;
|
||||
min_amount_kopeks: number | null;
|
||||
max_amount_kopeks: number | null;
|
||||
sub_options: GiftPaymentMethodSubOption[] | null;
|
||||
}
|
||||
|
||||
export interface GiftConfig {
|
||||
is_enabled: boolean;
|
||||
tariffs: GiftTariff[];
|
||||
payment_methods: GiftPaymentMethod[];
|
||||
balance_kopeks: number;
|
||||
currency_symbol: string;
|
||||
}
|
||||
|
||||
export interface GiftPurchaseRequest {
|
||||
tariff_id: number;
|
||||
period_days: number;
|
||||
recipient_type: 'email' | 'telegram';
|
||||
recipient_value: string;
|
||||
gift_message?: string;
|
||||
payment_mode: 'balance' | 'gateway';
|
||||
payment_method?: string;
|
||||
}
|
||||
|
||||
export interface GiftPurchaseResponse {
|
||||
status: string;
|
||||
purchase_token: string;
|
||||
payment_url: string | null;
|
||||
}
|
||||
|
||||
export interface GiftPurchaseStatus {
|
||||
status: string;
|
||||
is_gift: boolean;
|
||||
recipient_contact_value: string | null;
|
||||
gift_message: string | null;
|
||||
tariff_name: string | null;
|
||||
period_days: number | null;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
export const giftApi = {
|
||||
getConfig: async (): Promise<GiftConfig> => {
|
||||
const { data } = await apiClient.get<GiftConfig>('/cabinet/gift/config');
|
||||
return data;
|
||||
},
|
||||
|
||||
createPurchase: async (request: GiftPurchaseRequest): Promise<GiftPurchaseResponse> => {
|
||||
const { data } = await apiClient.post<GiftPurchaseResponse>('/cabinet/gift/purchase', request);
|
||||
return data;
|
||||
},
|
||||
|
||||
getPurchaseStatus: async (token: string): Promise<GiftPurchaseStatus> => {
|
||||
const { data } = await apiClient.get<GiftPurchaseStatus>(`/cabinet/gift/purchase/${token}`);
|
||||
return data;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user