@aios-inc/cashier-express
v1.8.2
Published
Express middleware and error handler for Cashier: unified subscription billing with typed req.cashier and HTTP error responses.
Readme
@aios-inc/cashier-express
Express middleware and error handler for Cashier, unified subscription billing for Node.js and TypeScript. Get a typed req.cashier on every request and answer billing errors with the right HTTP status. Supports Express 4 and 5.
Install
npm install @aios-inc/cashier @aios-inc/cashier-express stripe recurlyUsage
import express from 'express';
import { CashierProvider, createCashier } from '@aios-inc/cashier';
import {
cashierErrorHandler,
cashierMiddleware,
} from '@aios-inc/cashier-express';
const cashier = createCashier({
default: CashierProvider.Stripe,
providers: { stripe: { apiKey: process.env.STRIPE_SECRET_KEY! } },
});
const app = express();
app.use(cashierMiddleware(cashier));
app.get('/invoices/:id', async (req, res) => {
res.json(await req.cashier.use().invoices.get(req.params.id));
});
app.use(cashierErrorHandler());A missing invoice then answers 404 { "code": "not_found", "message": "..." }, a declined card 402 with the decline code, and so on. Errors that are not Cashier errors go to your next error handler.
Documentation
- Express guide: the middleware, the error handler, Express 4 and testing.
- API reference: customers, invoices, payments, products, prices and subscriptions.
- Errors: every error class and the HTTP responses.
License
MIT © AIOS
