Orders and Entitlements
When a WooCommerce order reaches Completed status, MIDDAG Account processes each line item and creates the appropriate entitlements. This page explains that pipeline in detail.
The order-to-entitlement pipeline
Step by step
1. Payment is confirmed
A payment webhook arrives from Stripe (credit card) or Banco Inter (Pix, Boleto), or the admin manually marks the order as paid. WooCommerce transitions the order to Completed status.
2. The provisioning service picks up the order
The EntitlementProvisioningService listens for the woocommerce_order_status_completed hook. When fired, it loads the order and iterates through each line item.
3. Each line item is checked for a class mapping
For every line item, the service reads the _middag_entitlement_class meta from the linked WooCommerce product. If the meta is absent, the item is skipped -- it is a standard product that does not create an entitlement.
4. An entitlement is created
For each mapped line item, the service creates an entitlement:
| Field | Value |
|---|---|
| Code | Auto-generated: {CLASS}-{YEAR}{MONTH}{SEQ:4d} (e.g., PLG-2026050042) |
| Class | From the product mapping |
| Status | active |
| Organization | Resolved from the customer's WordPress account |
| Order reference | WooCommerce order ID |
| Start date | Payment confirmation timestamp |
| End date | Calculated from billing period (subscriptions) or set by product config |
5. Downstream resources are provisioned
Based on the entitlement class, additional resources are created:
| Class | Downstream resources created |
|---|---|
| PLG | License key (with activation limit), download access |
| ENV | Environment instance (managed hosting) |
| SVC | Service record, Contract, initial Credit Balance |
| ORD | Order link only (general-purpose entitlement) |
| AFL | Affiliate record in SolidAffiliate |
| EDU | Course/training access record |
6. The customer is notified
A notification is sent to the organization's email confirming the new entitlement(s), including the entitlement code and access instructions.
Multi-item orders
An order can contain multiple line items, each potentially mapping to a different entitlement class. The provisioning service processes each item independently:
- An order with a plugin license + hosting plan creates one PLG entitlement and one ENV entitlement
- An order with three plugin products creates three separate PLG entitlements
- Line items without class mappings (e.g., a setup fee coded as a WC fee) are skipped
Each entitlement gets its own unique code and its own downstream resources.
Idempotency
Payment webhooks can fire more than once (this is common with Stripe). The provisioning service checks whether an entitlement already exists for the same order + line item + class combination before creating a new one. Duplicate webhooks are safely ignored.
Where orders come from
Orders are not always created by the customer through a storefront:
| Origin | How it works |
|---|---|
| Quote accepted | Customer accepts a quote in the portal; a WC order is created automatically |
| Admin-created | Admin creates an order directly in WooCommerce |
| Subscription renewal | WooCommerce Subscriptions creates a renewal order automatically |
| HubSpot deal | A CRM deal syncs to a quote, which converts to an order on acceptance |
Regardless of origin, the entitlement creation pipeline works the same way. Every completed order triggers the provisioning service.
Troubleshooting: entitlement not created
If an order was completed but no entitlement appeared, check these points:
| Check | What to look for |
|---|---|
| Order status | Must be Completed, not Processing or On Hold |
| Product mapping | The product must have _middag_entitlement_class meta set |
| Organization link | The customer's WordPress account must be linked to an organization |
| Provisioning log | Check MIDDAG Account > Logs for errors during provisioning |
| Duplicate check | If a webhook fired twice, the entitlement may already exist -- check by order ID |
| Manual provisioning mode | If the product's provisioning mode is manual, an admin must approve it |
What the admin sees
After provisioning completes:
- WooCommerce order page -- Shows a MIDDAG Account meta box with the created entitlement code(s)
- Organization dashboard -- The new entitlement appears with its code, class, and active status
- Entitlement detail page -- Links back to the originating order for audit
Related pages
- Products and Entitlement Classes -- how the product mapping is configured
- Renewals -- what happens on subscription renewal
- Refunds and Cancellations -- impact of refunds on entitlements
- Payment Status Mapping -- status mapping across WooCommerce, Stripe, and MIDDAG Account
- Orders -- order concept reference
- Purchase and Renewal Flow -- full pipeline walkthrough