Skip to content

Commit

Permalink
prevent notification if under cancellation save
Browse files Browse the repository at this point in the history
  • Loading branch information
shtukas committed Sep 9, 2024
1 parent c9445fb commit 1962781
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,30 @@ object NotificationHandler extends CohortHandler {
count <- CohortTable
.fetch(SalesforcePriceRiceCreationComplete, Some(today.plusDays(maxLeadTime(cohortSpec))))
.take(batchSize)
.mapZIO(item => sendNotification(cohortSpec)(item, today))
.mapZIO(item =>
MigrationType(cohortSpec) match {
case SupporterPlus2024 => {
for {
subscription <- Zuora.fetchSubscription(item.subscriptionName)
_ <-
if (SupporterPlus2024Migration.isUnderActiveCancellationSave(subscription, today)) {
CohortTable
.update(
CohortItem(
subscriptionName = item.subscriptionName,
processingStage = DoNotProcessUntil,
doNotProcessUntil =
Some(today.minusMonths(6)) // TODO: compute from the start of the cancellation, not today
)
)
} else {
sendNotification(cohortSpec)(item, today)
}
} yield ()
}
case _ => sendNotification(cohortSpec)(item, today)
}
)
.runCount
} yield HandlerOutput(isComplete = count < batchSize)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ object SupporterPlus2024Migration {
} yield date
}

def isUnderActiveCancellationSave(subscription: ZuoraSubscription, today: LocalDate): Boolean = {
cancellationSaveEffectiveDate(subscription: ZuoraSubscription) match {
case None => false
case Some(date) => (date == today) || today.isBefore(date)
}
}

// ------------------------------------------------
// Subscription Data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ object CohortTableFilter {

case object AmendmentFailed extends CohortTableFilter { override val value: String = "AmendmentFailed" }

case object DoNotProcessUntil extends CohortTableFilter { override val value: String = "DoNotProcessUntil" }

// Set of all states. Remember to update when adding a state.
val all: Set[CohortTableFilter] = Set(
AmendmentComplete,
Expand All @@ -69,6 +71,7 @@ object CohortTableFilter {
NotificationSendComplete,
NotificationSendDateWrittenToSalesforce,
ReadyForEstimation,
SalesforcePriceRiceCreationComplete
SalesforcePriceRiceCreationComplete,
DoNotProcessUntil
)
}

0 comments on commit 1962781

Please sign in to comment.