Skip to content

Commit

Permalink
Merge branch 'main' into update/non_aws
Browse files Browse the repository at this point in the history
  • Loading branch information
shtukas authored Feb 13, 2024
2 parents bddaeda + 9dee7ec commit 59b1f19
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,18 @@ object NotificationHandler extends CohortHandler {
val Unsuccessful = 0
val Cancelled_Status = "Cancelled"

// For general information about the notification period see the docs/notification-periods.md

// The standard notification period for letter products (where the notification is delivered by email)
// is -49 (included) to -35 (excluded) days. Legally the min is 30 days, but we set 35 days to alert if a
// subscription if exiting the notification window and needs to be investigated and repaired before the deadline
// of 30 days.

val letterMaxNotificationLeadTime = 49

// The digital migrations' notification window is from -33 (included) to -31 (excluded)

def maxLeadTime(cohortSpec: CohortSpec): Int = {
MigrationType(cohortSpec) match {
case Membership2023Monthlies => 33
case Membership2023Annuals => 33
case SupporterPlus2023V1V2MA => 33
case DigiSubs2023 => 33
case Newspaper2024 => newspaper2024Migration.StaticData.maxLeadTime
case Legacy => 49
}
}

def minLeadTime(cohortSpec: CohortSpec): Int = {
MigrationType(cohortSpec) match {
case Membership2023Monthlies => 31
case Membership2023Annuals => 31
case SupporterPlus2023V1V2MA => 31
case DigiSubs2023 => 31
case Newspaper2024 => newspaper2024Migration.StaticData.minLeadTime
case Legacy => 35
}
}

def thereIsEnoughNotificationLeadTime(cohortSpec: CohortSpec, today: LocalDate, cohortItem: CohortItem): Boolean = {
// To help with backward compatibility with existing tests, we apply this condition from 1st Dec 2022.
if (today.isBefore(LocalDate.of(2020, 12, 1))) {
true
} else {
cohortItem.startDate match {
case Some(sd) => today.plusDays(minLeadTime(cohortSpec)).isBefore(sd)
case _ => false
}
}
def handle(input: CohortSpec): ZIO[Logging, Failure, HandlerOutput] = {
main(input).provideSome[Logging](
EnvConfig.salesforce.layer,
EnvConfig.cohortTable.layer,
EnvConfig.emailSender.layer,
EnvConfig.stage.layer,
DynamoDBClientLive.impl,
DynamoDBZIOLive.impl,
CohortTableLive.impl(input),
SalesforceClientLive.impl,
EmailSenderLive.impl
)
}

def main(
Expand Down Expand Up @@ -112,22 +81,6 @@ object NotificationHandler extends CohortHandler {
}
}

def currencyISOtoSymbol(iso: String): ZIO[Any, Nothing, String] = {
ZIO.succeed(i18n.Currency.fromString(iso: String).map(_.identifier).getOrElse(""))
}

def dateStrToLocalDate(startDate: String): LocalDate = {
LocalDate.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"))
}

def emailUserFriendlyDateFormatter(startDate: LocalDate): String = {
startDate.format(DateTimeFormatter.ofPattern("d MMMM uuuu"));
}

def startDateConversion(startDate: String): String = {
emailUserFriendlyDateFormatter(dateStrToLocalDate(startDate: String))
}

def sendNotification(
cohortSpec: CohortSpec,
cohortItem: CohortItem,
Expand Down Expand Up @@ -198,6 +151,71 @@ object NotificationHandler extends CohortHandler {
_ <- updateCohortItemStatus(cohortItem.subscriptionName, NotificationSendComplete)
} yield Successful

// -------------------------------------------------------------------
// Notification Windows

// For general information about the notification period see the docs/notification-periods.md

// The standard notification period for letter products (where the notification is delivered by email)
// is -49 (included) to -35 (excluded) days. Legally the min is 30 days, but we set 35 days to alert if a
// subscription if exiting the notification window and needs to be investigated and repaired before the deadline
// of 30 days.

// The digital migrations' notification window is from -33 (included) to -31 (excluded)

def maxLeadTime(cohortSpec: CohortSpec): Int = {
MigrationType(cohortSpec) match {
case Membership2023Monthlies => 33
case Membership2023Annuals => 33
case SupporterPlus2023V1V2MA => 33
case DigiSubs2023 => 33
case Newspaper2024 => newspaper2024Migration.StaticData.maxLeadTime
case Legacy => 49
}
}

def minLeadTime(cohortSpec: CohortSpec): Int = {
MigrationType(cohortSpec) match {
case Membership2023Monthlies => 31
case Membership2023Annuals => 31
case SupporterPlus2023V1V2MA => 31
case DigiSubs2023 => 31
case Newspaper2024 => newspaper2024Migration.StaticData.minLeadTime
case Legacy => 35
}
}

def thereIsEnoughNotificationLeadTime(cohortSpec: CohortSpec, today: LocalDate, cohortItem: CohortItem): Boolean = {
// To help with backward compatibility with existing tests, we apply this condition from 1st Dec 2022.
if (today.isBefore(LocalDate.of(2020, 12, 1))) {
true
} else {
cohortItem.startDate match {
case Some(sd) => today.plusDays(minLeadTime(cohortSpec)).isBefore(sd)
case _ => false
}
}
}

// -------------------------------------------------------------------
// Support Functions

def currencyISOtoSymbol(iso: String): ZIO[Any, Nothing, String] = {
ZIO.succeed(i18n.Currency.fromString(iso: String).map(_.identifier).getOrElse(""))
}

def dateStrToLocalDate(startDate: String): LocalDate = {
LocalDate.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"))
}

def emailUserFriendlyDateFormatter(startDate: LocalDate): String = {
startDate.format(DateTimeFormatter.ofPattern("d MMMM uuuu"));
}

def startDateConversion(startDate: String): String = {
emailUserFriendlyDateFormatter(dateStrToLocalDate(startDate: String))
}

def requiredField[A](field: Option[A], fieldName: String): Either[NotificationHandlerFailure, A] = {
field match {
case Some(value) => Right(value)
Expand Down Expand Up @@ -313,18 +331,4 @@ object NotificationHandler extends CohortHandler {
)
_ <- Logging.error(s"Subscription $subscriptionName has been cancelled, price rise notification not sent")
} yield 0

def handle(input: CohortSpec): ZIO[Logging, Failure, HandlerOutput] = {
main(input).provideSome[Logging](
EnvConfig.salesforce.layer,
EnvConfig.cohortTable.layer,
EnvConfig.emailSender.layer,
EnvConfig.stage.layer,
DynamoDBClientLive.impl,
DynamoDBZIOLive.impl,
CohortTableLive.impl(input),
SalesforceClientLive.impl,
EmailSenderLive.impl
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ case class ZuoraRatePlanCharge(
billingDay: Option[String] = None,
triggerEvent: Option[String] = None,
triggerDate: Option[LocalDate] = None,
discountPercentage: Option[Double] = None
discountPercentage: Option[Double] = None,
originalOrderDate: Option[LocalDate] = None
)

object ZuoraRatePlanCharge {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("ContractEffective"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2016, 11, 13))
)
)

Expand Down Expand Up @@ -87,7 +88,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("ContractEffective"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2016, 11, 13))
)
),
lastChangeType = None
Expand Down Expand Up @@ -155,7 +157,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("ContractEffective"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2017, 1, 20))
)
)

Expand Down Expand Up @@ -193,7 +196,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("ContractEffective"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2017, 1, 20))
)
),
lastChangeType = None
Expand Down Expand Up @@ -261,7 +265,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("ContractEffective"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2017, 1, 20))
)
)

Expand Down Expand Up @@ -299,7 +304,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("ContractEffective"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2017, 1, 20))
)
),
lastChangeType = None
Expand Down Expand Up @@ -365,7 +371,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("CustomerAcceptance"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2023, 4, 1))
)
)

Expand Down Expand Up @@ -403,7 +410,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("CustomerAcceptance"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2023, 4, 1))
)
),
lastChangeType = Some("Add")
Expand Down Expand Up @@ -486,7 +494,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("CustomerAcceptance"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2023, 7, 3))
)
)

Expand Down Expand Up @@ -524,7 +533,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("CustomerAcceptance"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2023, 7, 3))
)
),
lastChangeType = None
Expand Down Expand Up @@ -619,7 +629,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("CustomerAcceptance"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2023, 7, 2))
)
)

Expand Down Expand Up @@ -657,7 +668,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("CustomerAcceptance"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2023, 7, 2))
)
),
lastChangeType = None
Expand Down Expand Up @@ -737,7 +749,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("CustomerAcceptance"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2023, 6, 28))
)
)

Expand Down Expand Up @@ -775,7 +788,8 @@ class AmendmentHandlerTest extends munit.FunSuite {
billingDay = Some("ChargeTriggerDay"),
triggerEvent = Some("CustomerAcceptance"),
triggerDate = None,
discountPercentage = None
discountPercentage = None,
originalOrderDate = Some(LocalDate.of(2023, 6, 28))
)
),
lastChangeType = None
Expand Down
Loading

0 comments on commit 59b1f19

Please sign in to comment.