This project is a practical example of implementing a payment processing state machine using the Java Framework Spring Boot and Spring Statemachine. It demonstrates how to model the lifecycle of a payment—from creation through pre-authorization and final capture—in a clean and state-driven way.
- Java 17
- Spring Boot
- Spring Statemachine
- Spring Data JPA
- H2 Database
- Maven
- JUnit 5 & Spring Test
The machine follows a two-step payment authorization flow. The states and transitions are managed based on specific events that represent the outcome of payment operations.
The diagram below visually represents the entire flow of states and events described below.
-
Creation → Pre-Authorization:
- The process begins when a
PRE_AUTHORIZEevent is sent. - This transitions the payment into the
NEWstate, ready for processing.
- The process begins when a
-
Pre-Authorization Outcome:
- If the pre-authorization is successful, a
PRE_AUTH_APPROVEDevent moves the state toPRE_AUTH. The funds are now on hold. - If the pre-authorization is declined, a
PRE_AUTH_DECLINEDevent moves the state toPRE_AUTH_ERROR, which is a final failure state.
- If the pre-authorization is successful, a
-
Final Authorization (Capture) Outcome:
- From the
PRE_AUTHstate, anAUTHORIZEevent is sent to capture the held funds. - If the capture is successful, an
AUTHORIZEDevent transitions the state toAUTH, the final success state. - If the capture is declined, an
AUTH_DECLINEDevent transitions the state toAUTH_ERROR, another final failure state.
- From the