feat: implement tax calculations for subscription and SMS wallet payments
- 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.
This commit is contained in:
@@ -136,3 +136,49 @@ describe('SubscriptionPage', () => {
|
||||
expect(await screen.findByText('در حال حاضر پلنی برای نمایش وجود ندارد.')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
// ── Tax ────────────────────────────────────────────────────────────────────
|
||||
// قیمت دوره خالص است و مالیات رویش مینشیند؛ کارت و مودال باید جمع کل را نشان
|
||||
// دهند نه قیمت خالص را، وگرنه کاربر سرِ درگاه عدد دیگری میبیند.
|
||||
|
||||
const TAXED_PLANS = [
|
||||
{ uuid: 'p-basic', name: 'basic', level: 1, max_secretaries: 3, max_resources: 3,
|
||||
features: { patient_records: true, services: true, sms_panel: false }, active: true,
|
||||
periods: [
|
||||
{ uuid: 'per-1m', label: 'یک ماهه', duration_months: 1, price_rials: 1000000,
|
||||
tax_percent: 10, tax_rials: 100000, payable_rials: 1100000, is_trial: false },
|
||||
] },
|
||||
];
|
||||
|
||||
describe('SubscriptionPage — tax', () => {
|
||||
beforeEach(() => { get.mockReset(); mockApi({ plans: TAXED_PLANS }); });
|
||||
|
||||
it('shows the payable amount on the plan card, not the net price', async () => {
|
||||
renderWithProviders(<SubscriptionPage />, { route: '/admin/subscription' });
|
||||
const card = within(await screen.findByTestId('plan-card-basic'));
|
||||
|
||||
expect(card.getByText(formatRial(1100000))).toBeInTheDocument();
|
||||
expect(card.queryByText(formatRial(1000000))).not.toBeInTheDocument();
|
||||
expect(card.getByText(/۱۰٪ مالیات بر ارزش افزوده/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('breaks the price down inside the payment modal', async () => {
|
||||
renderWithProviders(<SubscriptionPage />, { route: '/admin/subscription' });
|
||||
const card = within(await screen.findByTestId('plan-card-basic'));
|
||||
fireEvent.click(card.getByText('تمدید اشتراک'));
|
||||
|
||||
await screen.findByText('پرداخت اشتراک');
|
||||
expect(screen.getByText('قیمت دوره')).toBeInTheDocument();
|
||||
expect(screen.getByText('مالیات بر ارزش افزوده ۱۰٪')).toBeInTheDocument();
|
||||
expect(screen.getByText('جمع کل')).toBeInTheDocument();
|
||||
expect(screen.getAllByText(formatRial(1100000)).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('falls back to the net price when the backend sends no tax fields', async () => {
|
||||
mockApi({ plans: PLANS });
|
||||
renderWithProviders(<SubscriptionPage />, { route: '/admin/subscription' });
|
||||
const card = within(await screen.findByTestId('plan-card-basic'));
|
||||
|
||||
expect(card.getByText(formatRial(9000000))).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user