Skip to content

Quick Start

Quick Start

This guide will help you set up a basic billing integration with QZPay using Stripe.

Choose Your Setup Method

The CLI provides the fastest way to get started:

  1. Install the CLI

    Terminal window
    pnpm add -D @qazuor/qzpay-cli
  2. Initialize your project

    Terminal window
    pnpm qzpay init

    This interactive wizard will:

    • Ask which payment provider to use (Stripe, MercadoPago)
    • Ask which storage adapter to use (Drizzle)
    • Ask which framework to integrate with (Hono, NestJS)
    • Create the configuration file
    • Generate service files
  3. Configure environment variables

    Copy the generated .env.example to .env:

    Terminal window
    cp .env.example .env

    Fill in your actual credentials:

    Terminal window
    DATABASE_URL=postgresql://user:pass@localhost:5432/billing
    STRIPE_SECRET_KEY=sk_test_xxx
    STRIPE_WEBHOOK_SECRET=whsec_xxx
  4. Run database migrations

    Terminal window
    pnpm drizzle-kit push
  5. Create plans in Stripe

    Run the generated plans script:

    Terminal window
    npx tsx plans.ts

Your QZPay setup is ready. The CLI creates a qzpay.config.ts file you can import in your application.

Full Example

Here’s a complete example with Hono:

import { Hono } from 'hono';
import { createQZPayBilling } from '@qazuor/qzpay-core';
import { createQZPayStripeAdapter } from '@qazuor/qzpay-stripe';
import { createQZPayDrizzleAdapter } from '@qazuor/qzpay-drizzle';
import {
createQZPayMiddleware,
createBillingRoutes,
createWebhookRouter
} from '@qazuor/qzpay-hono';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
// Database setup
const sql = postgres(process.env.DATABASE_URL!);
const db = drizzle(sql);
// Create adapters
const storage = createQZPayDrizzleAdapter(db);
const stripeAdapter = createQZPayStripeAdapter({
secretKey: process.env.STRIPE_SECRET_KEY!,
webhookSecret: process.env.STRIPE_WEBHOOK_SECRET!
});
// Billing setup
const billing = createQZPayBilling({
storage,
paymentAdapter: stripeAdapter
});
// Event handlers
billing.on('subscription.created', async (event) => {
console.log('New subscription:', event.data.id);
});
billing.on('payment.succeeded', async (event) => {
console.log('Payment received:', event.data.amount);
});
// App setup
const app = new Hono();
// Add QZPay middleware
app.use('*', createQZPayMiddleware({ billing }));
// Mount billing routes
const billingRoutes = createBillingRoutes({ billing });
app.route('/api/billing', billingRoutes);
// Mount webhook handler
const webhookRouter = createWebhookRouter({
billing,
paymentAdapter: stripeAdapter
});
app.route('/webhooks/stripe', webhookRouter);
export default app;

Next Steps