diff --git a/lambda/src/main/scala/pricemigrationengine/handlers/NotificationHandler.scala b/lambda/src/main/scala/pricemigrationengine/handlers/NotificationHandler.scala index ca0fca22..9c3102c3 100644 --- a/lambda/src/main/scala/pricemigrationengine/handlers/NotificationHandler.scala +++ b/lambda/src/main/scala/pricemigrationengine/handlers/NotificationHandler.scala @@ -79,14 +79,6 @@ object NotificationHandler extends CohortHandler { item: CohortItem, subscription: ZuoraSubscription ): ZIO[CohortTable with Zuora, Failure, Unit] = { - // Known keys for this mapping can be found in the BillingPeriod object - val mapping: Map[String, Int] = Map( - "Month" -> 1, - "Quarter" -> 4, - "Quarterly" -> 4, - "Semi_Annual" -> 6, - "Annual" -> 12 - ) for { cancellationDate <- ZIO .fromOption(SupporterPlus2024Migration.cancellationSaveDiscountEffectiveDate(subscription)) @@ -94,9 +86,7 @@ object NotificationHandler extends CohortHandler { billingPeriod <- ZIO .fromOption(item.billingPeriod) .orElseFail(DataExtractionFailure(s"Could not extract billing period for item ${item}")) - months <- ZIO - .fromOption(mapping.get(billingPeriod)) - .orElseFail(DataExtractionFailure(s"Could not extract mapping value for billing period ${billingPeriod}")) + months <- ZIO.succeed(CohortItem.billingPeriodToInt(billingPeriod)) _ <- CohortTable .update( CohortItem( diff --git a/lambda/src/main/scala/pricemigrationengine/model/CohortItem.scala b/lambda/src/main/scala/pricemigrationengine/model/CohortItem.scala index 2e6516d6..291566ca 100644 --- a/lambda/src/main/scala/pricemigrationengine/model/CohortItem.scala +++ b/lambda/src/main/scala/pricemigrationengine/model/CohortItem.scala @@ -96,4 +96,17 @@ object CohortItem { } } } + + def billingPeriodToInt(period: String): Int = { + // This function is used to convert a CohortItem's billingPeriod in to the number of months + // that the billing period represents. + period match { + case "Month" => 1 + case "Quarter" => 3 + case "Quarterly" => 3 + case "Semi_Annual" => 6 + case "Annual" => 12 + case _ => throw new Exception(s"could no recover month count for period: ${period}") + } + } }