Phase 4 part 3: Stripe customers matched to EspoCRM Accounts

Every customer with billing is matched to an Account copied from the
CRM: the user's choice, then an Account Hermes created from here, a
stored ID on either side, an email (the Account's or a Contact's), or
the email's domain (not free mail). Several candidates wait for a
choice. Metrics → Customers and the CRM fixes matches, marks customers
not in the CRM, and queues paying ones as new Accounts. Schema 20.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 12:22:05 -07:00
co-authored by Claude Opus 5.5
parent 5e799c7541
commit 6ba524295b
13 changed files with 675 additions and 2 deletions
+23
View File
@@ -1089,6 +1089,29 @@ into `main`.
records), by stored ID, email or email domain, with a screen to fix
wrong matches. Customers already tied to prospects (Phase 2) keep that
tie.
- **Built 2026-11-22** (schema 20: `crm_matches`, the user's choices
only):
- `metrics.Matches` matches every customer with a paid or open
invoice, in this order:
1. the user's choice;
2. an Account Hermes created from here (a done `stripe-customer:`
CRM action);
3. a stored ID: `espocrm_id`, `espo_id`, `crm_id` or
`espocrm_account_id` in the customer's metadata, or a
`cus_…` in the Account's `stripeCustomerId`, `cStripeCustomerId`
or a similar field;
4. email, on the Account or one of its Contacts (via
`accountId`);
5. the email's domain, skipping free mail.
- When several Accounts fit, the user chooses.
- The page is Metrics → Customers and the CRM, with three tabs: to
fix, paying now, all. Each customer can be matched to an Account
(by name), marked "not in the CRM", put back to automatic, or
queued as a new Account for Hermes (the website comes from the
email's domain).
- On the live account, 385 customers have billing. None can be
matched until Hermes copies the CRM's Accounts, which waits on the
Core's MCP hub.
4. **The spend log and CAC.**
- Spend by channel and month, entered by hand or imported from CSV.
- Outside tools' spend comes in automatically (origami.chat and