Files
edr-platform/apps/edr-freight-web/backoffice/src/services/manualPaymentSettings.service.ts
2026-09-06 16:35:14 +03:00

57 lines
1.8 KiB
TypeScript

import { api as client } from "../auth/http";
import { unwrap } from "@/utils/endpoint";
import { URL_CONSTANTS } from "@/constants/URLS";
import type { ApiResponse } from "@/types/apiResponse";
const BASE = URL_CONSTANTS.MANUAL_PAYMENT_SETTINGS.BASE;
/**
* Whether Finance may settle invoices by hand (bank transfer / counter) rather
* than the customer paying online — switched per currency, because the two
* channels are operationally different.
*/
export interface ManualPaymentSettings {
etbEnabled: boolean;
usdEnabled: boolean;
djfEnabled: boolean;
/**
* Wider than `djfEnabled`: whether DJF is accepted as a payment currency at
* all — offered on the booking forms and payable online. Off leaves existing
* DJF invoices settleable by hand.
*/
djfPaymentsEnabled: boolean;
updatedById: string | null;
updatedAt?: string;
}
export const manualPaymentSettingsService = {
get: async (): Promise<ManualPaymentSettings> => {
const response = await client.get<ApiResponse<ManualPaymentSettings>>(BASE);
return unwrap(response.data);
},
/** Currencies customers may be billed and pay in — open read, no permission. */
currencies: async (): Promise<string[]> => {
const response = await client.get<ApiResponse<string[]>>(
URL_CONSTANTS.MANUAL_PAYMENT_SETTINGS.CURRENCIES,
);
return unwrap(response.data);
},
/** Partial: an omitted currency keeps its current setting. */
update: async (
patch: Partial<
Pick<
ManualPaymentSettings,
"etbEnabled" | "usdEnabled" | "djfEnabled" | "djfPaymentsEnabled"
>
>,
): Promise<ManualPaymentSettings> => {
const response = await client.patch<ApiResponse<ManualPaymentSettings>>(
BASE,
patch,
);
return unwrap(response.data);
},
};