Skip to main content
This tutorial demonstrates building a revenue-generating web application through Lovable (AI-driven development platform) paired with Paygentic for consumption-based billing. Our example: a bulk QR code tool offering limited free access with paid premium features.
Programming expertise isn’t necessary. AI handles the technical implementation while you focus on the business logic.

Initial Setup with Lovable

1

Register on Lovable

Navigate to lovable.dev and register. Select “New Project” to begin development.
2

Select starting point

Choose a foundation template or blank canvas. Label your application (example: QR Code Tool).

Developing Core Features

1

Sketch the Interface

Begin by drafting a visual layout. This guides the AI’s understanding of your intended workflow—eliminating ambiguity.

Interface mockup via Excalidraw

2

Provide Initial Instructions

Feed your design to the AI alongside functional requirements.
Create a batch QR generator following the provided mockup:

- Input field accepts multiple URLs (comma-delimited)
- Generate button triggers processing
- Right panel displays preview grid with sample QRs
- Batch download exports all as PNG files (named sequentially: code1.png, code2.png)
- Apply contemporary Tailwind aesthetics with cohesive color palette
3

Iterate on Results

Test the generated application. Report issues to AI for resolution.

Initial build - interface successful, download functionality required adjustment

Implementing Authentication

Enable user accounts through Lovable’s Supabase integration with minimal configuration:
integrate user authentication into the application
Lovable handles Supabase connection and configuration automatically.

Revenue Integration via Paygentic

Paygentic Configuration

1

Establish merchant account

Visit paygentic.io for registration. Select Merchant role at signup.
2

Configure your offering

Access the merchant portal to establish your product catalog.
3

Establish usage metrics

Define measurable units—for instance: QR generations per batch
4

Configure pricing structure

  • Establish consumption-based pricing
  • Define unit costs (example: $0.00001 per QR)

Application Integration Strategy

After configuring Paygentic’s backend, implement billing capabilities within Lovable through programmatic customer management.
1

Configure API Credentials

Instruct Lovable to establish environment settings:
  • PAYGENTIC_API_KEY: Authentication token (Settings → API Keys)
  • PAYGENTIC_MERCHANT_ID: Organization identifier (Settings → Organization)
  • PAYGENTIC_BILLABLE_METRIC_ID: Metric identifier (product configuration)
  • PAYGENTIC_PLAN_ID: Pricing plan reference (product configuration)
Configure these Paygentic integration variables:
PAYGENTIC_API_KEY, PAYGENTIC_MERCHANT_ID, PAYGENTIC_BILLABLE_METRIC_ID, PAYGENTIC_PLAN_ID
2

Extend User Data Model

Augment Supabase schema for billing data:
Extend the user profile schema with billing fields:
- paygentic_customer_id (text): Customer reference
- subscription_reference (text): Active plan identifier
- free_quota (number): Complimentary tier allowance (default: 2)
- period_consumption (number): Current billing cycle usage
Lovable executes the database migration automatically.
3

Implement Customer Registration

Direct Lovable to handle customer provisioning:
Implement Paygentic customer management for new registrations:

1. On signup, provision a managed customer via API
2. Persist the customer identifier in profiles
3. Initialize free tier consumption tracking

API endpoint: POST https://api.paygentic.io/v0/customers

Payload structure:
- merchantId (environment variable)
- consumer details (name, email, available contact data)

Persist the response's customerId to user profile.
4

Build Subscription Workflow

Handle premium tier activation:
Implement subscription when free quota exhausted (>2 QR generations):

1. Verify existing subscription_reference
2. If absent, provision subscription via:
   POST https://api.paygentic.io/v0/subscriptions

   Payload:
   - customerId (profile data)
   - planId (environment)
   - name: "QR Generator Premium"
   - startedAt: current timestamp
   - prefundAmount: "5" (initial balance)

3. Handle payment.checkoutUrl if present (payment required)
4. Persist subscription_reference post-payment
5. Enable unlimited generation for subscribers
5

Payment Flow Implementation

Create payment completion handler:
Build payment processor that:

1. Detects payment requirement (payment.checkoutUrl present)
2. Displays checkout in modal/tab
3. Monitors completion events (postMessage for iframes)
4. Activates subscription on success
5. Handles payment failures gracefully

Iframe configuration: sandbox="allow-scripts allow-same-origin allow-forms allow-popups"

Consumption Tracking Implementation

1

Usage Event Submission

Record billable actions:
Post-generation for premium users:

1. Submit consumption data:
   POST https://api.paygentic.io/v0/usage

   Payload:
   - customerId (profile)
   - merchantId (environment)
   - timestamp: ISO format
   - properties: [{
       billableMetricId: (environment),
       quantity: batch size
     }]
   - idempotencyKey: session-unique identifier
   - metadata: { batchSize, timestamp }

2. Display results only after successful billing
3. Handle billing failures with user feedback
4. Free tier: increment local counter only
2

Usage Analytics Interface

Provide consumption visibility:
Build usage monitoring interface:

1. Free tier display:
   - Progress indicator: X/2 monthly allowance
   - Premium upgrade CTA

2. Subscriber display:
   - Cumulative generation count
   - Portal access (POST /v0/subscriptions/{id}/portal)
   - Billing cycle details
   - Subscription management link
3

Portal Integration

Enable self-service billing management:
Implement billing portal launcher:

1. Generate access URL: POST https://api.paygentic.io/v0/subscriptions/{subscriptionId}/portal
2. Extract portal URL from response
3. Launch in tab/iframe
4. Features available:
   - Invoice history
   - Payment method updates
   - Detailed consumption logs
   - Receipt downloads

Place "Billing Management" action in account settings.

End-to-End User Journey

The complete implementation flow:
1

Registration Flow

  1. Account creation through Supabase
  2. Automatic Paygentic customer provisioning
  3. Monthly allowance: 2 free generations
  4. Local tracking for complimentary tier
2

Premium Conversion

  1. Quota exceeded (3+ QR attempts)
  2. Subscription provisioning triggered
  3. Payment collection initiated
  4. Subscription activated post-payment
  5. Unrestricted generation unlocked
3

Continuous Operations

  1. Generation triggers billing event
  2. Instant charging for subscribers
  3. Portal access for billing transparency
  4. Recurring monthly processing

Validation Process

1

Complimentary Tier Verification

  1. Create fresh account
  2. Process 2 QR batches (successful)
  3. Attempt third batch (upgrade prompt)
2

Premium Tier Validation

  1. Initiate upgrade flow
  2. Complete payment process
  3. Confirm subscription storage
  4. Test unlimited generation
  5. Verify merchant revenue dashboard
3

Dashboard Monitoring

Examine both perspectives:

Enhanced Capabilities

Pre-Authorization via Entitlements

Guarantee payment before resource consumption:
For large batches (10+ QRs), secure payment first:

1. POST https://api.paygentic.io/v0/entitlements
   - customerId, merchantId, billableMetricId
   - quantity: anticipated generation count

2. Capture entitlementId from response
3. Reference entitlementId in usage submission
4. Guarantees payment for batch processing

Intelligent Consumption Controls

Implement protective measures:
Implement consumption safeguards:
1. Alert at 80% historical average
2. Mandate entitlements for 100+ QR batches
3. Display cost estimates pre-generation
4. Enforce daily generation caps

Summary

Success! You’ve deployed a monetized QR generator combining Lovable’s rapid development with Paygentic’s billing APIs.
Your application delivers:
  • Frictionless onboarding via automated provisioning
  • Tiered monetization combining free and paid tiers
  • Complete transparency with customer portals
  • Dependable revenue through subscription infrastructure
This pattern extends to any consumption-based business:
  • Computing services (operations, processing cycles)
  • Media generation (graphics, audio, video)
  • Data operations (transformations, analytics)
  • Communications (transmissions, connections)
Lovable accelerates development while Paygentic handles complex billing—ship revenue-generating applications rapidly.