41 lines
1.2 KiB
Java
41 lines
1.2 KiB
Java
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;
|
|
}
|
|
} |