Stripe API License Integration AI Prompt

Copy/paste this prompt into your AI assistant to integrate Stripe payments with ExisOne API License generation - for selling API keys with usage quotas and rate limits.

API Licenses vs Standard Licenses: API licenses are designed for customers who sell API access to their end-users. Instead of hardware-locked device licenses, API licenses provide keys with usage quotas (e.g., 10,000 API calls) and rate limits (e.g., 100 calls/minute).
Before using this prompt: Replace the example values with your actual configuration:
  • PRODUCT_ID - Your ExisOne API License Product ID (e.g., 14)
  • QUANTITY - The API call quota to grant (e.g., 10000)
  • PRICE - Your price in USD (e.g., 25.00)

Prompt

You're assisting me in integrating Stripe payments with ExisOne for automatic API license key generation.

GOAL
- Integrate Stripe Checkout on my website to sell API access
- When customers complete payment, Stripe sends a webhook to ExisOne
- ExisOne automatically generates an API license key with usage quotas and emails it to the customer
- API licenses support lifetime quotas (e.g., 10,000 API calls) and rate limits (e.g., 100 calls/minute)

CONTEXT
- ExisOne webhook URL: https://www.exisone.com/api/stripe/webhook
- I have already configured my Stripe app in ExisOne with encrypted Secret Key and Webhook Signing Secret
- My ExisOne Product is configured as an "API License Product" with "Use Quantity as API Calls" enabled

EXAMPLE CONFIGURATION
- Product ID: 14
- Product Name: "API Access"
- Quota: 10,000 API calls
- Price: $25.00
- "Use Quantity as API Calls" is ENABLED (purchase quantity becomes the API call quota)

HOW IT WORKS
1. My website creates a Stripe Checkout session with metadata: productId=14, quantity=10000
2. Customer completes payment on Stripe
3. Stripe sends webhook to ExisOne (checkout.session.completed)
4. ExisOne reads Product ID from metadata.productId and quantity as the API call quota
5. ExisOne generates 1 API license key with 10,000 call quota
6. ExisOne emails the API key to the customer

SERVER-SIDE: Create Checkout Session (Node.js)

const stripe = require('stripe')('sk_live_YOUR_SECRET_KEY');

app.post('/create-api-checkout-session', async (req, res) => {
    const session = await stripe.checkout.sessions.create({
        mode: 'payment',
        success_url: 'https://yoursite.com/success?session_id={CHECKOUT_SESSION_ID}',
        cancel_url: 'https://yoursite.com/cancel',
        metadata: {
            productId: '14',      // ExisOne Product ID - REQUIRED
            quantity: '10000'     // THIS BECOMES THE API CALL QUOTA
        },
        line_items: [{
            quantity: 1,
            price_data: {
                currency: 'usd',
                unit_amount: 2500,   // $25.00 in cents
                product_data: {
                    name: 'API Access - 10,000 Calls'
                }
            }
        }]
    });

    res.json({ url: session.url });
});

MULTIPLE TIER EXAMPLE
If you want to offer multiple API tiers:

const tiers = {
    starter:      { productId: '14', quantity: '1000',   price: 999,   name: 'Starter - 1,000 API Calls' },
    professional: { productId: '14', quantity: '10000',  price: 2500,  name: 'Professional - 10,000 API Calls' },
    enterprise:   { productId: '14', quantity: '100000', price: 9900,  name: 'Enterprise - 100,000 API Calls' }
};

app.post('/create-api-checkout-session', async (req, res) => {
    const { tier } = req.body;
    const selected = tiers[tier] || tiers.professional;

    const session = await stripe.checkout.sessions.create({
        mode: 'payment',
        success_url: 'https://yoursite.com/success?session_id={CHECKOUT_SESSION_ID}',
        cancel_url: 'https://yoursite.com/cancel',
        metadata: {
            productId: selected.productId,
            quantity: selected.quantity
        },
        line_items: [{
            quantity: 1,
            price_data: {
                currency: 'usd',
                unit_amount: selected.price,
                product_data: { name: selected.name }
            }
        }]
    });

    res.json({ url: session.url });
});

CLIENT-SIDE: Stripe Checkout Button (HTML/JavaScript)

<h2>Purchase API Access</h2>
<p>10,000 API Calls - $25.00</p>
<button id="checkout-button">Buy Now</button>

<script>
document.getElementById('checkout-button').addEventListener('click', async () => {
    const response = await fetch('/create-api-checkout-session', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' }
    });
    const { url } = await response.json();
    window.location.href = url;
});
</script>

CRITICAL CONFIGURATION IN EXISONE
1. Product ID 14 must have "API License Product" checkbox ENABLED
2. Product ID 14 must have "Use Quantity as API Calls" checkbox ENABLED
3. "Send purchase email automatically" must be ENABLED
4. Configure email template with {{ApiKey}} placeholder

RATE LIMITS (OPTIONAL)
Add these as product features to limit API usage:
- api:rate:minute:100   (max 100 calls per minute)
- api:rate:hour:1000    (max 1,000 calls per hour)
- api:rate:day:10000    (max 10,000 calls per day)
- api:units:minute:500  (max 500 units consumed per minute)

EMAIL TEMPLATE EXAMPLE
Subject: Your API Key - {{ProductName}}

Body:
<h2>Thank you for your purchase!</h2>
<p>Your API key:</p>
<p style="font-size: 20px; font-family: monospace; background: #f0f0f0; padding: 15px;">{{ApiKey}}</p>
<p>Your API quota: {{ApiQuota}} calls</p>
<p>View your usage and remaining quota at: {{CustomerPortalUrl}}</p>

EMAIL TEMPLATE PLACEHOLDERS
- {{ApiKey}} - The generated API key
- {{ApiQuota}} - The API call quota purchased (e.g., "10,000")
- {{ProductName}} - Your product name
- {{CustomerEmail}} - Customer's email address
- {{PaymentProcessorCustomerName}} - Customer name from Stripe
- {{CustomerPortalUrl}} - Link to customer portal

VALIDATING API KEYS (FOR YOUR CUSTOMERS)
Your customers validate their end-users' API keys:

POST https://www.exisone.com/api/apilicense/validate
Content-Type: application/json

{
    "apiKey": "XXXX-XXXX-XXXX-XXXX",
    "units": 1,
    "consume": true
}

Response:
{
    "isValid": true,
    "unitsConsumed": 1,
    "quota": { "limit": 10000, "used": 501, "remaining": 9499 },
    "expiresAt": "2027-01-14T23:59:59Z"
}

DELIVERABLES
- Server-side code to create Stripe Checkout sessions with Product ID and quantity
- Client-side Stripe checkout button integration
- Email template configured in ExisOne

Please produce idiomatic code for my stack with proper error handling.

Notes