@billsdk/stripe
v1.2.0
Published
Stripe payment adapter for BillSDK
Downloads
142
Maintainers
Readme
@billsdk/stripe
Stripe payment adapter for BillSDK.
Installation
pnpm add @billsdk/stripe stripeUsage
import { billsdk } from "billsdk";
import { drizzleAdapter } from "@billsdk/drizzle";
import { stripePayment } from "@billsdk/stripe";
export const billing = billsdk({
database: drizzleAdapter(db, { schema, provider: "pg" }),
payment: stripePayment({
secretKey: process.env.STRIPE_SECRET_KEY!,
webhookSecret: process.env.STRIPE_WEBHOOK_SECRET!,
}),
});Configuration
interface StripePaymentOptions {
// Stripe secret key
secretKey: string;
// Webhook secret for signature verification
webhookSecret: string;
// API version (optional)
apiVersion?: string;
}Webhook Setup
Configure your Stripe webhook to point to your BillSDK webhook endpoint:
https://your-app.com/api/billing/webhookEvents Handled
checkout.session.completed- Activates subscription after paymentcustomer.subscription.updated- Updates subscription statuscustomer.subscription.deleted- Handles cancellationinvoice.payment_failed- Logs payment failures
Flow
- Call
billing.api.createSubscription()to create a subscription and get checkout URL - Redirect user to Stripe Checkout
- User completes payment
- Stripe sends webhook to
/api/billing/webhook - BillSDK activates the subscription
// Create subscription
const { subscription, checkoutUrl } = await billing.api.createSubscription({
customerId: "user_123",
planCode: "pro",
successUrl: "https://app.com/success",
cancelUrl: "https://app.com/pricing",
});
// Redirect to checkout
redirect(checkoutUrl);