def amendmentOrderPayload()

in lambda/src/main/scala/pricemigrationengine/migrations/SupporterPlus2024Migration.scala [386:423]


  def amendmentOrderPayload(
      orderDate: LocalDate,
      accountNumber: String,
      subscriptionNumber: String,
      effectDate: LocalDate,
      subscription: ZuoraSubscription,
      oldPrice: BigDecimal,
      estimatedNewPrice: BigDecimal,
      priceCap: BigDecimal
  ): Either[Failure, ZuoraAmendmentOrderPayload] = {
    for {
      existingRatePlan <- getSupporterPlusV2RatePlan(subscription)
      existingBaseRatePlanCharge <- getSupporterPlusBaseRatePlanCharge(
        subscription.subscriptionNumber,
        existingRatePlan
      )
      existingContributionRatePlanCharge <- getSupporterPlusContributionRatePlanCharge(
        subscription.subscriptionNumber,
        existingRatePlan
      )
      existingContributionPrice <- existingContributionRatePlanCharge.price.toRight(
        DataExtractionFailure(
          s"[e4e702b6] Could not extract existing contribution price for subscription ${subscription.subscriptionNumber}"
        )
      )
    } yield amendmentOrdersPayload(
      orderDate = orderDate,
      accountNumber = accountNumber,
      subscriptionNumber = subscriptionNumber,
      effectDate = effectDate,
      removeRatePlanId = existingRatePlan.id,
      productRatePlanId = existingRatePlan.productRatePlanId,
      existingBaseProductRatePlanChargeId = existingBaseRatePlanCharge.productRatePlanChargeId,
      existingContributionRatePlanChargeId = existingContributionRatePlanCharge.productRatePlanChargeId,
      newBaseAmount = PriceCap.priceCapForNotification(oldPrice, estimatedNewPrice, priceCap),
      newContributionAmount = existingContributionPrice
    )
  }