fix(billing): 월별 비용 계산 시 연도 무시 버그 수정

- hasBillingInMonth()에서 targetYear를 실제로 사용하도록 수정
- 연간 구독 수정 시 잘못된 월에 비용이 포함되던 문제 해결
- 연도+월을 포함한 개월 차이 계산으로 정확한 결제 발생 여부 판단
This commit is contained in:
JiWoong Sul
2026-01-29 23:55:57 +09:00
parent 5de33992a2
commit 903906c880

View File

@@ -214,20 +214,20 @@ class BillingCostUtil {
// 결제 주기에 따른 개월 수
final cycleMonths = _getCycleMonths(normalizedCycle);
// 결제 발생 월 계산 (nextBillingDate 기준으로 역산)
final billingMonth = nextBillingDate.month;
// 연도+월을 포함한 개월 차이 계산
// nextBillingDate와 target 월 사이의 차이가 cycleMonths의 배수인지 확인
final targetStart = DateTime(targetYear, targetMonth, 1);
final billingStart =
DateTime(nextBillingDate.year, nextBillingDate.month, 1);
// 대상 월이 결제 발생 월과 일치하는지 확인
// 예: 연간 결제(1월), targetMonth = 1 → true
// 예: 연간 결제(1월), targetMonth = 2 → false
for (int i = 0; i < 12; i += cycleMonths) {
final checkMonth = ((billingMonth - 1 + i) % 12) + 1;
if (checkMonth == targetMonth) {
return true;
}
}
final monthDiff = (billingStart.year - targetStart.year) * 12 +
(billingStart.month - targetStart.month);
return false;
// monthDiff가 cycleMonths의 배수이면 해당 월에 결제 발생
// 예: 연간 결제(2027-01), target=2026-01 → monthDiff=12, 12%12=0 → true (이전 결제)
// 예: 연간 결제(2027-01), target=2026-02 → monthDiff=11, 11%12≠0 → false
// 예: 연간 결제(2027-01), target=2027-01 → monthDiff=0, 0%12=0 → true
return monthDiff % cycleMonths == 0;
}
/// 결제 주기별 개월 수 반환