Add charge failure details to /v1/subscription/{subscriberId}/receipt_credentials 402 response

This commit is contained in:
Katherine authored and GitHub committed 2023-11-08 10:54:14 -08:00
1 parent 1c3aa87ca6
commit 76d8e81dc9
1 file changed
+8 -1
@@ -593,7 +593,14 @@ public class StripeManager implements SubscriptionProcessorManager {
throw new WebApplicationException(Status.NO_CONTENT);
}
if (!StringUtils.equalsIgnoreCase("paid", latestSubscriptionInvoice.getStatus())) {
throw new WebApplicationException(Status.PAYMENT_REQUIRED);
final Response.ResponseBuilder responseBuilder = Response.status(Status.PAYMENT_REQUIRED);
if (latestSubscriptionInvoice.getChargeObject() != null) {
final Charge charge = latestSubscriptionInvoice.getChargeObject();
if (charge.getFailureCode() != null || charge.getFailureMessage() != null) {
responseBuilder.entity(Map.of("chargeFailure", createChargeFailure(charge)));
}
}
throw new WebApplicationException(responseBuilder.build());
}
return getInvoiceLineItemsForInvoice(latestSubscriptionInvoice).thenCompose(invoiceLineItems -> {