Skip to content

Payment Namespace

The payment namespace provides payment processing providers.

ts
import { payment } from "nevr-env/plugins";

Providers

ProviderDescription
payment.stripe()Stripe - Payment processing platform

Stripe

Full-featured Stripe integration with webhooks, Connect, and checkout support.

Basic Usage

ts
import { createEnv } from "nevr-env";
import { payment } from "nevr-env/plugins";

const env = createEnv({
  plugins: [payment.stripe()],
  runtimeEnv: process.env,
});

// env.STRIPE_SECRET_KEY
// env.STRIPE_PUBLISHABLE_KEY

Options

OptionTypeDefaultDescription
webhookbooleanfalseInclude webhook secret
testModebooleantrue in devAllow test mode keys
customerPortalbooleanfalseInclude customer portal config
connectbooleanfalseInclude Stripe Connect config
checkoutbooleanfalseInclude checkout URLs
pricingTablebooleanfalseInclude pricing table ID
pricingbooleanfalseInclude price IDs
variableNamesobject-Custom variable names
extendobject-Extend schema with custom fields

Environment Variables by Option

Default (no options)

VariableRequiredFormatDescription
STRIPE_SECRET_KEYsk_test_* or sk_live_*API secret key
STRIPE_PUBLISHABLE_KEYpk_test_* or pk_live_*Publishable key for client

Key Prefixes

  • Test mode: sk_test_, pk_test_, rk_test_ (restricted)
  • Live mode: sk_live_, pk_live_, rk_live_ (restricted)

webhook: true

VariableRequiredFormatDescription
STRIPE_WEBHOOK_SECRETwhsec_*Webhook signing secret

customerPortal: true

VariableRequiredFormatDescription
STRIPE_CUSTOMER_PORTAL_CONFIG_IDbpc_*Customer portal configuration ID

connect: true

VariableRequiredFormatDescription
STRIPE_CONNECT_CLIENT_IDca_*Connect application client ID

checkout: true

VariableRequiredFormatDescription
STRIPE_SUCCESS_URLURLCheckout success redirect URL
STRIPE_CANCEL_URLURLCheckout cancel redirect URL

pricingTable: true

VariableRequiredFormatDescription
STRIPE_PRICING_TABLE_IDprctbl_*Embedded pricing table ID

pricing: true

VariableRequiredFormatDescription
STRIPE_MONTHLY_PRICE_IDprice_*Monthly subscription price ID
STRIPE_YEARLY_PRICE_IDprice_*Yearly subscription price ID

Key Validation

Stripe plugin validates key formats:

Key TypeTest ModeLive Mode
Secret Keysk_test_*sk_live_*
Publishable Keypk_test_*pk_live_*
Restricted Keyrk_test_*rk_live_*
Webhook Secretwhsec_*whsec_*
Connect Clientca_*ca_*
Portal Configbpc_*bpc_*
Price IDprice_*price_*

Examples

ts
// SaaS with subscriptions
payment.stripe({
  webhook: true,
  pricing: true,
  customerPortal: true,
})

// Marketplace with Connect
payment.stripe({
  webhook: true,
  connect: true,
})

// E-commerce checkout
payment.stripe({
  checkout: true,
  webhook: true,
})

// Production-only (no test keys)
payment.stripe({
  testMode: false,
  webhook: true,
})

// Custom product/tax configuration
payment.stripe({
  extend: {
    STRIPE_PRODUCT_ID: z.string().startsWith("prod_"),
    STRIPE_TAX_RATE_ID: z.string().startsWith("txr_").optional(),
    STRIPE_COUPON_ID: z.string().optional(),
  }
})

Integration Example

ts
// env.ts
import { createEnv } from "nevr-env";
import { payment } from "nevr-env/plugins";

export const env = createEnv({
  plugins: [
    payment.stripe({
      webhook: true,
      pricing: true,
    }),
  ],
  runtimeEnv: process.env,
});

// stripe.ts
import Stripe from "stripe";
import { env } from "./env";

export const stripe = new Stripe(env.STRIPE_SECRET_KEY, {
  apiVersion: "2024-06-20",
});

// webhook.ts
import { env } from "./env";

export async function handleWebhook(req: Request) {
  const sig = req.headers.get("stripe-signature")!;
  const event = stripe.webhooks.constructEvent(
    await req.text(),
    sig,
    env.STRIPE_WEBHOOK_SECRET
  );
  // Handle event...
}

Released under the MIT License.