Stripe Integration
OpenMeter allows you to integrate with Stripe to collect revenue with Stripe Payments. You can assign a Stripe Customer ID for a customer and use it to create a Stripe Checkout Session or a Stripe Portal Session.
How it works?
OpenMeter uses apps to extend the functionality of the platform. For example, you can use apps to integrate with external systems like Stripe.
In the case of the Stripe app, OpenMeter handles:
- Usage metering
- Products and prices
- Subscription management
- Billing
While Stripe handles:
- Credit card details
- Payment collection
- Tax calculations (if enabled)
- Sending invoices to customers
The OpenMeter Stripe app syncrhronizes invoices to Stripe Invoicing for automatic tax calculations and payment collection.
Stripe will charge a fee for each invoice, tax calculations and payment according to your contract with them. Please see the Stripe Fees page for more information.
Onboarding a Customer To Stripe
To bill customers using Stripe, follow the steps below:
- Install the OpenMeter Stripe App
- Create an OpenMeter Customer
- Set the Stripe Customer ID or Create a Stripe Checkout Session
Stripe Customer
OpenMeter allows you to assign a Stripe Customer ID to an OpenMeter customer. This is useful to collect revenue with Stripe Payments.
Set Stripe Customer ID
If you already have a Stripe Customer ID, you can set it to an OpenMeter customer. This will connect the OpenMeter customer to the Stripe customer.
await openmeter.customers.stripe.upsert('customer-id-or-key', {
stripeCustomerId: 'cus_123',
// Optionally set the default payment method
// stripeDefaultPaymentMethodId: 'pm_123',
});
Be sure that you also set the Stripe Default Payment Method ID in OpenMeter or to set a default payment method in Stripe for the customer. This is necessary to automatically charge the customer when an invoice is created.
Use the Stripe Checkout Session to collect payment details create a Stripe Customer automatically.
Get a Stripe Customer
You can get the Stripe Customer data for a customer.
const { stripeCustomerId } =
await openmeter.customers.stripe.get('customer-id-or-key');
// stripeCustomerId: 'cus_123'
// stripeDefaultPaymentMethodId: 'pm_123'
Stripe Checkout Session
You can create a Stripe Checkout Session to collect payment details from a customer and create a Stripe Customer automatically.
Create a Stripe Checkout Session
OpenMeter provides a simple API to create a customer and generate a Stripe Checkout link. With a single API call you can:
- Create an OpenMeter Customer (or use an existing one)
- Attribute Metered Usage to the customer
- Create a Stripe customer (or use an existing one)
- Generate a Stripe Checkout URL to the payment form
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"
}
Read more about the Stripe Checkout API.
Stripe Portal Session
You can create a Stripe Portal Session to allow customers to manage their payment methods and download their invoice history.
The Stripe Portal Session allows customers to:
- Manage their payment methods
- Change billing address
- Download their invoice history
Create a Stripe Portal Session
The session will contain a URL to the Stripe Portal. The customer can use this URL to manage their payment methods and download their invoice history.
const session = await openmeter.customers.stripe.createPortalSession(
'customer-id-or-key',
{
returnUrl: 'https://your-app.com/portal',
},
);
// session.url: 'https://billing.stripe.com/p/login/test_aEUg12345678901234567890'