Java – Rest API Design in case of partial success

apijavarest

So I have a ticket booking system.

I have ticket booking request on api, from my application we call payment service.

If failed on first attempt we proceed by adding message on queue for handling payment later. And proceed with issuing ticket to customer.

From queue we retry payment with payment api 10 times in 10 minutes if no success we add some status to that ticket booking record and by offline mean get money from customer.

Problem: We are getting many such booking due to credit card frauds.

Solution:

I have a solution in mind, I will not proceed with issuing ticket in payment fail , instead I want to return something different http code to client. like everything else except payment is success.

And while processing message from queue if it fails after 10 attempts I want to inform client this transaction is failed.

If pass let client know to proceed with issuing ticket

Question: Does this solution have technical feasibility ?

Best Answer

The HTTP return codes are designed to deal with the HTTP protocol, not every possible Request/Response.

Rather than selecting an obscure code that can, maybe, be interpreted, roughly, as what you want it to, if you squint at it. Simply return more information in the response body

200 OK
{
    "userCreation" : "Passed",
    "ticketReservation" : "Passed",
    "paymentProcessing" : "Failed"
    "orderStatus" : "PendingPayment"
}