424 lines
9.8 KiB
TypeScript
424 lines
9.8 KiB
TypeScript
import apiClient from './apiClient';
|
|
|
|
export interface PlatformCurrencyResponse {
|
|
status: string;
|
|
data: {
|
|
currency: string;
|
|
updated_at: string | null;
|
|
updated_by: string | null;
|
|
};
|
|
}
|
|
|
|
export interface UpdateCurrencyRequest {
|
|
currency: string;
|
|
}
|
|
|
|
export interface StripeSettingsResponse {
|
|
status: string;
|
|
data: {
|
|
stripe_secret_key: string;
|
|
stripe_publishable_key: string;
|
|
stripe_webhook_secret: string;
|
|
stripe_secret_key_masked: string;
|
|
stripe_webhook_secret_masked: string;
|
|
has_secret_key: boolean;
|
|
has_publishable_key: boolean;
|
|
has_webhook_secret: boolean;
|
|
updated_at?: string | null;
|
|
updated_by?: string | null;
|
|
};
|
|
message?: string;
|
|
}
|
|
|
|
export interface UpdateStripeSettingsRequest {
|
|
stripe_secret_key?: string;
|
|
stripe_publishable_key?: string;
|
|
stripe_webhook_secret?: string;
|
|
}
|
|
|
|
export interface PayPalSettingsResponse {
|
|
status: string;
|
|
data: {
|
|
paypal_client_id: string;
|
|
paypal_client_secret: string;
|
|
paypal_mode: string;
|
|
paypal_client_secret_masked: string;
|
|
has_client_id: boolean;
|
|
has_client_secret: boolean;
|
|
};
|
|
}
|
|
|
|
export interface UpdatePayPalSettingsRequest {
|
|
paypal_client_id?: string;
|
|
paypal_client_secret?: string;
|
|
paypal_mode?: string;
|
|
}
|
|
|
|
export interface SmtpSettingsResponse {
|
|
status: string;
|
|
data: {
|
|
smtp_host: string;
|
|
smtp_port: string;
|
|
smtp_user: string;
|
|
smtp_password: string;
|
|
smtp_password_masked: string;
|
|
smtp_from_email: string;
|
|
smtp_from_name: string;
|
|
smtp_use_tls: boolean;
|
|
has_host: boolean;
|
|
has_user: boolean;
|
|
has_password: boolean;
|
|
updated_at?: string | null;
|
|
updated_by?: string | null;
|
|
};
|
|
message?: string;
|
|
}
|
|
|
|
export interface UpdateSmtpSettingsRequest {
|
|
smtp_host?: string;
|
|
smtp_port?: string;
|
|
smtp_user?: string;
|
|
smtp_password?: string;
|
|
smtp_from_email?: string;
|
|
smtp_from_name?: string;
|
|
smtp_use_tls?: boolean;
|
|
}
|
|
|
|
export interface TestSmtpEmailRequest {
|
|
email: string;
|
|
}
|
|
|
|
export interface TestSmtpEmailResponse {
|
|
status: string;
|
|
message: string;
|
|
data: {
|
|
recipient: string;
|
|
sent_at: string;
|
|
};
|
|
}
|
|
|
|
export interface CompanySettingsResponse {
|
|
status: string;
|
|
data: {
|
|
company_name: string;
|
|
company_tagline: string;
|
|
company_logo_url: string;
|
|
company_favicon_url: string;
|
|
company_phone: string;
|
|
company_email: string;
|
|
company_address: string;
|
|
tax_rate: number;
|
|
updated_at?: string | null;
|
|
updated_by?: string | null;
|
|
};
|
|
message?: string;
|
|
}
|
|
|
|
export interface UpdateCompanySettingsRequest {
|
|
company_name?: string;
|
|
company_tagline?: string;
|
|
company_phone?: string;
|
|
company_email?: string;
|
|
company_address?: string;
|
|
tax_rate?: number;
|
|
}
|
|
|
|
export interface UploadLogoResponse {
|
|
status: string;
|
|
message: string;
|
|
data: {
|
|
logo_url: string;
|
|
full_url: string;
|
|
};
|
|
}
|
|
|
|
export interface UploadFaviconResponse {
|
|
status: string;
|
|
message: string;
|
|
data: {
|
|
favicon_url: string;
|
|
full_url: string;
|
|
};
|
|
}
|
|
|
|
export interface RecaptchaSettingsResponse {
|
|
status: string;
|
|
data: {
|
|
recaptcha_site_key: string;
|
|
recaptcha_enabled: boolean;
|
|
};
|
|
}
|
|
|
|
export interface RecaptchaSettingsAdminResponse {
|
|
status: string;
|
|
data: {
|
|
recaptcha_site_key: string;
|
|
recaptcha_secret_key: string;
|
|
recaptcha_secret_key_masked: string;
|
|
recaptcha_enabled: boolean;
|
|
has_site_key: boolean;
|
|
has_secret_key: boolean;
|
|
updated_at?: string | null;
|
|
updated_by?: string | null;
|
|
};
|
|
}
|
|
|
|
export interface UpdateRecaptchaSettingsRequest {
|
|
recaptcha_site_key?: string;
|
|
recaptcha_secret_key?: string;
|
|
recaptcha_enabled?: boolean;
|
|
}
|
|
|
|
export interface VerifyRecaptchaRequest {
|
|
token: string;
|
|
}
|
|
|
|
export interface VerifyRecaptchaResponse {
|
|
status: string;
|
|
data: {
|
|
verified: boolean;
|
|
score?: number;
|
|
action?: string;
|
|
error_codes?: string[];
|
|
message?: string;
|
|
};
|
|
}
|
|
|
|
const systemSettingsService = {
|
|
/**
|
|
* Get platform currency (public endpoint)
|
|
*/
|
|
getPlatformCurrency: async (): Promise<PlatformCurrencyResponse> => {
|
|
const response = await apiClient.get<PlatformCurrencyResponse>(
|
|
'/api/admin/system-settings/currency'
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Update platform currency (Admin only)
|
|
*/
|
|
updatePlatformCurrency: async (
|
|
currency: string
|
|
): Promise<PlatformCurrencyResponse> => {
|
|
const response = await apiClient.put<PlatformCurrencyResponse>(
|
|
'/api/admin/system-settings/currency',
|
|
{ currency }
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Get Stripe settings (Admin only)
|
|
*/
|
|
getStripeSettings: async (): Promise<StripeSettingsResponse> => {
|
|
const response = await apiClient.get<StripeSettingsResponse>(
|
|
'/api/admin/system-settings/stripe'
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Update Stripe settings (Admin only)
|
|
*/
|
|
updateStripeSettings: async (
|
|
settings: UpdateStripeSettingsRequest
|
|
): Promise<StripeSettingsResponse> => {
|
|
const response = await apiClient.put<StripeSettingsResponse>(
|
|
'/api/admin/system-settings/stripe',
|
|
settings
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Get PayPal settings (Admin only)
|
|
*/
|
|
getPayPalSettings: async (): Promise<PayPalSettingsResponse> => {
|
|
const response = await apiClient.get<PayPalSettingsResponse>(
|
|
'/api/admin/system-settings/paypal'
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Update PayPal settings (Admin only)
|
|
*/
|
|
updatePayPalSettings: async (
|
|
settings: UpdatePayPalSettingsRequest
|
|
): Promise<PayPalSettingsResponse> => {
|
|
const response = await apiClient.put<PayPalSettingsResponse>(
|
|
'/api/admin/system-settings/paypal',
|
|
settings
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Get SMTP settings (Admin only)
|
|
*/
|
|
getSmtpSettings: async (): Promise<SmtpSettingsResponse> => {
|
|
const response = await apiClient.get<SmtpSettingsResponse>(
|
|
'/api/admin/system-settings/smtp'
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Update SMTP settings (Admin only)
|
|
*/
|
|
updateSmtpSettings: async (
|
|
settings: UpdateSmtpSettingsRequest
|
|
): Promise<SmtpSettingsResponse> => {
|
|
const response = await apiClient.put<SmtpSettingsResponse>(
|
|
'/api/admin/system-settings/smtp',
|
|
settings
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Test SMTP email (Admin only)
|
|
*/
|
|
testSmtpEmail: async (
|
|
email: string
|
|
): Promise<TestSmtpEmailResponse> => {
|
|
const response = await apiClient.post<TestSmtpEmailResponse>(
|
|
'/api/admin/system-settings/smtp/test',
|
|
{ email }
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Get company settings (public endpoint)
|
|
*/
|
|
getCompanySettings: async (): Promise<CompanySettingsResponse> => {
|
|
const response = await apiClient.get<CompanySettingsResponse>(
|
|
'/api/admin/system-settings/company'
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Update company settings (Admin only)
|
|
*/
|
|
updateCompanySettings: async (
|
|
settings: UpdateCompanySettingsRequest
|
|
): Promise<CompanySettingsResponse> => {
|
|
const response = await apiClient.put<CompanySettingsResponse>(
|
|
'/api/admin/system-settings/company',
|
|
settings
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Upload company logo (Admin only)
|
|
*/
|
|
uploadCompanyLogo: async (
|
|
file: File
|
|
): Promise<UploadLogoResponse> => {
|
|
const formData = new FormData();
|
|
formData.append('image', file);
|
|
|
|
// Don't set Content-Type header - let the browser set it with the correct boundary
|
|
const response = await apiClient.post<UploadLogoResponse>(
|
|
'/api/admin/system-settings/company/logo',
|
|
formData
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Upload company favicon (Admin only)
|
|
*/
|
|
uploadCompanyFavicon: async (
|
|
file: File
|
|
): Promise<UploadFaviconResponse> => {
|
|
const formData = new FormData();
|
|
formData.append('image', file);
|
|
|
|
// Don't set Content-Type header - let the browser set it with the correct boundary
|
|
const response = await apiClient.post<UploadFaviconResponse>(
|
|
'/api/admin/system-settings/company/favicon',
|
|
formData
|
|
);
|
|
return response.data;
|
|
},
|
|
};
|
|
|
|
const recaptchaService = {
|
|
/**
|
|
* Get reCAPTCHA settings (public endpoint)
|
|
*/
|
|
getRecaptchaSettings: async (): Promise<RecaptchaSettingsResponse> => {
|
|
const response = await apiClient.get<RecaptchaSettingsResponse>(
|
|
'/api/admin/system-settings/recaptcha'
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Get reCAPTCHA settings (admin only)
|
|
*/
|
|
getRecaptchaSettingsAdmin: async (): Promise<RecaptchaSettingsAdminResponse> => {
|
|
const response = await apiClient.get<RecaptchaSettingsAdminResponse>(
|
|
'/api/admin/system-settings/recaptcha/admin'
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Update reCAPTCHA settings (admin only)
|
|
*/
|
|
updateRecaptchaSettings: async (
|
|
settings: UpdateRecaptchaSettingsRequest
|
|
): Promise<RecaptchaSettingsAdminResponse> => {
|
|
const response = await apiClient.put<RecaptchaSettingsAdminResponse>(
|
|
'/api/admin/system-settings/recaptcha',
|
|
settings
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Verify reCAPTCHA token
|
|
*/
|
|
verifyRecaptcha: async (
|
|
token: string
|
|
): Promise<VerifyRecaptchaResponse> => {
|
|
const response = await apiClient.post<VerifyRecaptchaResponse>(
|
|
'/api/admin/system-settings/recaptcha/verify',
|
|
{ token }
|
|
);
|
|
return response.data;
|
|
},
|
|
};
|
|
|
|
export default systemSettingsService;
|
|
export { recaptchaService };
|
|
|
|
export type {
|
|
PlatformCurrencyResponse,
|
|
UpdateCurrencyRequest,
|
|
StripeSettingsResponse,
|
|
UpdateStripeSettingsRequest,
|
|
PayPalSettingsResponse,
|
|
UpdatePayPalSettingsRequest,
|
|
SmtpSettingsResponse,
|
|
UpdateSmtpSettingsRequest,
|
|
TestSmtpEmailRequest,
|
|
TestSmtpEmailResponse,
|
|
CompanySettingsResponse,
|
|
UpdateCompanySettingsRequest,
|
|
UploadLogoResponse,
|
|
UploadFaviconResponse,
|
|
RecaptchaSettingsResponse,
|
|
RecaptchaSettingsAdminResponse,
|
|
UpdateRecaptchaSettingsRequest,
|
|
VerifyRecaptchaRequest,
|
|
VerifyRecaptchaResponse,
|
|
};
|
|
|