Documentation Index
Fetch the complete documentation index at: https://docs.pylonsync.com/llms.txt
Use this file to discover all available pages before exploring further.
@pylonsync/stripe replaces the ~400 lines every Pylon app rewrites when adding Stripe: customer creation, checkout session minting, billing portal, webhook signature verification, plan derivation, subscription state. One stripe({plans, hooks}) block returns a manifest fragment + handler factories.
Install
Config
Wrapper files
Pylon loads function handlers by file. Create one-line wrappers underfunctions/:
billing.handlers (cancelSubscription, restoreSubscription, stripeWebhook, plus the _pylonStripe* internals).
Required env
| Variable | Purpose |
|---|---|
STRIPE_SECRET_KEY | API requests (set per Pylon Cloud project’s Secrets UI). |
STRIPE_WEBHOOK_SECRET | Signature verification on /api/webhooks/stripeWebhook. |
PYLON_PUBLIC_URL | Auto-set by Pylon Cloud. Drives URL allowlist for success_url/cancel_url. |
Webhook endpoint
Configure in Stripe Dashboard → Developers → Webhooks → Add endpoint:whsec_...) → set as STRIPE_WEBHOOK_SECRET on your Pylon machine.
Lifecycle hooks
| Hook | Fires |
|---|---|
onCustomerCreate | After a Stripe customer is created (first checkout). |
onSubscriptionActivate | customer.subscription.created event. |
onSubscriptionUpdate | customer.subscription.updated event. |
onSubscriptionCancel | customer.subscription.deleted event. |
onInvoice | Any invoice event. |
onEvent | Catch-all for unhandled Stripe events. |
getCheckoutSessionParams | Inject tax/promo/idempotency-key params into checkout creation. |
RBAC
TheauthorizeReference hook gates subscription mutations. Defaults:
referenceType: "org"— caller must be the org’s owner or admin.referenceType: "user"— caller must be the user themselves.referenceType: "custom"— you must supply your ownauthorizeReference.
Security
- Constant-time signature verification with 5-minute replay window and multi-secret rotation (supports overlap window during secret rotation).
- URL allowlist auto-derived from
PYLON_PUBLIC_URL+PYLON_CORS_ORIGIN— no hardcoded host strings. - Three-signal plan resolver (lookup_key → nickname → priceId match) — Stripe occasionally elides the first two on webhook payloads.
- Double-trial guard — prior
Subscriptionrows for the same reference disable the trial period regardless of plan config. - Idempotent webhook upsert via
stripeSubscriptionIdlookup, so Stripe retries produce the same state.