Skip to content

Commit

Permalink
Zuora response introspection
Browse files Browse the repository at this point in the history
  • Loading branch information
shtukas committed Oct 22, 2024
1 parent 83c19d4 commit 24645b1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,18 @@ object ZuoraRenewOrderPayload {
)
}
}

case class ZuoraRenewOrderResponseReason(code: Long, message: String)
object ZuoraRenewOrderResponseReason {
implicit val rwZuoraRenewOrderResponseReason: ReadWriter[ZuoraRenewOrderResponseReason] = macroRW
}

case class ZuoraRenewOrderResponse(
success: Boolean,
processId: String,
reasons: List[ZuoraRenewOrderResponseReason],
requestId: String
)
object ZuoraRenewOrderResponse {
implicit val rwZuoraRenewOrderResponse: ReadWriter[ZuoraRenewOrderResponse] = macroRW
}
32 changes: 21 additions & 11 deletions lambda/src/main/scala/pricemigrationengine/services/ZuoraLive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,28 @@ object ZuoraLive {
subscriptionNumber: String,
payload: ZuoraRenewOrderPayload
): ZIO[Any, ZuoraRenewalFailure, Unit] = {
retry(
post[Unit](
path = s"orders",
body = write(payload)
).mapBoth(
e =>

post[ZuoraRenewOrderResponse](
path = s"orders",
body = write(payload)
).foldZIO(
e =>
ZIO.fail(
ZuoraRenewalFailure(
s"Failed to renew subscription number ${subscriptionNumber} with payload: ${payload}"
),
response => ()
)
) <* logging.info(s"renewed subscription ${subscriptionNumber}")
s"Subscription number: $subscriptionNumber, payload: ${payload}, reason: ${e.reason}"
)
),
answer =>
if (answer.success) {
ZIO.succeed(())
} else {
ZIO.fail(
ZuoraRenewalFailure(
s"Subscription number: $subscriptionNumber, payload: ${payload}, with answer ${answer}"
)
)
}
)
}
}
)
Expand Down

0 comments on commit 24645b1

Please sign in to comment.