diff --git a/lambda/src/main/scala/pricemigrationengine/handlers/NotificationHandler.scala b/lambda/src/main/scala/pricemigrationengine/handlers/NotificationHandler.scala index cd670bd1..115e5811 100644 --- a/lambda/src/main/scala/pricemigrationengine/handlers/NotificationHandler.scala +++ b/lambda/src/main/scala/pricemigrationengine/handlers/NotificationHandler.scala @@ -129,6 +129,8 @@ object NotificationHandler extends CohortHandler { sp2024_previous_combined_amount <- ZIO.fromEither(sp2024_previous_combined_amount(cohortSpec, subscription)) sp2024_new_combined_amount <- ZIO.fromEither(sp2024_new_combined_amount(cohortSpec, subscription)) + brazeName <- ZIO.fromEither(brazeName(cohortSpec, subscription)) + _ <- EmailSender.sendEmail( message = EmailMessage( EmailPayload( @@ -159,7 +161,7 @@ object NotificationHandler extends CohortHandler { ) ) ), - cohortSpec.brazeCampaignName, + brazeName, contact.Id, contact.IdentityID__c ) @@ -498,4 +500,25 @@ object NotificationHandler extends CohortHandler { case _ => Right(None) } } + + // ------------------------------------------------------------------- + // Braze names + + // Note: + + // This function was introduced in September 2024, when as part of SupporterPlus2024 we integrated two different + // email templates in Braze to serve communication to the users. + + // Traditionally the name of the campaign or canvas has been part of the CohortSpec, making + // `cohortSpec.brazeCampaignName` the default carrier of this information, but in the case of SupporterPlus 2024 + // we have two canvases and need to decide one depending on the structure of the subscription. Once + // SupporterPlus2024 finished, we may decide to go back to a simpler format, or keep that function, depending + // on the likelihood of Marketing adopting this variation in the future. + + def brazeName(cohortSpec: CohortSpec, subscription: ZuoraSubscription): Either[Failure, String] = { + MigrationType(cohortSpec) match { + case SupporterPlus2024 => SupporterPlus2024Migration.brazeName(subscription) + case _ => Right(cohortSpec.brazeCampaignName) + } + } } diff --git a/lambda/src/main/scala/pricemigrationengine/migrations/SupporterPlus2024Migration.scala b/lambda/src/main/scala/pricemigrationengine/migrations/SupporterPlus2024Migration.scala index 72e263ff..31b4e23b 100644 --- a/lambda/src/main/scala/pricemigrationengine/migrations/SupporterPlus2024Migration.scala +++ b/lambda/src/main/scala/pricemigrationengine/migrations/SupporterPlus2024Migration.scala @@ -210,6 +210,32 @@ object SupporterPlus2024Migration { ) } + def hasNonTrivialContribution(subscription: ZuoraSubscription): Either[Failure, Boolean] = { + for { + amountOpt <- sp2024_contribution_amount(subscription: ZuoraSubscription) + amount <- amountOpt.toRight( + AmendmentDataFailure( + s"(error: 232760f5) could not extract contribution amount for subscription ${subscription.subscriptionNumber}" + ) + ) + } yield amount > 0 + } + + // ------------------------------------------------------------------- + // Braze names + + def brazeName(subscription: ZuoraSubscription): Either[Failure, String] = { + for { + status <- hasNonTrivialContribution(subscription: ZuoraSubscription) + } yield { + if (status) { + "SV_SP2_Contributors_PriceRise2024" + } else { + "SV_SP2_PriceRise2024" + } + } + } + // ------------------------------------------------ // Primary Interface // ------------------------------------------------ diff --git a/lambda/src/test/scala/pricemigrationengine/migrations/SupporterPlus2024MigrationTest.scala b/lambda/src/test/scala/pricemigrationengine/migrations/SupporterPlus2024MigrationTest.scala index b90ba08f..56a24994 100644 --- a/lambda/src/test/scala/pricemigrationengine/migrations/SupporterPlus2024MigrationTest.scala +++ b/lambda/src/test/scala/pricemigrationengine/migrations/SupporterPlus2024MigrationTest.scala @@ -7,6 +7,10 @@ import pricemigrationengine.Fixtures import pricemigrationengine.migrations.SupporterPlus2024Migration class SupporterPlus2024MigrationTest extends munit.FunSuite { + + // ----------------------------------- + // Cancellation saves + test("isInCancellationSave") { val subscriptionNo = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/sub-with-cancellation-save/subscription-no.json") @@ -21,7 +25,6 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite { true ) } - test("cancellationSaveEffectiveDate") { val subscriptionNo = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/sub-with-cancellation-save/subscription-no.json") @@ -37,6 +40,9 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite { ) } + // ----------------------------------- + // Price Grid + test("Price Grid (Old)") { assertEquals( SupporterPlus2024Migration.getOldPrice(Monthly, "USD"), @@ -58,6 +64,9 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite { ) } + // ----------------------------------- + // Rate plans extraction + // The monthly is GBP without a contribution [10, 0] // The annual is a AUD with contribution [160, 340] // sub-without-LastChangeType is a EUR without a contribution [6, 0] @@ -462,6 +471,9 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite { ) } + // ----------------------------------- + // Notification helpers sp2024_* + test("sp2024_previous_base_amount (monthly)") { val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/monthly/subscription.json") assertEquals( @@ -615,6 +627,9 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite { ) } + // ----------------------------------- + // priceData + test("priceData (monthly)") { val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/monthly/subscription.json") assertEquals( @@ -637,6 +652,9 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite { ) } + // ----------------------------------- + // EstimationResult + test("EstimationResult (monthly)") { val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/monthly/subscription.json") val invoices = Fixtures.invoiceListFromJson("Migrations/SupporterPlus2024/monthly/invoices.json") @@ -690,6 +708,27 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite { ) } + // ----------------------------------- + // braze names + + test("brazeName (monthly)") { + val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/monthly/subscription.json") + assertEquals( + SupporterPlus2024Migration.brazeName(subscription), + Right("SV_SP2_PriceRise2024") + ) + } + test("brazeName (annual)") { + val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/annual/subscription.json") + assertEquals( + SupporterPlus2024Migration.brazeName(subscription), + Right("SV_SP2_Contributors_PriceRise2024") + ) + } + + // ----------------------------------- + // zuoraUpdate + test("zuoraUpdate (monthly)") { val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/monthly/subscription.json") assertEquals(