# Connecting Stripe

Source: https://kirora.io/docs/api/stripe

Record your Stripe payments, invoices and subscriptions as events on your contacts.

Connect your Stripe account and Kirora records your customers' payments, invoices and
subscriptions as events, on the contact with the same email. Journeys and segments use
them like any event: a receipt, a failed-payment reminder, a win-back after a
cancellation. Nothing changes in your code.

## Connect

1. In Stripe, open **Developers → API keys** and copy a **secret key** (`sk_live_…`), or
   create a **restricted key** (`rk_live_…`) with **Charges: Read**, **Webhook Endpoints:
   Write** and **Customers: Read**. Stripe advises a key of its own for this, since
   webhook access can see every event. In test mode, also give it **PaymentIntents: Write** so the
   connection check can make its test payment.
2. In Kirora, open **Integrations → Stripe** and paste the key.

Kirora checks the key with Stripe, then registers its own webhook endpoint in your Stripe
account, so there is no URL to copy. The key is stored encrypted and shown only by its
last characters. Use a test key (`sk_test_…`) in a staging workspace.

## What becomes Kirora data

| In Stripe | In Kirora |
| --- | --- |
| `charge.succeeded` with an email | `Order Completed`: `order_id` (the payment intent), `total` in major units (`49.90`, not `4990`), `currency` |
| `invoice.payment_succeeded` | `Payment Succeeded`, with `invoice_id`, `subscription_id`, `total`, `billing_reason` (`subscription_cycle` is a renewal) |
| `invoice.payment_failed` | `Payment Failed`, with `total`, `attempt_count`, `next_payment_attempt` (when Stripe tries again, or null when no retry is due) and `payment_url` (the hosted invoice page), once per attempt |
| `invoice.paid` (also when marked paid outside Stripe), `invoice.voided`, `invoice.marked_uncollectible` | `Invoice Closed`, with `reason`: stops payment reminders |
| A subscription created in trial | `Trial Started` |
| A subscription becoming active | `Subscription Started` |
| Renewal turned off, or a subscription deleted | `Subscription Cancelled` |

- **The contact** is found by the email Stripe has for the customer, or created with no
  marketing consent: a payment is not permission to send marketing.
- **Each Stripe event counts once**, however often Stripe redelivers it.
- **Names**: the events use Kirora's standard names. If your workspace calls a key event
  something else (`keyEvents` in workspace settings), Stripe's events use your name.
- **Payments with no email** name nobody and are skipped.

## Check the connection

**Integrations → Stripe → Check connection** asks Stripe whether the key still works and
whether Kirora's webhook is registered and turned on, and says what to fix when not. With
a test key (`sk_test_…` or `rk_test_…`) it also makes a 1.00 USD test payment with
Stripe's test card. Moments later it arrives as a real webhook and an `Order Completed`
for `stripe-check@kirora.test`, a reserved address that is never mailed. That proves the
whole path. A live key makes no payment; your first real payment confirms it instead.

## Status and problems

The Stripe card shows when Stripe last sent an event. If its webhooks start failing, the
card turns to failing and workspace admins get one notice. A key revoked in Stripe, or a
restricted key without **Customers: Read**, shows as such: payments and invoices still
arrive, but subscription events (which Kirora completes by reading the customer) are
refused until you paste a new key.

## Disconnect

**Integrations → Stripe → Disconnect** deletes the stored key and removes Kirora's
webhook endpoint from your Stripe account. Events already recorded stay.

## Requirements

- **Plan**: the integrations feature (Starter and above).
- **Role**: workspace admins and developers.

## Next steps

- [Events](https://kirora.io/docs/api/events): how events are named and stored
- [E-commerce events](https://kirora.io/docs/api/ecommerce-events): the standard commerce events and their properties
- [Recipe: failed payments](https://kirora.io/docs/api/recipe-failed-payments): a reminder journey on `Payment Failed`