Stripe Integration Guide

Complete guide to integrating Stripe Checkout and Billing with Discover Mac Apps. Forward affiliate referral codes via metadata and listen to payment webhooks.

Stripe is the most common integration for custom SaaS applications. We integrate seamlessly with Stripe Checkout and Stripe Billing.

1. Creating the Webhook

  1. Log in to your Stripe Dashboard.
  2. Go to Developers > Webhooks.
  3. Click Add an endpoint.
  4. Endpoint URL: Paste your unique webhook URL from the Discover Mac Apps dashboard.

2. Select Stripe Events

We need to listen to specific events to track sales and handle refunds/cancellations. Select the following events:

  • checkout.session.completed (Required for tracking initial sales)
  • invoice.paid (Required if you want recurring commissions on subscriptions)
  • charge.refunded (Required if you want to automatically claw back commissions on refunds)

Click Add endpoint to save.

3. The Webhook Secret

After creating the endpoint, Stripe will display a Signing secret that starts with whsec_.... Reveal this secret, copy it, and paste it into your Discover Mac Apps dashboard under Integrations > Stripe.

Passing the Affiliate ID to Stripe

Stripe webhooks only tell us that a sale occurred, not who referred it. To connect the dots, you must pass the affiliate ID into the Stripe Checkout Session metadata.

When you create a Checkout Session on your server, read the dma_aff_ref cookie and include it in the metadata object:

// Node.js example for creating a Stripe Checkout Session
const affiliateId = req.cookies.dma_aff_ref;

const session = await stripe.checkout.sessions.create({
  payment_method_types: ['card'],
  line_items: [{ price: 'price_123', quantity: 1 }],
  mode: 'subscription',
  success_url: 'https://yoursite.com/success',
  cancel_url: 'https://yoursite.com/cancel',
  client_reference_id: userId,
  metadata: {
    // THIS IS REQUIRED FOR TRACKING
    ref: affiliateId 
  }
});

When checkout.session.completed fires, Stripe will include that metadata, and we will attribute the sale to the correct affiliate!

Was this article helpful?
Still need help? Contact Support