Orders
An Order is a purchase record. In MIDDAG Account, WooCommerce handles the commerce -- products, checkout, payments, and subscriptions -- while MIDDAG Account handles what happens after the purchase: creating entitlements, tracking lifecycle, and connecting everything to the customer's organization.
Customers never see WooCommerce. The customer portal uses its own terminology ("orders" and "invoices," not "WooCommerce orders") and its own interface. WooCommerce is the backoffice engine, visible only to your admin team.
How orders create entitlements
This is the core pipeline. When a customer completes a purchase, MIDDAG Account automatically creates the entitlements that give them access to what they bought:
Step by step:
- Payment is confirmed -- via Stripe webhook (credit card), Banco Inter webhook (Pix or boleto), or manual admin confirmation.
- WooCommerce order status changes to completed -- this fires the standard WooCommerce hook.
- MIDDAG Account's provisioning service analyzes the order -- it reads each line item and checks the
_middag_entitlement_classproduct meta to determine what class of entitlement to create. - An entitlement is created for each line item -- with a unique code, status
active, and linked to the order and organization. - Downstream resources are provisioned -- a License for PLG items, an Environment for ENV items, a Service and Contract for SVC items, and so on.
The entire pipeline runs automatically. After a customer pays, they have their entitlements and access within seconds -- no admin intervention required.
Idempotency
If a payment webhook fires twice (which happens in practice), the system does not create duplicate entitlements. It checks whether an entitlement already exists for the same order + line item + class combination and skips creation if one is found.
Order lifecycle and entitlement lifecycle
The order status in WooCommerce maps to entitlement behavior:
| WooCommerce order status | Effect on entitlement |
|---|---|
| Completed | Entitlement created with status active |
| Processing | No entitlement yet -- payment is still being confirmed |
| On hold | No entitlement yet -- waiting for manual payment (boleto) |
| Refunded | Entitlement cancelled (if full refund) or remains active (partial, per policy) |
| Cancelled | Entitlement cancelled |
| Failed | No entitlement created |
For subscriptions (handled by WooCommerce Subscriptions):
| Subscription event | Effect on entitlement |
|---|---|
| Renewal paid | Entitlement remains active, expiration date extended |
| Renewal failed | Payment Recovery Policy consulted -- may suspend entitlement |
| Cancelled | Entitlement moves to expired or cancelled (per policy) |
| Upgraded | Same entitlement, tier attribute changes |
| Downgraded | Same entitlement, tier attribute changes (may require approval) |
WooCommerce Subscriptions handles all the complexity of recurring billing: proration, upgrade/downgrade calculations, and payment retry. MIDDAG Account's subscription adapter translates these events into entitlement lifecycle transitions.
Refund and cancellation impact
When an order is refunded or cancelled, the impact on the entitlement depends on the type:
- Full refund -- The linked entitlement is cancelled. Downstream resources (licenses, environments, services) are deactivated. The Refund Policy controls whether this happens automatically or requires admin approval.
- Partial refund -- The entitlement stays active by default. The admin can manually adjust the entitlement if the partial refund warrants reduced access.
- Order cancellation -- The entitlement is cancelled. If the entitlement was already provisioned, downstream resources are deactivated.
The Refund Policy (configurable through the Policy Engine) controls:
- How many days after purchase a refund is allowed
- Whether refunds below a threshold are processed automatically
- Whether credits are forfeited, retained, or adjusted proportionally
- Whether the entitlement is automatically cancelled after a full refund
Where orders come from
Orders in MIDDAG Account can originate from several paths:
| Origin | How it works |
|---|---|
| Quote accepted | Customer accepts a quote in the portal, WooCommerce order is created automatically, payment link is sent |
| Direct purchase | Admin creates an order in WooCommerce manually |
| Subscription renewal | WooCommerce Subscriptions creates a renewal order automatically |
| HubSpot deal | A deal in HubSpot syncs to a quote, which converts to an order |
Regardless of origin, the entitlement creation pipeline works the same way.
Dual-entity routing
Every order is routed to the correct MIDDAG legal entity -- MIDDAG BR (Brazil) or MIDDAG GLOBAL (US LLC) -- based on the organization's tax ID, billing entity setting, product configuration, or currency. This determines which Stripe account processes the payment and which tax rules apply.
The routing is automatic but can be overridden by an admin per transaction.
What admins see
In the WordPress admin, the orders view shows:
- Order number and date
- Organization name
- Amount and currency
- Payment status
- Billing entity (BR or GLOBAL)
- Linked entitlement codes
Admins also have a financial dashboard that aggregates data across both entities:
- Total revenue by period (monthly, quarterly, annual)
- Revenue split by entity (BR vs GLOBAL)
- Pending payments (unpaid boletos, open invoices)
- Overdue invoices
- Active vs cancelled subscriptions
The financial dashboard is admin-only -- customers do not have access to it. Customers see their own order history through the portal, with MIDDAG Account terminology (never WooCommerce labels).
Related pages
- Entitlements -- what orders create
- Entitlement Classes -- how the product determines what class of entitlement is created
- Policies -- refund, renewal, and payment recovery rules
- Organizations -- the customer entity that orders belong to
- How Concepts Connect -- the full relationship diagram