.do
Monetize

Monetize

Monetize your Business-as-Code through services.do (AI-delivered services) and payments.do (Stripe Connect)

Monetize your Business-as-Code through services.do (AI-delivered Services-as-Software) and payments.do (integrated Stripe Connect payments).

Overview

The Monetize phase transforms your Business-as-Code into revenue-generating operations. Using the .do platform's built-in monetization primitives, you can sell AI-delivered services, implement flexible pricing models, and process payments seamlessly.

This phase enables:

  • Services-as-Software: Monetize AI capabilities as services
  • Integrated Payments: Built-in Stripe Connect via payments.do
  • Flexible Pricing: Usage-based, subscription, and hybrid models
  • Revenue Automation: Automated billing, invoicing, and collections
  • Financial Operations: Revenue recognition, reporting, and analytics

Core Monetization Primitives

services.do: AI-Delivered Services

Monetize AI capabilities as Services-as-Software:

// Define monetizable service
export const ContentGenerationService = $.service({
  name: 'AI Content Generation',
  description: 'Generate high-quality content with AI',
  domain: 'services.do',

  // Pricing configuration
  pricing: {
    model: 'usage-based',
    unit: 'word',
    price: 0.01, // $0.01 per word
    currency: 'USD',
    tiers: [
      { upTo: 10000, price: 0.01 }, // $0.01/word up to 10k words
      { upTo: 100000, price: 0.008 }, // $0.008/word for 10k-100k
      { upTo: null, price: 0.005 }, // $0.005/word over 100k
    ],
  },

  // Service methods (AI-powered)
  methods: {
    generate: async ({ prompt, length, style }, context) => {
      // Track usage for billing
      const usage = {
        userId: context.userId,
        service: 'content-generation',
        units: length,
        timestamp: new Date(),
      }

      // Generate content
      const content = await $.ai.generate({
        prompt,
        maxTokens: length,
        style,
      })

      // Record billable usage
      await send($.Billing.recordUsage, usage)

      // Calculate cost
      const cost = calculateTieredCost(length, ContentGenerationService.pricing.tiers)

      return {
        content,
        usage: {
          words: length,
          cost,
        },
      }
    },
  },

  // Service events for revenue tracking
  events: {
    'service.used': {
      emit: async ({ userId, units, cost }) => {
        await send($.Revenue.track, {
          service: 'content-generation',
          userId,
          units,
          revenue: cost,
        })
      },
    },
  },
})

// Use the service
const result = await ContentGenerationService.generate({
  prompt: 'Write a blog post about AI',
  length: 1000,
  style: 'professional',
})

payments.do: Integrated Stripe Connect

Process payments with built-in Stripe Connect:

// Initialize payment integration
const payments = $.payments({
  provider: 'stripe',
  mode: 'connect', // Stripe Connect for marketplace
  features: {
    subscriptions: true,
    usage_based: true,
    invoicing: true,
  },
})

// Create customer
on($.User.signup, async (user, $) => {
  const customer = await payments.customer.create({
    email: user.email,
    name: user.name,
    metadata: { userId: user.id },
  })

  await db.update($.User, user.id, {
    stripeCustomerId: customer.id,
  })
})

// Process payment
on($.User.purchases.Service, async (purchase, $) => {
  const payment = await payments.charge({
    customer: purchase.user.stripeCustomerId,
    amount: purchase.total,
    currency: 'usd',
    description: `${purchase.service} - ${purchase.plan}`,
    metadata: {
      userId: purchase.userId,
      serviceId: purchase.serviceId,
    },
  })

  if (payment.status === 'succeeded') {
    await send($.Purchase.completed, {
      ...purchase,
      paymentId: payment.id,
    })
  } else {
    await send($.Purchase.failed, {
      ...purchase,
      error: payment.error,
    })
  }
})

Pricing Models

Usage-Based Pricing

Charge based on consumption:

// Define usage-based service
const AIAnalyticsService = $.service({
  name: 'AI Analytics',
  pricing: {
    model: 'usage-based',
    metrics: {
      api_calls: {
        price: 0.001, // $0.001 per call
        unit: 'call',
      },
      data_processed: {
        price: 0.10, // $0.10 per GB
        unit: 'gb',
      },
    },
  },
})

// Track usage
on($.User.calls.API, async (call, $) => {
  await send($.Billing.recordUsage, {
    userId: call.userId,
    service: 'ai-analytics',
    metric: 'api_calls',
    quantity: 1,
    timestamp: new Date(),
  })
})

// Calculate monthly bill
on($.Schedule.monthly, async () => {
  const users = await db.list($.User, {
    where: { plan: 'usage-based' },
  })

  for (const user of users) {
    const usage = await $.Billing.getUsage({
      userId: user.id,
      period: 'last-month',
    })

    const invoice = await payments.invoice.create({
      customer: user.stripeCustomerId,
      items: usage.map((u) => ({
        description: `${u.service} - ${u.metric}`,
        quantity: u.quantity,
        unit_amount: u.price,
      })),
    })

    await payments.invoice.send(invoice.id)
  }
})

Subscription Pricing

Recurring revenue with subscriptions:

// Define subscription plans
const subscriptionPlans = {
  starter: {
    name: 'Starter',
    price: 29,
    interval: 'month',
    features: {
      api_calls: 10000,
      data_storage: '10GB',
      support: 'email',
    },
  },
  professional: {
    name: 'Professional',
    price: 99,
    interval: 'month',
    features: {
      api_calls: 100000,
      data_storage: '100GB',
      support: 'priority',
    },
  },
  enterprise: {
    name: 'Enterprise',
    price: 499,
    interval: 'month',
    features: {
      api_calls: 'unlimited',
      data_storage: '1TB',
      support: '24/7',
    },
  },
}

// Handle subscription
on($.User.subscribes, async (subscription, $) => {
  const plan = subscriptionPlans[subscription.plan]

  const stripeSubscription = await payments.subscription.create({
    customer: subscription.user.stripeCustomerId,
    items: [
      {
        price_data: {
          currency: 'usd',
          product: plan.name,
          recurring: { interval: plan.interval },
          unit_amount: plan.price * 100, // Cents
        },
      },
    ],
    metadata: {
      userId: subscription.userId,
      plan: subscription.plan,
    },
  })

  await db.create($.Subscription, {
    userId: subscription.userId,
    plan: subscription.plan,
    stripeSubscriptionId: stripeSubscription.id,
    status: 'active',
    currentPeriodStart: stripeSubscription.current_period_start,
    currentPeriodEnd: stripeSubscription.current_period_end,
  })
})

// Handle subscription events from Stripe
on($.Webhook.stripe.subscription_updated, async (event, $) => {
  const subscription = await db.findOne($.Subscription, {
    where: { stripeSubscriptionId: event.subscription.id },
  })

  await db.update($.Subscription, subscription.id, {
    status: event.subscription.status,
    currentPeriodStart: event.subscription.current_period_start,
    currentPeriodEnd: event.subscription.current_period_end,
  })
})

Hybrid Pricing

Combine subscription + usage:

// Hybrid pricing model
const HybridService = $.service({
  name: 'AI Platform',
  pricing: {
    model: 'hybrid',
    base: {
      // Base subscription
      price: 49,
      interval: 'month',
      includes: {
        api_calls: 50000,
        storage: '50GB',
      },
    },
    overages: {
      // Usage beyond base
      api_calls: {
        price: 0.0005,
        unit: 'call',
      },
      storage: {
        price: 0.15,
        unit: 'gb',
      },
    },
  },
})

// Calculate hybrid bill
on($.Billing.calculate, async (user, period) => {
  const subscription = await db.get($.Subscription, {
    where: { userId: user.id },
  })

  const usage = await $.Billing.getUsage({
    userId: user.id,
    period,
  })

  // Base subscription fee
  let total = subscription.plan.base.price

  // Calculate overages
  for (const [metric, quantity] of Object.entries(usage)) {
    const included = subscription.plan.base.includes[metric]
    const overage = Math.max(0, quantity - included)

    if (overage > 0) {
      const price = subscription.plan.overages[metric].price
      total += overage * price
    }
  }

  return { base: subscription.plan.base.price, overages: total - subscription.plan.base.price, total }
})

Revenue Operations

Automated Billing

Automate invoicing and collections:

// Automated billing cycle
on($.Schedule.monthly, async () => {
  const customers = await db.list($.User, {
    where: { status: 'active' },
  })

  for (const customer of customers) {
    try {
      // Calculate charges
      const charges = await calculateMonthlyCharges(customer.id)

      // Create invoice
      const invoice = await payments.invoice.create({
        customer: customer.stripeCustomerId,
        auto_advance: true, // Auto-finalize
        collection_method: 'charge_automatically',
        items: charges,
      })

      // Invoice automatically attempts payment
      await send($.Billing.invoiceCreated, {
        userId: customer.id,
        invoiceId: invoice.id,
        amount: invoice.total,
      })
    } catch (error) {
      await send($.Alert.send, {
        type: 'billing-error',
        userId: customer.id,
        error: error.message,
      })
    }
  }
})

// Handle payment failures
on($.Webhook.stripe.invoice_payment_failed, async (event, $) => {
  const invoice = event.invoice

  // Retry logic
  const retries = invoice.metadata.retries || 0
  if (retries < 3) {
    // Attempt retry with backoff
    await $.Schedule.create({
      trigger: `+${Math.pow(2, retries)} days`,
      action: payments.invoice.pay,
      data: { invoiceId: invoice.id },
    })

    await payments.invoice.update(invoice.id, {
      metadata: { retries: retries + 1 },
    })
  } else {
    // Suspend service
    await send($.Subscription.suspend, {
      userId: invoice.metadata.userId,
      reason: 'payment-failed',
    })

    // Notify customer
    await send($.Email.send, {
      to: invoice.customer_email,
      template: 'payment-failed-final',
      invoice,
    })
  }
})

Revenue Analytics

Track and analyze revenue:

// Revenue tracking
on($.Payment.succeeded, async (payment, $) => {
  await db.create($.Revenue, {
    userId: payment.userId,
    amount: payment.amount,
    currency: payment.currency,
    service: payment.service,
    plan: payment.plan,
    type: payment.type, // subscription, usage, one-time
    timestamp: new Date(),
    metadata: payment.metadata,
  })

  // Update metrics
  await $.Metrics.increment('mrr', payment.mrr)
  await $.Metrics.increment('arr', payment.mrr * 12)
})

// Revenue dashboard
on($.Schedule.daily, async () => {
  const metrics = await calculateRevenueMetrics()

  await send($.Dashboard.update, {
    dashboard: 'revenue',
    metrics: {
      mrr: metrics.mrr,
      arr: metrics.arr,
      growth_rate: metrics.growth,
      churn: metrics.churn,
      ltv: metrics.ltv,
      cac: metrics.cac,
      ltv_cac_ratio: metrics.ltv / metrics.cac,
    },
  })
})

// Revenue forecasting
const forecastRevenue = async (months: number) => {
  const historical = await db.list($.Revenue, {
    where: {
      timestamp: { gte: subtractMonths(new Date(), 12) },
    },
  })

  const forecast = await $.ai.forecast({
    metric: 'revenue',
    historical,
    periods: months,
    model: 'time-series',
  })

  return forecast
}

Services-as-Software Marketplace

Build a marketplace for AI services:

// Service marketplace
const marketplace = {
  // List available services
  listServices: async () => {
    return await db.list($.Service, {
      where: { published: true },
      include: {
        provider: true,
        pricing: true,
        reviews: true,
      },
    })
  },

  // Purchase service
  purchaseService: async ({ userId, serviceId, plan }) => {
    const service = await db.get($.Service, serviceId)
    const user = await db.get($.User, userId)

    // Process payment via payments.do
    const payment = await payments.charge({
      customer: user.stripeCustomerId,
      amount: service.pricing[plan].price,
      currency: 'usd',
      description: `${service.name} - ${plan}`,
    })

    if (payment.status === 'succeeded') {
      // Grant access
      await db.create($.ServiceAccess, {
        userId,
        serviceId,
        plan,
        status: 'active',
        startDate: new Date(),
      })

      // Revenue split (Stripe Connect)
      await payments.transfer({
        destination: service.provider.stripeAccountId,
        amount: payment.amount * 0.85, // 85% to provider, 15% platform fee
        currency: 'usd',
      })

      return { success: true, payment }
    }
  },
}

Best Practices

Do's

  1. Start with services.do - Monetize AI capabilities as services
  2. Use payments.do - Built-in Stripe Connect integration
  3. Implement usage tracking - Accurate billing requires tracking
  4. Offer flexible pricing - Usage, subscription, and hybrid
  5. Automate billing - Reduce manual intervention
  6. Track revenue metrics - MRR, ARR, churn, LTV:CAC
  7. Provide clear pricing - Transparency builds trust

Don'ts

  1. Don't skip usage tracking - Lost revenue from unbilled usage
  2. Don't ignore failed payments - Automated retry and dunning
  3. Don't overcomplicate pricing - Simple pricing converts better
  4. Don't forget taxes - Use Stripe Tax or similar
  5. Don't skip invoicing - Professional invoices required
  6. Don't ignore churn - Monitor and reduce churn

CLI Tools

# services.do commands
do service create --name "AI Content" --pricing usage

# payments.do commands
do payment create --customer cus_123 --amount 99
do subscription create --customer cus_123 --plan pro

# Revenue analytics
do revenue report --period 30d
do revenue forecast --months 12

Next Steps


Monetization Tip: The best monetization is invisible to users and automatic for you. Use services.do and payments.do to monetize AI seamlessly.