r/WordpressPlugins • u/Hugo_SecureHoldWP • Oct 13 '26
[DISCUSSION] Plugin developers: how would you model a refundable security deposit in WooCommerce?
I’ve been thinking about how a WordPress plugin should model refundable security deposits in WooCommerce, especially for rental and booking use cases.
The obvious implementation is to treat the deposit like a normal payment: charge it with the order, keep the money, then refund it later if everything is fine.
But that feels like a very different lifecycle from the actual order payment.
Another approach is to keep the two separate. The order is paid normally, while the security deposit is represented by a separate card authorization that can later be captured or released.
From a plugin architecture point of view, that raises a lot of interesting questions:
- should the deposit have its own state machine separate from the WooCommerce order?
- how should the plugin handle expired authorization windows?
- how do you make capture/release safe to retry?
- what happens if the payment provider succeeds but WordPress fails to persist the new state?
- how much operational history should the plugin retain?
- how do you handle partial capture without making the state model messy?
I’m curious how other plugin developers would structure this.
Would you treat the security deposit as part of the order payment lifecycle, or as its own financial object linked to the order?
2
u/PeepSoWP Oct 15 '26
I would treat the deposit as its own state machine linked to the order, rather than adding more WooCommerce order statuses. Store the gateway authorization ID, amount and currency, authorization time and expiry, captured and released amounts, an idempotency key, the last error, and an append-only event history. Each capture or release should claim that deposit record without waiting, verify the current state, and call the gateway with an idempotency key. Because gateway success and a failed database write can split, run a bounded reconciler that queries the gateway and repairs local state. Model partial captures as separate transactions whose total cannot exceed the authorization, and retry failures later with backoff instead of holding a checkout or admin request open.
1
u/[deleted] Oct 15 '26
[removed] — view removed comment