Developers

Guide

Stripe billing events

Connect your Stripe account with one restricted key: customers, checkouts, subscriptions, invoices and refunds update contacts and start journeys.

Connect each product to the Stripe account that bills its customers. HelpWell then reads every existing customer, keeps billing fields on the matching contacts (subscription status, plan, MRR, last payment) so active customers can be told from cancelled ones, and starts journeys on Stripe events: trial ending, payment failed, subscription cancelled. Nothing to code.

#Connect with one restricted key

  1. In HelpWell open Settings → Integrations → Stripe → Connect Stripe and choose the product.
  2. Click Create the key in Stripe (test mode first). Stripe's "Create restricted key" form opens with the name HelpWell journeys and these permissions already set; every other row stays None:
SectionResourceAccessUsed for
Core resourcesCustomersReadmatch customers to contacts
Core resourcesCharges and RefundsReadrefund events
Core resourcesProductsReadplan names
Checkout resourcesCheckout SessionsReadcheckout events
Billing resourcesInvoicesReadpayment events
Billing resourcesSubscriptionsReadplan, status and MRR
Connect resourcesAccountsReadshow which Stripe account is connected
Webhook resourcesWebhook EndpointsWritecreate, check and remove HelpWell’s endpoint

The direct links: test mode and live mode.

  1. Click Create key in Stripe and copy the key (rk_test_…).
  2. Paste it into Restricted key in HelpWell and click Connect.

HelpWell checks the key, creates its own webhook endpoint (https://app.helpwell.ai/webhooks/stripe/<product id>) subscribed to exactly the events below, stores the endpoint's signing secret encrypted and checks it. You never copy a signing secret. The page then shows Webhook created by HelpWell with the endpoint id, and the connection's health: the last event received, deliveries refused, and events that failed.

Manual setup stays available under "Set up the webhook yourself": create the endpoint in Stripe Workbench with the URL and events HelpWell shows, then paste the key and the endpoint's whsec_… signing secret.

#Sync every existing customer

Connecting starts a sync of everything already in Stripe, and Sync all customers now on the connection's card runs it again whenever you like. It is a background job that pages through every customer and subscription (all statuses, cancelled included), 100 at a time, and shows its progress on the card. It needs only read access: Customers and Subscriptions, which a key made for the manual setup has too. Products: Read names plans (otherwise the price's nickname, lookup key or id does), and Charges: Read adds the lifetime value; without them the sync carries on without those fields.

  • Each Stripe customer is matched to a contact of the product by the Stripe customer id, the helpwell_contact_id metadata, or an email that matches exactly one contact (contacts you imported earlier are matched this way and keep their tags). A customer nobody matches becomes a new contact; one without an email is skipped, and so is one whose email several contacts share.
  • Several Stripe customers with one email are one person: their best subscription wins (active, then trialing, past due, unpaid, paused, incomplete, cancelled), "customer since" is the earliest, and what they paid adds up.
  • It never changes an existing contact's email consent (an unsubscribe stays), never adds an address on the suppression list (the card counts them: "N skipped (unsubscribed/bounced)"; a contact that already exists is still updated), never starts a journey (old customers do not get a "Customer created" welcome), and never overwrites a subscription a webhook updated after it started. A contact it adds is subscribed by default, like one a webhook adds (below).
  • A sync that stops (a deploy, a Stripe error, a rate limit) resumes at the page it was on. One stopped by a missing permission says which, and Resume sync carries on once the key is fixed.

Connecting also adds four segments you can edit or delete; connecting again never makes them twice:

SegmentWho is in it
Active customersstripe.status is active or trialing
Cancelled customersstripe.status is canceled, or stripe.cancelAtPeriodEnd is true
Trialingstripe.status is trialing
Past duestripe.status is past_due

Use them as a newsletter's audience (include or exclude), in journey conditions, or as a journey trigger (Entered a segment, for example "Entered Cancelled customers" for a win-back). Webhook events keep every field current after the sync.

#Send a test event

In test mode, open Stripe → Customers → Add customer, enter a name and an email address you own, and save. Within a minute Recent deliveries in HelpWell shows customer.created as processed and the person appears in Contacts. With the Stripe CLI, stripe trigger customer.subscription.created sends a subscription. In live mode, wait for a real event rather than creating customers.

#Events and journey triggers

Stripe eventJourney triggerUpdates
customer.createdstripe.customer.createdcustomer id, customer since, delinquent (status none until a subscription starts); fills a missing name or email
customer.updatedstripe.customer.updatedcustomer id, customer since, delinquent (status none until a subscription starts); fills a missing name or email
checkout.session.completedstripe.checkout.completedlast checkout, its amount; a one-off payment adds to lifetime value
customer.subscription.createdstripe.subscription.createdstatus, plan, MRR, quantity, started, cancelled at, trial and period end
customer.subscription.updatedstripe.subscription.updatedstatus, plan, MRR, quantity, started, cancelled at, trial and period end
customer.subscription.deletedstripe.subscription.cancelledstatus, plan, MRR, quantity, started, cancelled at, trial and period end
customer.subscription.trial_will_endstripe.subscription.trial_endingstatus, plan, MRR, quantity, started, cancelled at, trial and period end
invoice.paidstripe.invoice.paidlast invoice status and amount, last payment or failed payment; a paid invoice adds to lifetime value
invoice.payment_failedstripe.invoice.payment_failedlast invoice status and amount, last payment or failed payment; a paid invoice adds to lifetime value
charge.refundedstripe.charge.refundedlast refund, its amount; takes the refund off lifetime value

Each event is processed once (retries from Stripe are recognised by event id), older states never overwrite newer ones, and a journey starts once per checkout, subscription or paid invoice.

#Every subscription and product

A customer can hold several subscriptions, each with several products. HelpWell keeps every one, cancelled ones included, one row per product: its name (Products: Read; otherwise the price's nickname or id), the price's nickname, status, MRR, currency, start date, current period end, trial end, whether it cancels at the period end, when it was cancelled and any coupon. The sync backfills them and webhooks keep them current. Contacts shows them as chips in the Plan / product column ("BrandWell Pro · active", "AI Detector · cancelled") and the profile lists each one.

From them, every contact carries lists you can filter on like any field:

FieldHolds
stripe.productsproducts on subscriptions still running (active, trialing, past due, unpaid, paused, incomplete)
stripe.productsActiveproducts on active subscriptions
stripe.productsTrialingproducts on trialing subscriptions
stripe.productsPastDueproducts on past-due subscriptions
stripe.productsCanceledproducts on cancelled subscriptions
stripe.allProductsevery product they ever subscribed to
stripe.productHistoryevery product with its status, such as "AI Detector · cancelled"
  • Has a subscription to a product with a status: stripe.productsCanceled includes "AI Detector" (likewise productsActive, productsTrialing, productsPastDue).
  • Does not have an active subscription to a product: stripe.productsActive excludes "AI Detector".
  • Past subscribers of a product: stripe.productsCanceled includes "AI Detector" and stripe.products excludes it.
  • A subscription to a product changed status is a journey trigger, stripe.subscription.product_status, raised once per product whose status is new or changed, with product, productId, status, previousStatus, subscriptionId and mrr. Filter it on Product and New status, for example "Product is AI Detector and New status includes canceled" for a cross-sell.

Choosing fields. The four main fields (Plan / product, Subscription status, MRR, Total revenue paid) are on as soon as Stripe is connected. See more on the connection's card lists the other fields below to tick (country, customer since, current period end, cancels at period end, trial end, last payment and its amount, currency, coupon, Stripe customer ID, delinquent, billing interval, product history…); each ticked field shows in columns, filters and the profile. Every field is synced either way.

#Fields on the contact

FieldLabelType
stripe.productsPlan / productList
stripe.statusSubscription statusList
stripe.mrrMRRNumber (cents)
stripe.lifetimeValueTotal revenue paidNumber (cents)
stripe.productsActiveProducts with an active subscriptionList
stripe.productsTrialingProducts with a trialing subscriptionList
stripe.productsPastDueProducts with a past-due subscriptionList
stripe.productsCanceledProducts with a cancelled subscriptionList
stripe.allProductsProducts ever subscribedList
stripe.productHistoryProduct historyList
stripe.countryCountryList
stripe.customerSinceCustomer sinceNumber (Unix seconds)
stripe.currentPeriodEndCurrent period endsNumber (Unix seconds)
stripe.cancelAtPeriodEndCancels at period endYes or no
stripe.trialEndTrial endsNumber (Unix seconds)
stripe.lastPaymentAtLast paymentNumber (Unix seconds)
stripe.lastPaymentAmountLast payment amountNumber (cents)
stripe.currencyCurrencyList
stripe.discountCoupon or discountText
stripe.customerIdStripe customer IDText
stripe.delinquentDelinquentYes or no
stripe.intervalBilling intervalList
stripe.planPlanText
stripe.amountPriceNumber (cents)
stripe.quantityQuantityNumber
stripe.subscriptionStartedAtSubscription startedNumber (Unix seconds)
stripe.canceledAtCancelled atNumber (Unix seconds)
stripe.lastInvoiceStatusLast invoice statusList
stripe.lastInvoiceAmountLast invoice amountNumber (cents)
stripe.lastPaymentFailedAtLast failed paymentNumber (Unix seconds)
stripe.lastCheckoutAtLast checkoutNumber (Unix seconds)
stripe.lastCheckoutAmountLast checkout amountNumber (cents)
stripe.lastRefundAtLast refundNumber (Unix seconds)
stripe.lastRefundAmountLast refund amountNumber (cents)

Amounts are in the currency's smallest unit (cents) and times in Unix seconds, as Stripe sends them; the contact profile shows them as money and dates. Subscription status is Stripe's (active, trialing, past_due, unpaid, paused, incomplete, canceled, incomplete_expired) or none for a customer without a subscription, and the fields describe the person's main subscription: the best status, so an old cancelled subscription never hides a live one. MRR counts active and past-due subscriptions per month (yearly prices divided by 12); trials and cancelled subscriptions count 0, and discounts are not included. The contact profile and the inbox's contact panel show the status as a badge (Active customer, Trialing, Past due, Cancelling, Cancelled customer).

Use these fields in segments and newsletter audiences, journey If/else branches, entry conditions and goals, and in email: {{plan}}, {{subscription_status}} (active, trialing, past due, cancelled), {{customer_since}} and {{trial_ends}}, each with a fallback.

#How customers become contacts

HelpWell finds the contact by the Stripe customer id it saw before, by helpwell_contact_id in the customer's metadata, or by an email that matches exactly one contact of the product; otherwise it creates one. A guest checkout without a customer is matched by its email. Billing never changes an existing contact's email consent. A contact Stripe creates (a webhook or the sync) is recorded as subscribed, with the statement "Paying customer in Stripe" and the time: this is on by default, and an owner or admin can turn it off or change the statement by asking an AI assistant connected to HelpWell (Settings → Integrations → AI assistants) to update the marketing consent settings. An address on the suppression list (unsubscribed, bounced or complained) never becomes a contact. A contact a webhook creates also raises the journey trigger Contact created (source: Stripe customers); the sync of existing customers starts no journey.

To be certain a Stripe customer joins the right person, set the customer's metadata when you create it in your app:

await stripe.customers.create({
  email: user.email,
  metadata: { helpwell_contact_id: contactIdFromHelpWell },
});

#Disconnect

Disconnect stops the connection and deletes the webhook endpoint HelpWell created. If Stripe cannot delete it (for example, the key was revoked first), HelpWell links to it so you can delete it in Workbench. An endpoint you made by hand is yours to delete. Then revoke the key in Stripe → Developers → API keys.

See also Custom fields and Webhooks from HelpWell.