Console →
Example Integrations

DocuMind AI Suite (Document AI Integration Example)

DocuMind is a premium, open-source AI document toolkit built with Next.js 15+, Tailwind CSS 4, and the SettleSettle SDK. It serves as a flagship production blueprint for developers looking to implement usage-based billing, multi-rail checkouts (Paystack + Solana), and interactive ad monetization in their SaaS products.

View the Repository on GitHub →

Why is DocuMind unique?#

  • One-Round-Trip Hydration: Boosts UI performance by querying all user metadata, active credit packages, billing rules, and transaction history in one fast network request using settle.billing.bootstrap().
  • Advanced Payment Redirects: Dynamically injects a secure callbackUrl into checkout flows to seamlessly return the user back to the application homepage once their Paystack or Solana checkout completes.
  • Rewarded Ad Incentives: Leverages native sponsored ad fallbacks, letting low-credit users restore their balances instantly by engaging with reward video ads.

Implementation Highlights#

1. Ultra-Fast Dashboard Hydration#

Query all user data, packages, active rules, and balance states at once to avoid multiple waterfall requests:

typescript
// app/api/settle/bootstrap/route.ts
import { settle } from '@/lib/settle'
import { NextResponse } from 'next/server'

export async function GET() {
  const userId = 'demo-user-123'
  try {
    const bootstrapData = await settle.billing.bootstrap(userId)
    return NextResponse.json({ ok: true, data: bootstrapData })
  } catch (error) {
    return NextResponse.json({ ok: false, error: error.message }, { status: 500 })
  }
}

2. Multi-Rail Checkouts with Dynamic Redirection#

Initialize dynamic billing links for Cards (Paystack) or Web3 SPL tokens (Solana), passing a secure return location that takes users back to the dashboard upon successful payment:

typescript
// app/api/settle/topup/route.ts
import { settle } from '@/lib/settle'
import { NextResponse } from 'next/server'

export async function POST(req: Request) {
  const userId = 'demo-user-123'
  try {
    const { packageId, provider } = await req.json()

    // 1. Fetch available packages from bootstrap parameters
    const bootstrap = await settle.billing.bootstrap(userId)
    const selectedPkg = bootstrap.availablePackages.find(p => p.id === packageId)

    if (!selectedPkg) {
      return NextResponse.json({ error: 'Package not found' }, { status: 404 })
    }

    // 2. Construct return redirect callback URL
    const url = new URL(req.url)
    const callbackUrl = `${url.origin}/?success=true`

    // 3. Initialize checkout session
    const paymentSession = await settle.payments.initialize({
      endUserId: userId,
      email: 'user@documind.ai',
      amountKobo: selectedPkg.priceKobo,
      provider: provider === 'solana' ? 'solana' : 'paystack',
      callbackUrl,
      metadata: {
        packageId: selectedPkg.id,
        credits: selectedPkg.credits,
      },
    })

    return NextResponse.json({ ok: true, data: paymentSession })
  } catch (error) {
    return NextResponse.json({ error: error.message }, { status: 500 })
  }
}

3. Rewarded Video Ads Integration#

Let users earn free credits instantly inside your workspace when their wallet balance reaches zero:

typescript
// app/api/settle/ad-reward/route.ts
import { settle } from '@/lib/settle'
import { NextResponse } from 'next/server'

export async function POST() {
  const userId = 'demo-user-123'
  try {
    // Awards dynamic credits configured directly in the cloud dashboard
    const result = await settle.billing.rewardAd(userId)
    return NextResponse.json({ ok: true, data: result })
  } catch (error) {
    return NextResponse.json({ error: error.message }, { status: 500 })
  }
}

Clone & Run Locally#

To spin up DocuMind locally:

  1. Clone the repository and navigate inside:
bash
git clone https://github.com/Ek0m/documind.git
cd documind
  1. Install dependencies:
bash
npm install
  1. Configure your local environment in .env.local:
env
SETTLESETTLE_API_KEY=your_api_key_here
  1. Run the Next.js development server:
bash
npm run dev