Logo

Checkout Session

OpenMeter provides a simple API to create a customer and generate a Stripe Checkout link to collect payment details. With a single API call you can:

  • Create an OpenMeter Customer (or use an existing one)
  • Create a Stripe customer (or use an existing one)
  • Generate a Stripe Checkout URL to the payment form

The response will contain a URL to the Stripe checkout form to collect credit card details.

When a customer completes the checkout form and provides their payment method, OpenMeter will automatically set the Stripe Customer ID and the payment method to the default payment method for the OpenMeter customer. This is done via OpenMeter listening to the setup_intent.succeeded event via webhooks. This webhook is setup automatically when the OpenMeter Stripe App is installed.

Node.js Example

const session = await openmeter.apps.stripe.createCheckoutSession({
  customer: {
    name: 'ACME, Inc.',
    // Optional: make lookup easier
    key: 'my-database-id',
    usageAttribution: {
      // The subject in the usage event
      subjectKeys: ['my-usage-event-subject'],
    },
  },
  options: {
    // Stripe will redirect to this URL after the checkout
    successURL: 'https://example.com/success',
    currency: 'USD',
  },
});

Wich will return a URL to the Stripe checkout form to collect credit card details:

{
  "customerId": "01JKHFVVZ71HGXD25E28PG8F5Z",
  "mode": "setup",
  "sessionId": "cs_test_xxx",
  "setupIntentId": "seti_xxx",
  "stripeCustomerId": "cus_xxx",
  "successURL": "https://example.com/success",
  "url": "https://checkout.stripe.com/c/pay/cs_test_xxx"
}

cURL Example

Example API Request:

curl  -X POST \
  'https://openmeter.cloud/api/v1/stripe/checkout/sessions' \
  --header 'Authorization: Bearer my-token' \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "customer": {
    "name": "ACME, Inc.",
    "currency": "USD",
    "usageAttribution": { "subjectKeys": ["my-identifier"] }
  },
  "options": {
    "successUrl": "https://example.com/success"
  }
}'

See the Stripe Checkout API documentation for more details on the response fields.