
Worldpay integration in .NET: the 'simple' payment system that spawns duplicate refunds, async ghosts, and finance team therapy sessions
A recent integration of Worldpay payment processing in ASP.NET Core has highlighted the importance of safe payment state management. The system's asynchronous nature can lead to incorrect order statuses, duplicate captures or refunds, and confusion among finance and support teams if not handled properly. To mitigate this, key principles such as tracking the current state explicitly, allowing only valid transitions, using idempotent processing, and maintaining an audit trail are essential. By following these principles, developers can ensure accurate payment states and prevent silent failures. Worldpay payments involve multiple steps, including authorization, capture, settlement, and refund, which can be triggered by API responses, webhooks, or scheduled background jobs. The implementation of a reusable payment event logging and state handling system has proven effective in preventing issues such as incorrect captures, refunds, or settlement mismatches, ultimately increasing customer and finance trust, and reducing debugging time and manual interventions.