This is all about Retry Logics! This is part2 where I am testing the starter boiler code for the payment flow. I was specifically looking forward to make this system robust as I suspect there could be times when there would be database deadlocks, timeout, rate limiiting exceeds,intermittent connectivity issue.
So, I refactored at the code to include retry logic at the top level and the deepest level of the payment flow.
That’s the retry code logic at the viewset level.

So, if I am giving the paymenttype as None which matches nothing at the payment processor strategies, then here are the bunch of events that would happen!
- In first attempt , it would go to the try block
- This will call the external payment service

- Payment’s service try block will execute and it will go to the first else block and throw an error
- Goes to the except block and then except block of the calling function which is in orders service

- This will again be thrown to the except block of the order’s service where the attempts is increased by 1
- Mark this is a loop and attempt is still less than 3 then it would again attempt to initiate the payment through the above flow, at last would return the error of the order’s service main method

Now if the payment strategy is correct and then there are some other after the flow enters the payment processor flow then the circuit breaker come to effect.