@qazuor/qzpay-hono
v1.1.0
Published
Hono middleware and handlers for QZPay billing library
Maintainers
Readme
@qazuor/qzpay-hono
Hono middleware and routes for the QZPay billing library.
Installation
pnpm add @qazuor/qzpay-hono hono zodFeatures
- Billing Routes: REST API for billing operations
- Admin Routes: Administrative endpoints
- Webhook Routes: Webhook handling
- Rate Limiting: Request rate limiting middleware
- Zod Validation: Input validation schemas
- Type Safety: Full TypeScript support
Usage
Basic Setup
import { createBillingRoutes } from '@qazuor/qzpay-hono';
import { Hono } from 'hono';
const app = new Hono();
const billingRoutes = createBillingRoutes({
billing,
prefix: '/billing',
customers: true,
subscriptions: true,
payments: true,
invoices: true,
plans: true
});
app.route('/api', billingRoutes);Rate Limiting
import { createRateLimitMiddleware } from '@qazuor/qzpay-hono';
app.use('/api/*', createRateLimitMiddleware({
windowMs: 60 * 1000, // 1 minute
limit: 100,
keyGenerator: (c) => c.req.header('x-api-key') || 'anonymous'
}));Webhook Routes
import { createWebhookRoutes } from '@qazuor/qzpay-hono';
const webhookRoutes = createWebhookRoutes({
billing,
stripeWebhookSecret: process.env.STRIPE_WEBHOOK_SECRET
});
app.route('/webhooks', webhookRoutes);Admin Routes
import { createAdminRoutes } from '@qazuor/qzpay-hono';
const adminRoutes = createAdminRoutes({
billing,
prefix: '/admin'
});
app.route('/api', adminRoutes);Custom Validation
import { CustomerBaseSchema, z } from '@qazuor/qzpay-hono';
// Extend the base schema
const MyCustomerSchema = CustomerBaseSchema.extend({
companyName: z.string(),
taxId: z.string().regex(/^\d{11}$/)
});API Endpoints
Customers
GET /billing/customers- List customersGET /billing/customers/:id- Get customerPOST /billing/customers- Create customerPATCH /billing/customers/:id- Update customerDELETE /billing/customers/:id- Delete customer
Subscriptions
GET /billing/subscriptions- List subscriptionsGET /billing/subscriptions/:id- Get subscriptionPOST /billing/subscriptions- Create subscriptionPOST /billing/subscriptions/:id/cancel- Cancel subscription
Payments
GET /billing/payments- List paymentsGET /billing/payments/:id- Get paymentPOST /billing/payments- Process paymentPOST /billing/payments/:id/refund- Refund payment
Invoices
GET /billing/invoices- List invoicesGET /billing/invoices/:id- Get invoicePOST /billing/invoices- Create invoicePOST /billing/invoices/:id/void- Void invoice
Plans
GET /billing/plans- List plansGET /billing/plans/:id- Get plan
Validation Schemas
Exported schemas for extension:
CustomerBaseSchemaSubscriptionBaseSchemaPaymentBaseSchemaInvoiceBaseSchema,InvoiceLineSchemaPaginationSchema
Rate Limit Store Interface
For custom stores (e.g., Redis):
import type { QZPayRateLimitStore } from '@qazuor/qzpay-hono';
class RedisRateLimitStore implements QZPayRateLimitStore {
async get(key: string) { ... }
async increment(key: string, windowMs: number) { ... }
async reset(key: string) { ... }
}
app.use('/api/*', createRateLimitMiddleware({
store: new RedisRateLimitStore(redisClient)
}));License
MIT
