def isBelowMinimumStripeCharge()

in handlers/product-move-api/src/main/scala/com/gu/productmove/zuora/BuildPreviewResult.scala [13:45]


  def isBelowMinimumStripeCharge(amount: BigDecimal): Boolean =
    amount > BigDecimal(0) && amount < BigDecimal(0.50)

  def getRefundInvoiceAmount(
      subscriptionName: SubscriptionName,
      invoice: SubscriptionUpdateInvoice,
      invoiceItems: List[SubscriptionUpdateInvoiceItem],
      activeRatePlanCharge: RatePlanCharge,
  ): Task[BigDecimal] =
    if (invoiceItems.isEmpty) {
      /*
          Term renewal for many subs happens during the billing run on the renewal day which is scheduled for around 6am BST.
          During this billing run, Zuora does not return the contribution invoice item, only supporter plus invoice items.
          When this happens we can just use the full price of the active rate plan as the amount to be refunded
       */
      for {
        _ <- ZIO.log(s"Entered edge case. Subscription name is $subscriptionName. Invoice data was: $invoice")
        priceDifference <- ZIO
          .fromOption(activeRatePlanCharge.price)
          .orElseFail(
            new Throwable(
              s"Price is null on rate plan. Subscription name is $subscriptionName. Invoice data was: $invoice",
            ),
          )
      } yield BigDecimal.valueOf(priceDifference)
    } else {
      for {
        date <- Clock.currentDateTime.map(_.toLocalDate)
        invoice =
          invoiceItems
            .find(invoiceItem => invoiceItem.totalAmount <= 0 && invoiceItem.serviceStartDate == date)
      } yield invoice.head.totalAmount
    }