in lambda/src/main/scala/pricemigrationengine/handlers/SalesforcePriceRiseCreationHandler.scala [65:111]
def buildPriceRise(
cohortSpec: CohortSpec,
cohortItem: CohortItem,
subscription: SalesforceSubscription
): IO[SalesforcePriceRiseWriteFailure, SalesforcePriceRise] = {
for {
oldPrice <-
ZIO
.fromOption(cohortItem.oldPrice)
.orElseFail(SalesforcePriceRiseWriteFailure(s"$cohortItem does not have an oldPrice"))
estimatedNewPrice <-
ZIO
.fromOption(cohortItem.estimatedNewPrice)
.orElseFail(SalesforcePriceRiseWriteFailure(s"$cohortItem does not have an estimatedNewPrice"))
priceRiseDate <-
ZIO
.fromOption(cohortItem.startDate)
.orElseFail(SalesforcePriceRiseWriteFailure(s"$cohortItem does not have a startDate"))
} yield {
val estimatedPriceWithOptionalCapping = MigrationType(cohortSpec) match {
case Newspaper2024 => estimatedNewPrice
case GW2024 => PriceCap.priceCapForNotification(oldPrice, estimatedNewPrice, GW2024Migration.priceCap)
case SupporterPlus2024 => estimatedNewPrice // [1]
case Default => PriceCap.priceCapLegacy(oldPrice, estimatedNewPrice)
}
// [1]
// (Comment group: 7992fa98)
// This value wasn't actually used because we did that step using a Ruby script (we did not run the
// SalesforcePriceRiseCreationHandler from the AWS step function).
// The problem was that from the CohortItem we only had the old base price and the new base price
// but not the contribution component, and therefore we could not compute the total which is what
// we need to send to Salesforce.
SalesforcePriceRise(
Some(subscription.Name),
Some(subscription.Buyer__c),
Some(oldPrice),
Some(estimatedPriceWithOptionalCapping),
Some(priceRiseDate),
Some(subscription.Id),
Migration_Name__c = Some(cohortSpec.cohortName),
Migration_Status__c = Some("EstimationComplete"),
Cancellation_Reason__c = None
)
}
}