Skip to content

Commit

Permalink
Tidy some stuff up
Browse files Browse the repository at this point in the history
  • Loading branch information
rupertbates committed Nov 9, 2023
1 parent 8c7917e commit f522603
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.gu.productmove.endpoint.move.ProductMoveEndpointTypes.{ErrorResponse,
import com.gu.productmove.zuora.GetSubscription.GetSubscriptionResponse
import com.gu.productmove.zuora.model.{SubscriptionId, SubscriptionName}
import com.gu.productmove.zuora.rest.ZuoraGet
import com.gu.productmove.zuora.rest.ZuoraRestBody.{ZuoraSuccessResultsArray, ZuoraSuccessCheck, ZuoraSuccessLowercase}
import com.gu.productmove.zuora.rest.ZuoraRestBody.{ZuoraSuccessCheck, ZuoraSuccessLowercase}
import com.gu.util.config
import sttp.capabilities.zio.ZioStreams
import sttp.capabilities.{Effect, WebSockets}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,20 @@ object ZuoraRestBody {
// the `/v1/object/` endpoint which we are using to get the user's payment method does not have a success property, and instead returns `size: "0"` if nothing was found
// Zuora either returns a "success" property with a lower or upper case starting letter, hence the need for SuccessCheckLowercase and SuccessCheckCapitalised enums
enum ZuoraSuccessCheck:
case SuccessCheckSize, SuccessCheckLowercase, SuccessCheckCapitalised, SuccessCheckResultsArray, None
case SuccessCheckSize, SuccessCheckLowercase, SuccessCheckCapitalised, None

case class Reason(
code: Int,
message: String,
)
given JsonDecoder[Reason] = DeriveJsonDecoder.gen

sealed trait ZuoraSuccessCheckResponse
case class ZuoraSuccessCapitalised(Success: Boolean, reasons: Option[List[Reason]])
given JsonDecoder[ZuoraSuccessCapitalised] = DeriveJsonDecoder.gen
case class ZuoraSuccessLowercase(success: Boolean, reasons: Option[List[Reason]])
given JsonDecoder[ZuoraSuccessLowercase] = DeriveJsonDecoder.gen
case class ZuoraSuccessSize(size: Option[Int])
given JsonDecoder[ZuoraSuccessSize] = DeriveJsonDecoder.gen
case class ZuoraSuccessResultsArray(results: List[ZuoraResultsArrayItem])
given JsonDecoder[ZuoraSuccessResultsArray] = DeriveJsonDecoder.gen
case class ZuoraResultsArrayItem(Success: Boolean)
given JsonDecoder[ZuoraResultsArrayItem] = DeriveJsonDecoder.gen

def attemptDecode[A](body: String)(implicit decoder: JsonDecoder[A]) =
body.fromJson[A].left.map(InternalServerError.apply)
Expand Down Expand Up @@ -151,17 +146,6 @@ object ZuoraRestBody {
case None => Left(InternalServerError(s"success = false, body: $body"))
}
} yield ()

case ZuoraSuccessCheck.SuccessCheckResultsArray =>
for {
zuoraResponse <- attemptDecode[ZuoraSuccessResultsArray](body)
isSuccessful <-
if (zuoraResponse.results.forall(_.Success)) Right(())
else
Left(InternalServerError(s"success = false, body: $body"))

} yield ()

case ZuoraSuccessCheck.None => Right(())
}

Expand Down

0 comments on commit f522603

Please sign in to comment.