private def validateOldMembershipPrice()

in handlers/product-move-api/src/main/scala/com/gu/productmove/endpoint/move/switchtype/ToRecurringContribution.scala [209:242]


  private def validateOldMembershipPrice(
      currency: Currency,
      billingPeriod: BillingPeriod,
      price: BigDecimal,
  ): Task[Unit] = {
    val expectedPrices = Map(
      "GBP" -> Map("month" -> 5, "year" -> 49),
      "USD" -> Map("month" -> 6.99, "year" -> 69),
      "EUR" -> Map("month" -> 4.99, "year" -> 49),
      "AUD" -> Map("month" -> 10, "year" -> 100),
      "CAD" -> Map("month" -> 6.99, "year" -> 69),
    )

    val periodKey = billingPeriod match {
      case Monthly => "month"
      case Annual => "year"
      case _ => throw new IllegalArgumentException(s"Unsupported billing period: $billingPeriod")
    }

    val currencyCode = currency.iso

    expectedPrices.get(currencyCode) match {
      case Some(prices) if prices.get(periodKey).contains(price.toDouble) =>
        ZIO.unit
      case _ =>
        ZIO.fail(
          new Throwable(
            s"Invalid price $price for currency $currencyCode and billing period $billingPeriod. Expected: ${expectedPrices
                .get(currencyCode)
                .flatMap(_.get(periodKey))}",
          ),
        )
    }
  }