Skip to content

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:

FieldValue
CodeAuto-generated: {CLASS}-{YEAR}{MONTH}{SEQ:4d} (e.g., PLG-2026050042)
ClassFrom the product mapping
Statusactive
OrganizationResolved from the customer's WordPress account
Order referenceWooCommerce order ID
Start datePayment confirmation timestamp
End dateCalculated from billing period (subscriptions) or set by product config

5. Downstream resources are provisioned

Based on the entitlement class, additional resources are created:

ClassDownstream resources created
PLGLicense key (with activation limit), download access
ENVEnvironment instance (managed hosting)
SVCService record, Contract, initial Credit Balance
ORDOrder link only (general-purpose entitlement)
AFLAffiliate record in SolidAffiliate
EDUCourse/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:

OriginHow it works
Quote acceptedCustomer accepts a quote in the portal; a WC order is created automatically
Admin-createdAdmin creates an order directly in WooCommerce
Subscription renewalWooCommerce Subscriptions creates a renewal order automatically
HubSpot dealA 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:

CheckWhat to look for
Order statusMust be Completed, not Processing or On Hold
Product mappingThe product must have _middag_entitlement_class meta set
Organization linkThe customer's WordPress account must be linked to an organization
Provisioning logCheck MIDDAG Account > Logs for errors during provisioning
Duplicate checkIf a webhook fired twice, the entitlement may already exist -- check by order ID
Manual provisioning modeIf 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