r/WordpressPlugins • • 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 Upvotes

4 comments sorted by

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/Hugo_SecureHoldWP Oct 16 '26

This is probably the clearest version of the model so far.

I like the idea of separating the durable deposit record from the append-only event history, especially if the local “current state” can always be rebuilt or reconciled from provider-confirmed outcomes.

The bounded reconciler is the part I find most important here. If the gateway succeeds and the database write fails, that ambiguity has to become explicit recovery work rather than something a checkout or admin request quietly retries.

The partial-capture point is useful too. Treating each capture as its own transaction and enforcing that the cumulative total never exceeds the original authorization seems much safer than trying to mutate one generic captured amount without history.

1

u/[deleted] Oct 15 '26

[removed] — view removed comment

1

u/Hugo_SecureHoldWP Oct 15 '26

That’s the direction I’m leaning toward too.

Keeping the deposit as its own financial object linked to the order seems much cleaner than trying to encode its lifecycle into WooCommerce order statuses.

It also makes the failure cases easier to reason about: the order can be “done” commercially while the deposit is still authorized, partially captured, released or expired on its own timeline.

The part I’m finding most important is making that separate lifecycle explicit enough that retries, webhooks and recovery don’t accidentally bleed back into the main order state.