Skip to content

Stripe Setup & Integration Guide

The stripe provider integrates Stripe Checkout, Stripe Elements, Subscriptions & Invoicing, Customer Billing Portal, Saved Payment Methods, and Dispute Management into the Kirak payments runtime.


No extra install: the provider calls Stripe’s REST API over Kirak’s own async HTTP client, so pip install kirak is all it needs.


In the Stripe Dashboard:

  1. Navigate to Developers $\rightarrow$ API keys.
  2. Copy your Secret key (sk_test_... in test mode, sk_live_... in production).

Declare the Stripe instance under payments.providers:

{
"payments": {
"default_provider": "stripe",
"providers": {
"stripe": {
"type": "stripe",
"success_url": "https://your-domain.com/payment/success",
"cancel_url": "https://your-domain.com/payment/cancel",
"timeout": 15
}
}
}
}
Setting Type Default Description
type string "stripe" Provider type identifier
success_url string "/payment/success" Buyer redirect URL after payment completion (Kirak appends ?tid=<transaction_id>). Must be absolute
cancel_url string "/payment/cancel" Buyer redirect URL if checkout is cancelled. Must be absolute
timeout number 15 Maximum seconds allowed for Stripe API calls

Stripe sends the buyer’s browser to success_url and cancel_url from its own site, so both must be absolute (https://...). The defaults above are relative and Stripe refuses them: set both, or payments.success_url and payments.cancel_url for every provider, before taking a payment. A relative one is refused with 400 STRIPE_ERROR naming the setting, in details.config_key.

Set credentials in your environment. Secrets are never declared in kirak.json:

Terminal window
KIRAK_PAYMENT_STRIPE_SECRET_KEY=sk_test_51...
KIRAK_PAYMENT_STRIPE_WEBHOOK_SECRET=whsec_... # Obtained in Step 4

[!NOTE] If you name your instance differently in kirak.json (e.g. "stripe_us"), the environment variables become KIRAK_PAYMENT_STRIPE_US_SECRET_KEY and KIRAK_PAYMENT_STRIPE_US_WEBHOOK_SECRET.


In the Stripe Dashboard, navigate to Developers $\rightarrow$ Webhooks $\rightarrow$ Add endpoint:

  1. Endpoint URL: https://your-domain.com/payments/webhook/stripe
  2. Listen to: Events on your account.
  3. Select at minimum the following events:
    • Checkout & One-Time: checkout.session.completed, checkout.session.async_payment_succeeded, checkout.session.async_payment_failed
    • Subscriptions & Invoices: invoice.payment_succeeded, invoice.payment_failed, customer.subscription.updated, customer.subscription.deleted
    • Refunds: charge.refunded
    • Saved Methods & Off-Session: payment_method.detached, payment_method.updated, payment_method.automatically_updated, customer.updated, payment_intent.succeeded, payment_intent.payment_failed
    • Disputes: charge.dispute.created, charge.dispute.closed
  4. Copy the Signing secret (whsec_...) and export it as KIRAK_PAYMENT_STRIPE_WEBHOOK_SECRET.

[!WARNING] If KIRAK_PAYMENT_STRIPE_WEBHOOK_SECRET is unset, all incoming webhooks are rejected with 500 WEBHOOK_SECRET_NOT_CONFIGURED to prevent spoofing.


If you run multiple Kirak applications or environments (e.g. Staging and Production) against the same Stripe account in test mode, Stripe broadcasts events to all endpoints.

Kirak safely isolates events using the following protections:

  1. Checkout Sessions: A checkout webhook only updates the database record that originally stored the Stripe Checkout session_id.
  2. Off-Session Charges: Off-session PaymentIntents store a random identifier (kirak_ref) in Stripe metadata; events lacking a matching reference in payment_meta are acknowledged (HTTP 200) and safely skipped.
  3. Setup Sessions: Cards are vaulted only for the customer ID registered by that database instance.

result = await kirak.payments.initiate_payment({
"provider": "stripe",
"user_id": "usr_100",
"amount": 2999, # $29.99 in cents
"currency": "USD",
"name": "Standard License",
"type": "one_time",
"idempotency_key": "order-100-std",
})
checkout_url = result["data"]["url"]
result = await kirak.payments.initiate_payment({
"provider": "stripe",
"user_id": "usr_100",
"amount": 0, # Charged directly from Stripe Price ID
"currency": "USD",
"name": "Pro Monthly Plan",
"type": "subscription",
"subscription_plan_id": "price_1NXXXXXXXXXXXXXX",
})

5.3 Creating the Price That Subscription Charges

Section titled “5.3 Creating the Price That Subscription Charges”

The subscription_plan_id above is a Stripe Price, which ensure_plan creates so the plans can live in the app’s code rather than in the dashboard. Set "plan_catalog": true under payments in kirak.json first; it is off by default.

answer = await kirak.payments.ensure_plan({
"provider": "stripe",
"key": "pro_monthly_2900", # becomes the Price's lookup_key
"product_key": "pro", # the Product the Prices hang off
"name": "Pro Monthly Plan", # the Product's name, shown at checkout
"amount": 2900,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"metadata": {"tier": "pro"},
})
price_id = answer["data"]["plan_id"] # price_1NXXXXXXXXXXXXXX

Stripe splits a plan into a Product (what is sold) and a Price (how much, how often), and a Price is immutable. ensure_plan maps onto that: product_key is the Product’s id, created if missing, and key is the Price’s lookup_key, which it searches before creating anything. Because the lookup_key lives on the Price for good, a re-run finds the same Price and reports created: false - unlike an idempotency key, which Stripe forgets after 24 hours. A changed amount needs a new key; the old Price keeps billing its existing subscribers until they are moved with update_subscription.

portal = await kirak.payments.get_billing_portal({
"user_id": "usr_100",
"return_url": "https://app.example.com/account",
"provider": "stripe",
})
portal_url = portal["data"]["portal_url"]
# Save card during checkout:
await kirak.payments.initiate_payment({
"provider": "stripe",
"user_id": "usr_100",
"amount": 1000,
"currency": "USD",
"name": "Verification Hold",
"type": "one_time",
"save_payment_method": True,
"consent": {"text_version": "2026-v1"},
})
# Charge saved card headless (Admin / System only):
charge = await kirak.payments.charge_off_session({
"provider": "stripe",
"user_id": "usr_100",
"amount": 4500, # $45.00
"currency": "USD",
"name": "Usage Overage",
"idempotency_key": "overage-usr100-oct",
})

Kirak normalizes Stripe webhook events into standard after_webhook event names:

Normalized event Gateway Events Description
payment_completed checkout.session.completed (when paid), checkout.session.async_payment_succeeded, payment_intent.succeeded (off-session) Payment confirmed and settled
payment_failed invoice.payment_failed, checkout.session.async_payment_failed, payment_intent.payment_failed (declined) Payment rejected
subscription_renewed invoice.payment_succeeded Recurring subscription billed
subscription_updated customer.subscription.updated Subscription terms altered
subscription_past_due customer.subscription.updated (past_due, unpaid) Recurring charge failed
subscription_cancelled customer.subscription.deleted Subscription canceled
refund_completed charge.refunded Refund issued and settled
dispute_created charge.dispute.created Customer bank opened chargeback
dispute_updated charge.dispute.closed Dispute resolved or closed
payment_method_saved payment_method.updated, customer.updated Card details vaulted
payment_method_removed payment_method.detached Card removed at Stripe