I am facing an issue in my Node Js application where I need to ensure that operations in my controller either all succeed together or none of them succeed. Here is the scenario:
In my Node Js controller, I perform operations that involve both internal calculations and calls to the Stripe API (e.g., creating customers, subscriptions).
If any internal calculation fails or encounters an error after the Stripe API operations have already succeeded, I want to ensure that any changes made via Stripe API are rolled back.
Essentially, I want to achieve transaction-like behavior where either everything in my controller (including Stripe operations) succeeds or everything fails, ensuring data integrity across all operations.
How can I ensure that if any part of my controller logic fails (internal calculations or Stripe API operations or any other third party API), all changes and operations are rolled back?