def zuoraUpdate()

in lambda/src/main/scala/pricemigrationengine/migrations/GW2024Migration.scala [224:270]


  def zuoraUpdate(
      subscription: ZuoraSubscription,
      effectiveDate: LocalDate,
      oldPrice: BigDecimal,
      estimatedNewPrice: BigDecimal,
      priceCap: BigDecimal
  ): Either[DataExtractionFailure, ZuoraSubscriptionUpdate] = {
    for {
      ratePlan <- subscriptionToMigrationRatePlan(subscription).toRight(
        DataExtractionFailure(
          s"[a4d99cf3] Could not determine the Zuora migration rate plan for subscription ${subscription.subscriptionNumber}"
        )
      )
      ratePlanChargeId <- zuoraRatePlanToRatePlanChargeId(ratePlan).toRight(
        DataExtractionFailure(
          s"[105f6c88] Could not determine the rate plan charge id for rate plan ${ratePlan}"
        )
      )
      billingPeriod <- subscriptionToBillingPeriod(subscription).toRight(
        DataExtractionFailure(
          s"[17469705] Could not determine the billing period for subscription ${subscription.subscriptionNumber}"
        )
      )
    } yield ZuoraSubscriptionUpdate(
      add = List(
        AddZuoraRatePlan(
          productRatePlanId = ratePlan.productRatePlanId,
          contractEffectiveDate = effectiveDate,
          chargeOverrides = List(
            ChargeOverride(
              productRatePlanChargeId = ratePlanChargeId,
              billingPeriod = BillingPeriod.toString(billingPeriod),
              price = PriceCap.priceCapForNotification(oldPrice, estimatedNewPrice, priceCap)
            )
          )
        )
      ),
      remove = List(
        RemoveZuoraRatePlan(
          ratePlanId = ratePlan.id,
          contractEffectiveDate = effectiveDate
        )
      ),
      currentTerm = None,
      currentTermPeriodType = None
    )
  }