Guides
Stripe Integration
Automatically provision and manage licenses based on Stripe subscription events.
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.
# 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.
# 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 webhook4. Events Handled
Licentric listens for these Stripe webhook events and takes action automatically.
| Stripe Event | Licentric Action |
|---|---|
| checkout.session.completed | Auto-provisions a new license key and creates a customer record |
| customer.subscription.deleted | Revokes the associated license (with configurable grace period) |
| invoice.payment_failed | Suspends the license until payment succeeds |
| charge.refunded | Revokes 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.
# 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.
# 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