Class SendSmsOneTimeCodeUseCase
The cost is reserved by SmsCostLedgerRepository.tryRecord(java.time.Instant, java.lang.String, long, com.irurueta.authserver.authorization.domain.sms.SmsSpendCap, com.irurueta.authserver.authorization.domain.sms.SmsSpendCap), which checks both caps and records the message
in one atomic step, so concurrent senders cannot overshoot a budget and a refused message costs nothing. The message
itself is not sent here: an SmsRequested event is published and sent after the transaction commits, off the
request thread, so the gateway is never called inside a transaction and a rolled-back request sends nothing. A
refusal does not roll the surrounding transaction back (noRollbackFor): this use case is joined by its
callers, and a rollback-only mark here would undo what they saved.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ClockSource of the current time.private final org.springframework.context.ApplicationEventPublisherPublishes the request to send the message.private final PhoneCountryResolverPort that finds the country of a number.private final SmsCostLedgerRepositoryPort that records the spend.private final SmsCostPolicyPolicy of countries, costs and caps. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute(PhoneNumber to, String text) Reserves the cost of a message and requests it.
-
Field Details
-
phoneCountryResolver
Port that finds the country of a number. -
smsCostPolicy
Policy of countries, costs and caps. -
smsCostLedgerRepository
Port that records the spend. -
eventPublisher
private final org.springframework.context.ApplicationEventPublisher eventPublisherPublishes the request to send the message. -
clock
Source of the current time.
-
-
Constructor Details
-
SendSmsOneTimeCodeUseCase
public SendSmsOneTimeCodeUseCase()
-
-
Method Details
-
execute
Reserves the cost of a message and requests it.- Parameters:
to- destination number.text- text of the message.- Throws:
SmsCountryNotAllowedException- if the country of the number is unknown or not served.SmsBudgetExceededException- if the message would exceed the cap of the window or of the day.
-