δΈ­

Stripe Payment Setup

This guide covers setting up Stripe for payment processing in your web and desktop applications.

Prerequisites

  • Stripe account (Create one here)
  • Access to Stripe Dashboard
  • Your backend server URL for webhooks

Step 1: Create a Stripe Account

  1. Go to Stripe Dashboard
  2. Create an account with your business email
  3. Verify your email address
  4. Complete business verification (required for live payments)

Step 2: Get API Keys

  1. Log in to Stripe Dashboard
  2. Navigate to Developers > API keys
  3. You'll see two environments:

Test Mode Keys

Key Type Format Usage
Publishable Key pktest... Frontend, safe to expose
Secret Key sktest... Backend only, keep secret

Live Mode Keys

Key Type Format Usage
Publishable Key pklive... Production frontend
Secret Key sklive... Production backend

Warning: Never expose Secret Keys in frontend code or version control.

Step 3: Create Products and Prices

Using Stripe Dashboard

  1. Go to Products in the sidebar
  2. Click Add Product
  3. Fill in product details:
  • Name: Product name
  • Description: Product description
  • Image: Product image (optional)
  1. Add pricing:

One-time Payments

Price: $9.99
Type: One-time

Subscription Pricing

Price: $9.99
Type: Recurring
Billing period: Monthly

Using Stripe API

// Create a product
const product = await stripe.products.create({
  name: 'Pro Plan',
  description: 'Access to all premium features',
});

// Create a price for subscription
const price = await stripe.prices.create({
  product: product.id,
  unit_amount: 999, // $9.99 in cents
  currency: 'usd',
  recurring: {
    interval: 'month',
  },
});
  1. Note down the Price ID (starts with price_)

Step 4: Configure Webhooks

Webhooks notify your server of payment events.

  1. Go to Developers > Webhooks
  2. Click Add endpoint
  3. Enter your endpoint URL:
https://yourdomain.com/v1/payment/webhook/stripe
  1. Select events to listen to:
  • checkout.session.completed
  • payment_intent.succeeded
  • paymentintent.paymentfailed
  • customer.subscription.created
  • customer.subscription.updated
  • customer.subscription.deleted
  • invoice.paid
  • invoice.payment_failed
  1. Click Add endpoint
  2. Note down the Webhook Signing Secret (starts with whsec_)

Step 5: Configure in OpenDev

  1. Log in to OpenDev Platform
  2. Navigate to your application settings
  3. Go to Payment Configuration
  4. Add Stripe configuration:
{
  "platform": "stripe",
  "enabled": true,
  "config": {
    "publishableKey": "pk_live_xxx",
    "secretKey": "sk_live_xxx",
    "webhookSecret": "whsec_xxx"
  }
}

Configuration Fields

Field Required Description
Publishable Key Yes Frontend API key
Secret Key Yes Backend API key
Webhook Secret Yes Webhook signing secret

Step 6: Configure Product Tiers

Link Stripe Price IDs to your product tiers:

  1. Go to Product Tiers in OpenDev
  2. For each tier, add the Stripe Price ID:
{
  "productId": "pro_monthly",
  "name": "Pro Monthly",
  "platformProductIds": {
    "stripe": "price_1234567890"
  }
}

Step 7: Implement Checkout

The easiest way to accept payments:

// Frontend - Create checkout session
const response = await fetch('/api/create-checkout-session', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    priceId: 'price_xxx',
    successUrl: 'https://yourdomain.com/success',
    cancelUrl: 'https://yourdomain.com/cancel',
  }),
});

const { sessionId } = await response.json();

// Redirect to Stripe Checkout
const stripe = Stripe('pk_xxx');
stripe.redirectToCheckout({ sessionId });
// Backend - Create session
const session = await stripe.checkout.sessions.create({
  payment_method_types: ['card'],
  line_items: [{
    price: 'price_xxx',
    quantity: 1,
  }],
  mode: 'subscription', // or 'payment' for one-time
  success_url: 'https://yourdomain.com/success?session_id={CHECKOUT_SESSION_ID}',
  cancel_url: 'https://yourdomain.com/cancel',
});

Using Payment Elements

For custom UI integration:

<form id="payment-form">
  <div id="payment-element"></div>
  <button type="submit">Pay</button>
</form>

<script>
const stripe = Stripe('pk_xxx');
const elements = stripe.elements({
  clientSecret: 'pi_xxx_secret_xxx',
});

const paymentElement = elements.create('payment');
paymentElement.mount('#payment-element');
</script>

Step 8: Handle Webhooks

// Backend webhook handler
app.post('/webhook/stripe', express.raw({ type: 'application/json' }), async (req, res) => {
  const sig = req.headers['stripe-signature'];
  
  let event;
  try {
    event = stripe.webhooks.constructEvent(req.body, sig, webhookSecret);
  } catch (err) {
    return res.status(400).send(`Webhook Error: ${err.message}`);
  }

  switch (event.type) {
    case 'checkout.session.completed':
      const session = event.data.object;
      // Fulfill the purchase
      await handleCheckoutComplete(session);
      break;
    case 'invoice.paid':
      // Subscription renewal
      await handleSubscriptionRenewal(event.data.object);
      break;
    case 'customer.subscription.deleted':
      // Subscription canceled
      await handleSubscriptionCanceled(event.data.object);
      break;
  }

  res.json({ received: true });
});

Step 9: Test the Integration

Test Cards

Card Number Scenario
4242 4242 4242 4242 Successful payment
4000 0000 0000 9995 Declined (insufficient funds)
4000 0000 0000 3220 3D Secure required

Use any future expiry date and any 3-digit CVC.

Testing Webhooks Locally

Use Stripe CLI for local webhook testing:

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

# Login
stripe login

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

Troubleshooting

Error: No such price

Solution: Verify the Price ID is correct and exists in your Stripe dashboard.

Error: Invalid API Key

Solution: Check you're using the correct key for your environment (test vs live).

Webhook Signature Verification Failed

Solutions:

  • Ensure webhook secret is correct
  • Use raw body parser for webhook endpoint
  • Check webhook endpoint is receiving POST requests

Payment Declined

Solutions:

  • In test mode, use test card numbers
  • In live mode, verify card details are correct
  • Check for fraud prevention blocks

Security Best Practices

  1. Never Log Full Card Numbers - PCI compliance
  2. Use Webhook Signing - Verify all webhook events
  3. Implement Idempotency - Handle duplicate events
  4. Secure API Keys - Use environment variables
  5. Enable 3D Secure - Reduce fraud and chargebacks