- Updated SubscriptionPeriod interface to include tax-related fields: tax_percent, tax_rials, and payable_rials. - Modified payment API documentation to reflect changes in tax handling for subscriptions and SMS wallet charges. - Adjusted PaymentController to calculate payment amounts based on subscription period details instead of client input. - Enhanced PaymentManager to handle net amounts for SMS wallet charges, ensuring tax is not credited to the wallet. - Created PaymentTaxCalculator and SubscriptionTaxCalculator services to manage tax calculations consistently across payment types. - Added tests for tax calculations in both subscription and SMS wallet contexts, ensuring correct behavior with and without tax enabled. - Updated frontend components to display tax information appropriately during payment processes.
30 lines
818 B
TypeScript
30 lines
818 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { api } from '../lib/api';
|
|
import type { ApiResponse } from '../lib/api';
|
|
|
|
export interface PaymentGatewayInfo {
|
|
name: string;
|
|
label: string;
|
|
}
|
|
|
|
interface PaymentConfig {
|
|
test_mode: boolean;
|
|
appointment_fee_rials: number;
|
|
gateways: PaymentGatewayInfo[];
|
|
/** نرخ مالیات اشتراک و شارژ کیف پول؛ صفر یعنی خاموش. */
|
|
tax_percent: number;
|
|
}
|
|
|
|
export function usePaymentConfig() {
|
|
const { data } = useQuery<ApiResponse<PaymentConfig>>({
|
|
queryKey: ['payment-config'],
|
|
queryFn: () => api.get('/api/v1/payment/config'),
|
|
staleTime: 5 * 60 * 1000,
|
|
});
|
|
return {
|
|
isTestMode: data?.data?.test_mode ?? false,
|
|
gateways: data?.data?.gateways ?? [],
|
|
taxPercent: data?.data?.tax_percent ?? 0,
|
|
};
|
|
}
|