From 90249fcc451d7807d77e0d46714503e75676dda0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Honor=C3=A9?= Date: Thu, 28 Nov 2024 13:34:35 +0000 Subject: [PATCH 1/3] compute the doNotProcessUntil timespan for cancellation saves --- .../handlers/NotificationHandler.scala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lambda/src/main/scala/pricemigrationengine/handlers/NotificationHandler.scala b/lambda/src/main/scala/pricemigrationengine/handlers/NotificationHandler.scala index 20f41ca2..ca0fca22 100644 --- a/lambda/src/main/scala/pricemigrationengine/handlers/NotificationHandler.scala +++ b/lambda/src/main/scala/pricemigrationengine/handlers/NotificationHandler.scala @@ -79,16 +79,30 @@ 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)) .orElseFail(DataExtractionFailure(s"Could not extract cancellation date for item ${item}")) + 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}")) _ <- CohortTable .update( CohortItem( subscriptionName = item.subscriptionName, processingStage = DoNotProcessUntil, - doNotProcessUntil = Some(cancellationDate.plusMonths(6)) + doNotProcessUntil = Some(cancellationDate.plusMonths(months * 2)) ) ) } yield () From 6e16895fb17d7de51b220b798cb42f3b6842ba32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Honor=C3=A9?= Date: Thu, 28 Nov 2024 14:06:33 +0000 Subject: [PATCH 2/3] refactoring --- .../handlers/NotificationHandler.scala | 12 +----------- .../pricemigrationengine/model/CohortItem.scala | 13 +++++++++++++ 2 files changed, 14 insertions(+), 11 deletions(-) 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}") + } + } } From 1717f959901082232b27d9e38015e177a2009d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Honor=C3=A9?= Date: Thu, 28 Nov 2024 14:28:22 +0000 Subject: [PATCH 3/3] refactoring --- .../pricemigrationengine/model/CohortItem.scala | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lambda/src/main/scala/pricemigrationengine/model/CohortItem.scala b/lambda/src/main/scala/pricemigrationengine/model/CohortItem.scala index 291566ca..bb11f4c3 100644 --- a/lambda/src/main/scala/pricemigrationengine/model/CohortItem.scala +++ b/lambda/src/main/scala/pricemigrationengine/model/CohortItem.scala @@ -100,13 +100,11 @@ 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}") + BillingPeriod.fromString(period) match { + case Monthly => 1 + case Quarterly => 3 + case SemiAnnual => 6 + case Annual => 12 } } }