Updates
This commit is contained in:
41
src/main/java/com/test/payment/models/LimitPeriod.java
Normal file
41
src/main/java/com/test/payment/models/LimitPeriod.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user