Fetches Stripe customers matching a contact's email, selects the appropriate record, and returns billing and subscription details for use in contact views.
# Source: https://github.com/chatwoot/chatwoot | License: MIT | Copyright 2017-2026 Chatwoot Inc
# Provided via justclaw.it.com; keep this notice with the code.
class Integrations::Stripe::CustomerSummary
RECENT_LIMIT = 5
def initialize(connection:, contact:)
@connection = connection
@contact = contact
end
def perform(customer_id: nil)
return { customers: [], missing_email: true } if @contact.email.blank?
@options = { api_key: @connection.api_token }
@products = {}
escaped_email = @contact.email.gsub(/["\\]/) { |char| "\\#{char}" }
customers = ::Stripe::Customer.search({ query: "email:\"#{escaped_email}\"", limit: 100 }, @options)
matches = customers.data.select { |customer| customer.email&.casecmp?(@contact.email) }
.map {
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key