Skip to main content

Guides

Stripe Integration

Automatically provision and manage licenses based on Stripe subscription events.

Zero billing code
Licentric handles all Stripe webhook processing. You connect your Stripe account, map products to policies, and Licentric manages the rest automatically.

1. Connect Your Stripe Account

Navigate to Settings → Integrations → Stripe in the Licentric dashboard and connect your Stripe account. Licentric registers the necessary webhook endpoints in Stripe automatically.

2. Map Stripe Products to Policies

Link each Stripe product/price to a Licentric policy. When a customer subscribes to that Stripe product, a license is automatically created with the mapped policy.

Product mapping (dashboard)
# In the Licentric dashboard:
# Settings → Integrations → Stripe
#
# Map your Stripe products to Licentric policies:
#
# Stripe Product "Starter Plan" ($5/mo)
#   → Licentric Policy "starter_policy"
#   → Entitlements: ["export", "api_access"]
#
# Stripe Product "Growth Plan" ($29/mo)
#   → Licentric Policy "growth_policy"
#   → Entitlements: ["export", "api_access", "premium_analytics"]
#
# When a customer subscribes via Stripe Checkout,
# Licentric automatically creates the license.

3. Checkout Flow

Your app creates a Stripe Checkout session as usual. After payment, Licentric processes the webhook and provisions the license automatically.

checkout.py
# Your app creates a Stripe Checkout session as usual
import stripe

stripe.api_key = "sk_live_..."

session = stripe.checkout.Session.create(
    mode="subscription",
    line_items=[{
        "price": "price_starter_monthly",
        "quantity": 1
    }],
    customer_email="customer@example.com",
    success_url="https://yourapp.com/success",
    cancel_url="https://yourapp.com/pricing"
)

# After payment:
# 1. Stripe sends checkout.session.completed webhook
# 2. Licentric processes it automatically
# 3. License key is created for the customer
# 4. Your app receives a license.created webhook

4. Events Handled

Licentric listens for these Stripe webhook events and takes action automatically.

Stripe EventLicentric Action
checkout.session.completedAuto-provisions a new license key and creates a customer record
customer.subscription.deletedRevokes the associated license (with configurable grace period)
invoice.payment_failedSuspends the license until payment succeeds
charge.refundedRevokes the license associated with the refunded charge

5. Receive the License Key

After Licentric provisions the license, it sends a license.created webhook to your app. Use this to store the key and notify the customer.

webhook_handler.py
# Your webhook handler receives the license.created event
# from Licentric (not from Stripe — Licentric handles Stripe events)

def handle_licentric_webhook(request):
    event = verify_webhook(request)

    if event["type"] == "license.created":
        license_data = event["data"]
        user = find_user_by_email(license_data["email"])
        user.license_key = license_data["key"]
        user.plan = license_data["policy"]["name"]
        user.save()

        send_welcome_email(user, license_data["key"])

6. Cancellation Grace Period

Configure how long a license stays active after a subscription is cancelled. This gives customers time to resubscribe without losing access.

Grace period options
# Configure grace period for subscription cancellation
# In the Licentric dashboard:
# Settings → Integrations → Stripe → Grace Period
#
# Options:
#   Immediate — license revoked when subscription ends
#   3 days    — customer has 3 days to resubscribe
#   7 days    — customer has 7 days to resubscribe (default)
#   30 days   — customer has 30 days to resubscribe
#
# During the grace period:
#   - License status remains "active"
#   - validation returns valid=true
#   - metadata includes graceEndsAt timestamp
Failed payments
When an invoice payment fails, Licentric automatically suspends the associated license. If the payment succeeds on retry (handled by Stripe's dunning), the license is automatically reinstated.