LogoNEXTDEVKIT Docs

Stripe Integration

Complete guide to set up and configure Stripe payments in NEXTDEVKIT

🚀 Stripe Setup

Follow these steps to integrate Stripe with NEXTDEVKIT:

1. Create Stripe Account

  1. Create a Stripe account at stripe.com
  2. Go to the Stripe Dashboard

2. Get API Keys

  1. Go to DevelopersAPI keys
  2. Copy your Secret key (starts with sk_test_ for test mode)

Add to your .env file:

STRIPE_SECRET_KEY="sk_test_your_secret_key"

3. Set up Webhooks

  1. Go to DevelopersWebhooks

  2. Click "Add endpoint"

  3. Enter your webhook URL: https://your-domain.com/api/webhooks/stripe

  4. Select these events:

    • checkout.session.completed
    • customer.subscription.created
    • customer.subscription.updated
    • customer.subscription.deleted
  5. Copy the Webhook Signing Secret (starts with whsec_)

Add to your .env file:

STRIPE_WEBHOOK_SECRET="whsec_your_webhook_secret"

4. Create Products and Prices

Pro Subscription Product

  1. Go to ProductsAdd product
  2. Name: "Pro Plan"
  3. Add Monthly price:
    • Price: your monthly price
    • Billing period: Monthly
    • Recurring: Yes
    • Copy the Price ID (starts with price_)
  4. Add Yearly price:
    • Price: your yearly price
    • Billing period: Yearly
    • Recurring: Yes
    • Copy the Price ID (starts with price_)

Lifetime Product

  1. Go to ProductsAdd product
  2. Name: "Lifetime Plan"
  3. Add One-time price:
    • Price: your lifetime price
    • Billing period: One-time
    • Recurring: No
    • Copy the Price ID (starts with price_)

5. Configure Environment Variables

# Stripe Configuration
STRIPE_SECRET_KEY="sk_test_your_secret_key"
STRIPE_WEBHOOK_SECRET="whsec_your_webhook_secret"

# Price IDs
NEXT_PUBLIC_PRICE_ID_PRO_MONTHLY="price_your_monthly_price_id"
NEXT_PUBLIC_PRICE_ID_PRO_YEARLY="price_your_yearly_price_id"
NEXT_PUBLIC_PRICE_ID_LIFETIME="price_your_lifetime_price_id"

6. Update Payment Provider Configuration

In src/config/index.ts, set the provider to Stripe:

payment: {
  provider: "stripe",
  currency: "USD",
  // ... rest of your configuration
  plans: {
    pro: {
      prices: [
					{
						amount: 9.99, // your monthly price
						interval: PlanInterval.MONTH,
						trialPeriodDays: 7, // your trial period days
					},
					{
						amount: 99, // your yearly price
						interval: PlanInterval.YEAR,
						trialPeriodDays: 30, // your trial period days
					},
      ],
    },
  },
}

🧪 Testing with Stripe

Test Credit Cards

Use these test cards with Stripe:

Card NumberDescription
4242 4242 4242 4242Successful payment
4000 0000 0000 32203D Secure authentication
4000 0000 0000 9995Insufficient funds
4000 0000 0000 0069Expired card

Local Development

# Install Stripe CLI
brew install stripe/stripe-cli/stripe

# Login to Stripe
stripe login

# Forward events to local server
stripe listen --forward-to localhost:3000/api/webhooks/stripe

# Test webhooks
stripe trigger checkout.session.completed
stripe trigger customer.subscription.created

Using ngrok for Webhook Testing

You can also use ngrok to create a tunnel to your local machine:

ngrok http 3000

Then use the ngrok URL in your Stripe webhook configuration.

🔧 Stripe Features

Customer Portal

Stripe provides a hosted customer portal where customers can:

  • Update payment methods
  • View billing history
  • Cancel subscriptions
  • Download invoices

Advanced Features

  • Tax calculation: Automatic tax calculation for global customers
  • Fraud detection: Built-in fraud prevention
  • Subscription management: Flexible subscription handling
  • Multi-currency: Support for 135+ currencies
  • Payment methods: Credit cards, digital wallets, bank transfers

🔧 Troubleshooting

Common Issues

Webhook Not Receiving Events:

  • Check webhook URL is correct
  • Verify webhook signing secret
  • Ensure HTTPS in production
  • Check selected events

Payment Failures:

  • Verify API keys are correct
  • Check card details format
  • Ensure proper error handling
  • Test with different cards

Customer Portal Issues:

  • Check customer ID is valid
  • Verify return URL is correct
  • Ensure customer has payment methods

Subscription Problems:

  • Check subscription status
  • Verify webhook processing
  • Review billing cycle settings

📊 Stripe Dashboard

The Stripe Dashboard provides:

  • Real-time analytics: Revenue, customer metrics
  • Payment tracking: Transaction history and status
  • Customer management: Customer profiles and data
  • Subscription monitoring: Active subscriptions and churn
  • Tax reporting: Automated tax calculations

🔗 Stripe Resources


🎯 Next Steps

Now that Stripe is configured: