From 9f6ed76b2d176914983452672685d20f8bf32009 Mon Sep 17 00:00:00 2001 From: Rupert Bates Date: Fri, 8 Dec 2023 14:08:59 +0000 Subject: [PATCH 1/2] Don't try to adjust an invoice which already has a balance of zero --- .../switchtype/RecurringContributionToSupporterPlus.scala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/handlers/product-move-api/src/main/scala/com/gu/productmove/switchtype/RecurringContributionToSupporterPlus.scala b/handlers/product-move-api/src/main/scala/com/gu/productmove/switchtype/RecurringContributionToSupporterPlus.scala index ac07ffe306..7a46a04686 100644 --- a/handlers/product-move-api/src/main/scala/com/gu/productmove/switchtype/RecurringContributionToSupporterPlus.scala +++ b/handlers/product-move-api/src/main/scala/com/gu/productmove/switchtype/RecurringContributionToSupporterPlus.scala @@ -266,8 +266,10 @@ object RecurringContributionToSupporterPlus { charge of 50 cents. Instead we write-off the invoices in the `adjustNonCollectedInvoices` function. */ paidAmount <- - // not clear why we would want to create a negative payment, but this logic was already in place - if (invoiceBalance < 0 || invoiceBalance >= 0.5) { + if (invoiceBalance == 0) { + ZIO.succeed(BigDecimal(0)) + } else if (invoiceBalance < 0 || invoiceBalance >= 0.5) { + // not clear why we would want to create a negative payment, but this logic was already in place import account._ CreatePayment .create( @@ -532,7 +534,7 @@ object RecurringContributionToSupporterPlus { balanceToAdjust: BigDecimal, ): ZIO[InvoiceItemAdjustment with GetInvoiceItems, ErrorResponse, Unit] = for { - _ <- ZIO.log(s"Attempting to adjust invoice $invoiceId") + _ <- ZIO.log(s" Attempting to adjust invoice $invoiceId") invoiceResponse <- GetInvoiceItems.get(invoiceId) invoiceItems = invoiceResponse.invoiceItems invoiceItem <- ZIO From 66c66ca1bd6f636b24903c5b13c87488058cb1f6 Mon Sep 17 00:00:00 2001 From: Rupert Bates Date: Mon, 11 Dec 2023 11:03:24 +0000 Subject: [PATCH 2/2] Remove extra space from logging --- .../switchtype/RecurringContributionToSupporterPlus.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/product-move-api/src/main/scala/com/gu/productmove/switchtype/RecurringContributionToSupporterPlus.scala b/handlers/product-move-api/src/main/scala/com/gu/productmove/switchtype/RecurringContributionToSupporterPlus.scala index 7a46a04686..61dcd4ae91 100644 --- a/handlers/product-move-api/src/main/scala/com/gu/productmove/switchtype/RecurringContributionToSupporterPlus.scala +++ b/handlers/product-move-api/src/main/scala/com/gu/productmove/switchtype/RecurringContributionToSupporterPlus.scala @@ -534,7 +534,7 @@ object RecurringContributionToSupporterPlus { balanceToAdjust: BigDecimal, ): ZIO[InvoiceItemAdjustment with GetInvoiceItems, ErrorResponse, Unit] = for { - _ <- ZIO.log(s" Attempting to adjust invoice $invoiceId") + _ <- ZIO.log(s"Attempting to adjust invoice $invoiceId") invoiceResponse <- GetInvoiceItems.get(invoiceId) invoiceItems = invoiceResponse.invoiceItems invoiceItem <- ZIO