Skip to content

Purchase and Renewal Flow

This page explains the complete purchase pipeline -- from quote to entitlement -- and how renewals, auto-renewals, and payment recovery work.

The purchase pipeline

Step by step

1. Quote creation

Quotes originate from two sources:

  • HubSpot CRM -- The sales team creates a quote in HubSpot. A webhook sends it to MIDDAG Account, which creates a local record with line items, pricing, and validity dates.
  • Admin panel -- The admin creates a quote directly in the WordPress admin, selecting the Organization, billing entity (BR or US), line items, and terms.

Quotes start in draft status. When sent to the customer, they transition to sent.

2. Customer review

The customer sees pending quotes in the portal. Opening a quote transitions it from sent to viewed (tracked with a timestamp). The customer can:

  • Review line items and pricing
  • Add comments for negotiation
  • Accept the quote (irreversible)
  • Reject the quote (requires a reason)

Quotes have a configurable validity period (default: 30 days). Expired quotes cannot be accepted but can be re-sent by the admin with new validity dates.

3. Acceptance and order creation

When the customer accepts a quote:

  1. The quote status transitions to accepted.
  2. The system automatically creates a WooCommerce order from the quote's line items.
  3. The order is linked to the quote via metadata.
  4. The status is synced back to HubSpot.
  5. The customer is directed to the payment step.

4. Payment

Payment methods depend on the billing entity:

EntityAvailable methods
MIDDAG BRCredit card (Stripe), Pix, Boleto (Banco Inter)
MIDDAG GLOBALCredit card (Stripe)

The customer selects a payment method in the portal:

  • Pix: QR code generated, payment confirmed via Banco Inter webhook (30-minute timeout).
  • Boleto: Generated with due date, payment confirmed via Banco Inter webhook.
  • Credit card: Stripe Elements form, payment confirmed via Stripe webhook.

5. Entitlement provisioning

When payment is confirmed:

  1. The WooCommerce order status updates to paid.
  2. The quote transitions to paid.
  3. The system analyzes the order's line items to determine the entitlement class (PLG, ENV, SVC, ORD, EDU).
  4. An entitlement is created automatically with a unique code.
  5. Downstream resources are provisioned based on the class.
  6. The quote transitions to fulfilled.
  7. The customer is notified with the entitlement code.

See Entitlement Activation for details on what happens after the entitlement is created.

6. Cascade effects

Payment confirmation triggers additional downstream actions:

  • Invoice -- Stripe generates an invoice, synced via webhook.
  • NFSe -- For BR transactions, a tax invoice is issued automatically via ISSNet (see Billing and Finance).
  • HubSpot -- The deal/quote status is updated in the originating portal.
  • Jira -- If configured, a Jira issue is created for order fulfillment.

Renewal flow

Auto-renewal

For subscription-based entitlements, renewal is handled by WooCommerce Subscriptions and Stripe:

  1. The renewal policy determines when to attempt renewal (default: 7 days before expiration).
  2. The system charges the stored payment method via Stripe.
  3. On success, the entitlement's end date extends and remains active.
  4. The customer is notified of the successful renewal.

Manual renewal

For non-subscription entitlements or when auto-renewal is disabled:

  1. The system sends renewal reminders at configurable intervals (default: 30, 7, and 1 day before expiration).
  2. The customer can initiate renewal from the portal, which starts a new payment flow.
  3. On payment, the entitlement is renewed with updated dates.

Grace period

When an entitlement expires without renewal:

  1. The entitlement transitions to expired.
  2. A configurable grace period begins (governed by the RenewalPolicy).
  3. During the grace period, the customer can still renew.
  4. If the grace period ends without renewal, the system transitions the entitlement toward cancellation (see Suspension and Recovery).

Payment recovery

When a renewal payment fails:

  1. The system retries according to Stripe's retry schedule.
  2. If retries exhaust, the PaymentRecoveryPolicy determines what happens next.
  3. By default, the entitlement is suspended after retries are exhausted.
  4. The customer is notified at each step.
  5. If payment is recovered, the entitlement returns to active automatically.

See Suspension and Recovery for the full suspension and escalation timeline.