This commit is contained in:
spiro-alvin-nyasimi
2026-07-27 10:27:58 +03:00
parent 3ab155a8b8
commit c6a6755b08
17 changed files with 437 additions and 3 deletions

View File

@@ -0,0 +1,41 @@
package com.test.payment.models;
import java.time.LocalDateTime;
/**
* The window a provider limit applies over. PER_TRANSACTION checks the request
* amount on its own; the others sum the payer's prior payments over the window.
* Adding a new period (WEEKLY, YEARLY, ...) only means adding a constant here —
* PaymentLimitService iterates whatever rows exist in PROVIDER_LIMITS.
*/
public enum LimitPeriod {
PER_TRANSACTION {
@Override
public LocalDateTime windowStart(LocalDateTime now) {
return null;
}
},
DAILY {
@Override
public LocalDateTime windowStart(LocalDateTime now) {
return now.toLocalDate().atStartOfDay();
}
},
MONTHLY {
@Override
public LocalDateTime windowStart(LocalDateTime now) {
return now.toLocalDate().withDayOfMonth(1).atStartOfDay();
}
};
/**
* Start of the accumulation window, or null when the limit applies to a single
* transaction rather than to a running total.
*/
public abstract LocalDateTime windowStart(LocalDateTime now);
public boolean isCumulative() {
return this != PER_TRANSACTION;
}
}