@vocdoni/skills 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/.claude-plugin/marketplace.json +5 -15
  2. package/CHANGELOG.md +16 -0
  3. package/README.md +31 -20
  4. package/package.json +1 -1
  5. package/plugins/agentic-dev/.claude-plugin/plugin.json +2 -2
  6. package/plugins/agentic-dev/agents/model-router.md +105 -0
  7. package/plugins/agentic-dev/skills/subagent-driven-development/SKILL.md +22 -12
  8. package/plugins/agentic-dev/skills/subagent-driven-development/references/audits.md +20 -13
  9. package/plugins/agentic-dev/skills/subagent-driven-development/references/dispatch.md +37 -1
  10. package/plugins/agentic-dev/skills/subagent-driven-development/references/ledger.md +5 -3
  11. package/plugins/agentic-dev/skills/subagent-driven-development/references/model-catalog.md +118 -0
  12. package/plugins/agentic-dev/skills/subagent-driven-development/references/models.md +93 -70
  13. package/plugins/agentic-dev/skills/subagent-driven-development/scripts/init-workspace.sh +1 -1
  14. package/plugins/agentic-dev/skills/subagent-driven-development/scripts/model-inventory.sh +140 -0
  15. package/plugins/vocdoni-comments/.claude-plugin/plugin.json +2 -2
  16. package/plugins/vocdoni-comments/hooks/hooks.json +28 -0
  17. package/plugins/vocdoni-comments/hooks/session-start.sh +45 -0
  18. package/plugins/vocdoni-contributing/.claude-plugin/plugin.json +3 -2
  19. package/plugins/vocdoni-contributing/hooks/hooks.json +14 -2
  20. package/plugins/vocdoni-contributing/hooks/session-start.sh +18 -6
  21. package/plugins/vocdoni-contributing/skills/contributing/SKILL.md +9 -2
  22. package/plugins/vocdoni-stripe/.claude-plugin/plugin.json +0 -22
  23. package/plugins/vocdoni-stripe/skills/stripe-subscription/SKILL.md +0 -276
  24. package/plugins/vocdoni-stripe/skills/stripe-subscription/references/backend-contract.md +0 -142
  25. package/plugins/vocdoni-stripe/skills/stripe-subscription/references/product-templates.md +0 -132
  26. package/plugins/vocdoni-stripe/skills/stripe-subscription/references/stripe-cli.md +0 -212
  27. package/plugins/vocdoni-stripe/skills/stripe-subscription/scripts/clone-product.sh +0 -247
  28. package/plugins/vocdoni-stripe/skills/stripe-subscription/scripts/stripe-json.sh +0 -223
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: contributing
3
- description: Use whenever starting work on a change in a repository, or writing or posting a pull request or merge request description, an issue, a code review, a review comment or a commit message, or answering review comments on a pull request, on GitHub, GitLab or any other git host, through gh, glab or the web, including as one step of a larger task, and when an epic issue needs several pull requests. Sets how to tie the work to an issue (find one, or open one before the PR), how to stack an epic's PRs on each other with gh stack instead of opening them all against the base branch, how to introduce yourself as the agent acting for the user, length limits and structure for PRs, issues and reviews, how to post a review, and how to reply to and resolve the review threads you address.
3
+ description: Use whenever starting work on a change in a repository, or writing or posting a pull request or merge request description, an issue, a code review, a review comment or a commit message, or answering review comments on a pull request, on GitHub, GitLab or any other git host, through gh, glab or the web, including as one step of a larger task, and when an epic issue needs several pull requests. Sets how to tie the work to an issue (find one, or open one before the PR), how to stack an epic's PRs on each other with gh stack instead of opening them all against the base branch, how to introduce yourself and say whether the user asked for or reviewed the post, length limits and structure for PRs, issues and reviews, how to post a review, and how to reply to and resolve the review threads you address.
4
4
  ---
5
5
 
6
6
  # Contributing
@@ -9,7 +9,14 @@ These rules cover the issue that tracks your work and everything you write on th
9
9
 
10
10
  ## Introduce yourself
11
11
 
12
- Start every PR description, issue, review and comment you post with one line saying which model you are and who you act for, such as "This is {model} speaking on behalf of {owner}." or "{model} here, on behalf of {owner}." `{owner}` is the login of the host CLI's user (`gh api user -q .login`, `glab api user | jq -r .username`), else `git config user.name`. Don't sign off at the end.
12
+ Start every PR description, issue, review and comment you post with one line saying which model you are and how `{owner}` stands behind the post. `{owner}` is the login of the host CLI's user (`gh api user -q .login`, `glab api user | jq -r .username`), else `git config user.name`.
13
+
14
+ - The user asked for this post in their own words in this conversation, or approved its text: "This is {model} speaking on behalf of {owner}."
15
+ - Anything else: "This is {model}, working from {owner}'s account. {owner} has not asked for or reviewed this message."
16
+
17
+ Judge each post separately. When the user asks for a PR, only the PR is asked for: the tracking issue you open for it and your later replies to reviewers are not, so they take the second line. So does anything you post while the user is away (a loop, a scheduled or headless run). Showing the user the text before you post it makes it the first line. If you can't tell which applies, use the second line.
18
+
19
+ <important>Don't sign off at the end.</important>
13
20
 
14
21
  Don't add a `Co-authored-by` trailer for yourself to commits. The person running you answers for the change.
15
22
 
@@ -1,22 +0,0 @@
1
- {
2
- "name": "vocdoni-stripe",
3
- "version": "0.1.1",
4
- "description": "Stripe operations for the Vocdoni SaaS, run through the Stripe CLI (or a Stripe MCP server). Creates subscriptions for existing customers with the org-address metadata the backend needs, clones per-customer Custom / Integrator Starter plan products from the catalog templates, handles discounts and payment collection, and always confirms before writing. Ships an environment-guarding CLI wrapper, a product-cloning script and a verified reference of what the SaaS backend reads from Stripe.",
5
- "author": {
6
- "name": "Vocdoni",
7
- "url": "https://vocdoni.io"
8
- },
9
- "homepage": "https://github.com/vocdoni/skills",
10
- "repository": "https://github.com/vocdoni/skills",
11
- "license": "AGPL-3.0-or-later",
12
- "keywords": [
13
- "claude-code",
14
- "skills",
15
- "vocdoni",
16
- "stripe",
17
- "billing",
18
- "subscriptions",
19
- "saas",
20
- "stripe-cli"
21
- ]
22
- }
@@ -1,276 +0,0 @@
1
- ---
2
- name: stripe-subscription
3
- description: Creates a Stripe subscription for an existing Vocdoni SaaS customer, including per-customer "Custom" and "Integrator Starter" plans cloned from template products, with the org-address metadata the backend needs, an optional discount, and a chosen payment-collection mode. Use this whenever the user wants to give an organization a plan, assign or create a subscription, make a subscription free or discounted, set up a custom or integrator plan for a client, or asks anything about creating subscriptions, coupons, or plan products in Stripe for Vocdoni, even if they only mention a customer email, a product name, or a 0x organization address.
4
- ---
5
-
6
- # Stripe subscription for a Vocdoni org
7
-
8
- You are about to move real money settings on a live billing account. The
9
- workflow below is shaped by mistakes that already happened once: the CLI
10
- silently pointing at a sandbox instead of live, a subscription created for a
11
- customer without a card (it dies `incomplete` after 23 hours), a discount
12
- applied after creation so the first invoice had to be patched by hand, and a
13
- coupon left open for anyone to reuse. Every step exists to make one of those
14
- impossible.
15
-
16
- Work through the phases in order. Never write to Stripe before the user has
17
- confirmed the table in Phase 3.
18
-
19
- ## Phase 0: preflight
20
-
21
- **Tooling.** You need `jq` (the scripts and every cookbook command parse
22
- JSON with it) and one of:
23
-
24
- - The Stripe CLI, installed and with a started session. Check with
25
- `scripts/stripe-json.sh env` (without `STRIPE_ENV` it only reports the
26
- account and mode; the environment is chosen in Phase 1). If it fails it prints what is missing and how
27
- to fix it: install `jq`, install the CLI, `stripe login`, and
28
- `stripe agent setup` to install the Stripe CLI agent skill. Install what
29
- you can yourself (a package manager the user already uses is fine) and ask
30
- the user for anything that needs their credentials or privileges. Do not
31
- continue until it prints a mode.
32
- - A connected Stripe MCP server (tools named `mcp__…stripe…`) with its skill.
33
- The phases are the same; `references/stripe-cli.md` maps every CLI call to
34
- the MCP equivalent and says which calls still need the CLI.
35
-
36
- **Environment.** The environment is an input like any other, collected in
37
- Phase 1 and shown in the confirmation table; do not infer it from what the CLI
38
- happens to be pointing at. Once known, prefix every Stripe command with it and
39
- with the account name `env` printed (`STRIPE_ENV=live STRIPE_ACCOUNT_NAME='…'
40
- scripts/stripe-json.sh …`, same for `clone-product.sh`; the mode alone cannot
41
- tell two live accounts apart):
42
- agent shells usually do not keep an `export` between tool calls, and the
43
- wrapper refuses to run without it rather than guess. Run every Stripe command
44
- through `scripts/stripe-json.sh`, which reads the CLI's own banner to check
45
- the mode and refuses on mismatch. If it reports a mismatch, compare against
46
- the environment the user chose, not against whatever the error suggests. The CLI keeps one active account and a
47
- `stripe switch` in another terminal changes it under you, so run
48
- `scripts/stripe-json.sh env` again right before Phase 4. On mismatch tell the
49
- user to run `! stripe switch` (it is interactive) and re-check.
50
-
51
- **Sandbox is not isolated.** A sandbox account is wired to the dev and
52
- staging backends through its webhook endpoints, so every write there changes
53
- real org records in those backends. List them with
54
- `webhook_endpoints list` and show the enabled URLs in the confirmation table.
55
- When any is enabled, a subscription created for an org address moves that org
56
- to the new plan in each of those backends at once, and canceling or deleting
57
- it afterwards does not bring the previous plan back. Only use an org address
58
- the user has confirmed is disposable in every listed backend, and do not
59
- create "test" subscriptions to clean up later: there is no cleanup.
60
-
61
- Read `references/stripe-cli.md` now for the command cookbook. Read
62
- `references/backend-contract.md` if you need to know why a field matters.
63
-
64
- ## Phase 1: collect the minimum
65
-
66
- Six things are required. Take what the user gave, then ask for the rest in a
67
- single `AskUserQuestion` call (one question per missing item):
68
-
69
- 0. **Environment**: `live` or `sandbox`. Ask unless the user said it; offer
70
- `live` first since that is what a real customer request means, but never
71
- assume it silently. Whatever the answer, it is what `STRIPE_ENV` gets and
72
- what the confirmation table shows.
73
- 1. **Customer**: email (or `cus_…` id). The customer must already exist.
74
- 2. **Org type**: integrator or regular. The new subscription replaces the
75
- org's plan in the backend, and an integrator org is often on
76
- `Integrator Free`, which has no Stripe subscription, so Stripe cannot tell
77
- you. Take it from the user's wording ("integrator", "Integrator Free",
78
- "managed orgs") or from an existing subscription on a product with
79
- `integratorLimits.maxManagedOrgs > 0`; otherwise ask. Never guess regular.
80
- 3. **Product**: a catalog name (`Free`, `Starter`, `Professional`, `Custom`,
81
- `Integrator Starter`, `Integrator Free`) or a `prod_…` id. `Custom` and
82
- `Integrator Starter` are templates and go through Phase 2b. The product
83
- keeps the org's type unless the user explicitly asks to change it: for an
84
- integrator org, "upgrade", "custom plan" or no product at all means a copy
85
- of `Integrator Starter`, never plain `Custom`; for a regular org, `Custom`.
86
- A product of the other type is a type change: show it as such in the
87
- Phase 3 table and only proceed if the user named that product.
88
- 4. **Billing interval**: `yearly` or `monthly` (or a `price_…` id). If the user
89
- said nothing and the product's default price is yearly, propose yearly.
90
- 5. **Organization address**: `0x` + 40 hex chars. It becomes the subscription
91
- metadata key `address`, the only thing linking the subscription to the org
92
- in the backend. A missing or malformed value makes every webhook for that
93
- subscription fail forever, so validate the shape before doing anything
94
- else.
95
-
96
- ## Phase 2: resolve and validate (read-only)
97
-
98
- - **Customer**: `customers list --email <email>`. Exactly one match, or stop
99
- and report what you found. Note name, currency, `invoice_settings.default_payment_method`
100
- and `payment_methods list --customer` (together they decide the collection
101
- default: a card that is attached but not the customer's default is only
102
- charged if you pass it as the subscription's `default_payment_method`).
103
- A customer metadata `address` pointing to another org is not a blocker and
104
- not a sign of the wrong customer (one customer may own several orgs'
105
- subscriptions); note it in the Phase 3 table and leave it untouched.
106
- - **Product and price**: search by name, then filter to the exact name because
107
- search is a substring match and `Custom - someone@…` copies would otherwise
108
- win. Then `prices list --product <id> --active` and pick the recurring price
109
- for the chosen interval. Show amount, currency, nickname.
110
- - **One org, one subscription**: list every non-canceled subscription
111
- (active, trialing, past_due, unpaid, paused, incomplete), every page, and compare `metadata.address` case-insensitively
112
- (see the cookbook; use the list, not search, because search lags by up to a
113
- minute). If one exists,
114
- stop and name it: the user should update or cancel that one instead.
115
- - **Org type matches the product**: read the resolved product's
116
- `integratorLimits`. An integrator org given a product without
117
- `integratorLimits.maxManagedOrgs > 0` (plain `Custom`, `Starter`,
118
- `Professional`) stops being an integrator, and a regular org given an
119
- integrator product becomes one. If that does not match the Phase 1 type
120
- and the user did not name the product explicitly, switch to the matching
121
- template before going further.
122
- - **Customer's other subscriptions**: warn, do not block.
123
- - **Currency**: the price currency must match the customer's currency when the
124
- customer already has one, or Stripe rejects the create.
125
-
126
- ## Phase 2b: template flow (Custom / Integrator Starter)
127
-
128
- The backend reads plan limits from the product's metadata, so a customized
129
- plan needs its own product. Read `references/product-templates.md` and:
130
-
131
- 1. Resolve the template by exact name and show its `organization`, `features`,
132
- `votingTypes` (and `integratorLimits`) blocks as pretty JSON.
133
- 2. Ask what to change: per-block overrides (for example `2FAemail: 10000`), the
134
- yearly/monthly amounts (custom plans are negotiated; default is the template
135
- amount), a short client label for names, and the org email (defaults to the
136
- customer email). Show a before/after of every block you change.
137
- 3. Run `scripts/clone-product.sh … --dry-run` and include its output in the
138
- Phase 3 table so the user sees the exact product and prices to be created.
139
- 4. After confirmation, run it without `--dry-run`. It writes the copy with
140
- `visibility=private`, `orgAddress`, `orgEmail`, `copiedFrom`, `copiedAt`,
141
- creates one price per interval the template has (yearly and/or monthly),
142
- and never sets a default price.
143
- 5. Read the product back and check: all metadata blocks parse as JSON, visibility
144
- is private, one active recurring price per template interval, and for integrator copies
145
- `integratorLimits.maxManagedOrgs > 0`. Then continue with its price.
146
-
147
- ## Phase 3: confirmation table
148
-
149
- Render one table with everything chosen, then everything optional that is
150
- still at its default, and ask a single `AskUserQuestion`: "Create it as shown?"
151
- with options `Yes`, `Change something`. On `Change something`, collect the
152
- change, re-render, ask again. Never proceed on silence or an implicit yes.
153
-
154
- ```
155
- | Setting | Value |
156
- |--------------------|---------------------------------------------------|
157
- | Environment | live · Account Name |
158
- | Backends notified | every enabled webhook endpoint URL |
159
- | Customer | cus_xxx · Client Name · client@example.org |
160
- | Product | prod_xxx · Professional |
161
- | Org plan change | Integrator Free → Professional (not integrator) |
162
- | Price | price_xxx · yearly · 1 890,00 EUR |
163
- | metadata.address | 0x0000000000000000000000000000000000000000 |
164
- | Customer address | 0x… (another org, left untouched) (or: empty) |
165
- | Org billing email | becomes client@example.org (the customer email) |
166
- | --- not defined (defaults) --- |
167
- | Collection | send_invoice, due in 30 days (no card on file) |
168
- | Discount | none |
169
- | Trial | none |
170
- | Start / anchor | now |
171
- | Scheduled cancel | none |
172
- | Description / meta | none |
173
- ```
174
-
175
- What each optional row means and its alternatives:
176
-
177
- - **Collection**. Default `send_invoice` with `days_until_due=30` when the
178
- customer has no default payment method, else `charge_automatically`. If
179
- the customer has saved payment methods but none is the default, ask which
180
- one to charge and pass it as `default_payment_method`; without it Stripe
181
- has nothing to charge and the subscription is left `incomplete`.
182
- Alternatives: the other one, or a **checkout link** (a hosted Checkout
183
- Session the customer pays; Stripe then creates the subscription itself, so
184
- Phase 5 verifies the session instead). `charge_automatically` with no card
185
- needs `payment_behavior=default_incomplete` and the user must know the
186
- subscription expires in 23 hours unless the invoice gets paid.
187
- - **Discount**. Only when the user asks for one. Before creating anything,
188
- look for an existing fit: `coupons list` (valid, same percent/amount and
189
- duration, redemptions left) and, if the user named a code,
190
- `promotion_codes list --active`. Show matches in a small table and let the
191
- user pick one or "create new". Otherwise create a single-use coupon
192
- (`max_redemptions=1`, name tied to the client and reason). Either way it is
193
- passed on the create call through `discounts[0][coupon]` so the first invoice
194
- is already discounted; there is nothing to patch afterwards and nothing to
195
- delete later. If the user does not want a discount, skip the lookup.
196
- - **Trial**: `trial_period_days` or `trial_end`. If the chosen price carries
197
- `freeTrialDays` metadata (copied onto a cloned price from its template),
198
- that metadata alone does not create a Stripe trial — it is read by other
199
- parts of the Vocdoni stack, not by `subscriptions create`. Ask the user
200
- whether this subscription should also get that many days as a real Stripe
201
- trial, or the customer is billed immediately.
202
- - **Start / anchor**: `backdate_start_date`, `billing_cycle_anchor`.
203
- - **Scheduled cancel**: `cancel_at` or `cancel_at_period_end`.
204
- - **Description / extra metadata**: `description`, extra `metadata[...]`.
205
- Never add customer metadata; the backend writes the customer's `address`
206
- itself when it is empty and leaves an existing one alone.
207
-
208
- ## Phase 4: execute
209
-
210
- 1. `scripts/stripe-json.sh env` again. Stop on mismatch.
211
- 2. Template flow: `clone-product.sh` for real, then the read-back checks.
212
- 3. Discount: create the coupon now if a new one was chosen; capture its id.
213
- 4. `subscriptions create` with every chosen flag in one call (or
214
- `checkout sessions create` for the link mode). See the cookbook for the
215
- exact flags.
216
- 5. `send_invoice`: finalize the first invoice right away
217
- (`invoices finalize_invoice`), but only if the create response's
218
- `latest_invoice` exists and is still `draft`. A trial's zero invoice is
219
- already `paid`, and a future `billing_cycle_anchor` may leave no invoice
220
- at all; finalizing those fails after the subscription already exists, so
221
- skip this step instead. A zero-total invoice becomes `paid` on the
222
- spot; a real one gets a `hosted_invoice_url`. Finalizing by hand does not
223
- email it: run `invoices send_invoice` too if the customer should get
224
- Stripe's email. `finalize_invoice` and `send_invoice` each return a
225
- different token in that URL for the same invoice; hand the customer the
226
- one from whichever call you made last (or from the Phase 5 read-back),
227
- not the finalize-time one if you also sent it.
228
-
229
- Destructive CLI commands (`delete`, `delete_*`, `cancel`, `void_invoice`,
230
- `mark_uncollectible`, `detach`) can prompt interactively and hang inside an
231
- agent; the wrapper refuses them without `--confirm`, so always pass it.
232
-
233
- ## Phase 5: verify and report
234
-
235
- Re-read from Stripe; never report from the create response.
236
- `subscriptions retrieve <id> -d expand[0]=discounts -d expand[1]=latest_invoice`
237
- (plus `coupons retrieve` for the discount row, since the discount only
238
- carries the coupon id, and `products retrieve` and `prices list` for a cloned
239
- product) and print:
240
-
241
- ```
242
- | Item | Value |
243
- |-------------------|---------------------------------------------------------|
244
- | Subscription | sub_xxx · active |
245
- | Customer | cus_xxx · Client Name · client@example.org |
246
- | Product | prod_xxx · Professional (or: copy of Custom, private) |
247
- | Price | price_xxx · yearly · 1 890,00 EUR |
248
- | metadata.address | 0x0000000000000000000000000000000000000000 |
249
- | Discount | coupon_xxx · 100% · forever · redeemed 1/1 (or none) |
250
- | First invoice | in_xxx · paid · total 0,00 EUR · hosted URL |
251
- | Collection | send_invoice · due in 30 days |
252
- | Current period | until 2027-01-01 |
253
- | Environment | live |
254
- ```
255
-
256
- Follow with two or three sentences: what happens next (invoice emailed if you
257
- sent it, link to hand over, backend picks a cloned product up on the
258
- `product.updated` webhook fired by its activation, or at the next restart), and anything left at a default the user should know about
259
- (for example, a free subscription still emits zero-value invoices in revenue
260
- reports).
261
-
262
- ## When to stop instead of continuing
263
-
264
- - The environment check fails or flips between phases.
265
- - The customer is missing or ambiguous, the product name matches several
266
- active products, or the address is malformed.
267
- - Another active subscription already carries that address.
268
- - The environment is sandbox, it has enabled webhook endpoints, and the user
269
- has not confirmed the org address is disposable in those backends.
270
- - The org is an integrator and the chosen product is not, and the user has
271
- not confirmed the downgrade.
272
- - The user asked for something this skill does not do: changing an existing
273
- subscription, refunds, cancellations. Say so and offer the CLI command.
274
-
275
- Related: [[stripe-best-practices]] for general Stripe API choices,
276
- [[stripe-docs]] to look up a parameter this skill does not cover.
@@ -1,142 +0,0 @@
1
- # What the SaaS backend reads from Stripe
2
-
3
- Verified against `saas-backend` (`stripe/service.go`, `stripe/webhook.go`,
4
- `stripe/client.go`, `db/plans.go`, `subscriptions/subscriptions.go`) in
5
- September 2026. Re-check the line references if the backend has moved on.
6
-
7
- ## Products are plans
8
-
9
- Stripe is the single source of truth for plans; Mongo `plans` is a cache.
10
-
11
- | Product metadata key | Required | Parsed as | Effect |
12
- | -------------------- | ------------ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
13
- | `organization` | yes (marker) | JSON object | plan limits: `teamMembers`, `subOrgs`, `maxProcesses`, `maxCensus`, `maxVotes`, `maxDaysDuration`, `customURL`, `drafts`, `customPlan` |
14
- | `votingTypes` | yes (marker) | JSON object | `single`, `multiple`, `approval`, `cumulative`, `ranked`, `weighted` |
15
- | `features` | yes (marker) | JSON object | `anonymous`, `overwrite`, `liveResults`, `2FAsms`, `2FAemail`, `personalization`, `emailReminder`, `whiteLabel`, `liveStreaming`, `phoneSupport` |
16
- | `integratorLimits` | no | JSON object | `maxManagedOrgs`; the plan is an integrator plan only when it is `> 0` |
17
- | `visibility` | no | string | exactly `private` hides the plan from `GET /plans`. Nothing else: a private plan is still fetchable by id and usable at checkout |
18
-
19
- - A product missing any of the three marker keys is silently not a plan
20
- (`service.go` `planProductMarkerKeys`, `isPlanProduct`).
21
- - A marker present but not valid JSON makes the product skip with a warning.
22
- - Only **active** products are listed (`client.go` `ListProducts`).
23
- - `orgAddress`, `orgEmail`, `copiedFrom`, `copiedAt` (and the older
24
- `restoredFrom` / `restoredAt` from a one-off migration) are **not read**.
25
- They exist so a human can tell which customer a copy belongs to and where it
26
- came from. Keep writing them.
27
-
28
- ## Prices
29
-
30
- `GetProductPrices` lists **active** prices of the product. In
31
- `processProductToPlan`:
32
-
33
- - recurring interval `year` becomes the yearly price and amount, `month` the
34
- monthly ones; other intervals and one-time prices are ignored;
35
- - if several prices share an interval the last one listed wins, so keep one
36
- active price per interval on a plan product;
37
- - yearly price metadata `freeTrialDays` (integer) is honoured;
38
- - the catalog **default plan** marker is `Default=true` on the metadata of the
39
- product's `default_price`. Never set a default price on a per-customer copy.
40
-
41
- Lookup keys are not used: the "lookup key" in the checkout endpoint is the
42
- product id.
43
-
44
- ## Subscriptions
45
-
46
- The only subscription metadata key read is **`address`**
47
- (`webhook.go` `parseSubscriptionFromEvent`). It is parsed with
48
- `common.HexToAddress`, so matching is case-insensitive and the `0x` prefix is
49
- optional; garbage silently becomes the zero address.
50
-
51
- On `customer.subscription.*` events:
52
-
53
- - missing/zero address: error `subscription missing address metadata`;
54
- - address with no organization: error `organization … not found`;
55
- - product not in the plan cache: error `plan with Stripe ID … not found`.
56
-
57
- Every error returns HTTP 500 to Stripe, the event is not marked processed, and
58
- Stripe retries it for days. So a wrong address is not "no-op", it is a
59
- permanently failing webhook.
60
-
61
- On success the org gets `PlanID`, `StripeSubscriptionID`, `BillingPeriod`,
62
- `StartDate`, `RenewalDate`, `Active` (only when status is `active`) and
63
- `Email` (the Stripe customer email).
64
-
65
- The previous plan is overwritten, not stacked or remembered. That includes a
66
- plan the org holds with no Stripe subscription behind it (the free integrator
67
- plan assigned at `integrator: true` creation), and a later cancel or delete of
68
- the new subscription does not restore it. Every endpoint subscribed to the
69
- account applies this, so a sandbox subscription rewrites the org in dev and
70
- staging alike.
71
-
72
- ## Customers
73
-
74
- The subscription metadata `address` is the only link between a subscription
75
- and an org. The customer's metadata `address` is never read to route a
76
- subscription; one Stripe customer may own subscriptions for several orgs.
77
-
78
- After saving the org, the handler stamps the **customer** metadata `address`
79
- with the org address, but only when it is empty. What happens when it is
80
- already set depends on the backend version:
81
-
82
- - `main` (since dd58581, #704; not in a release tag yet): it logs
83
- "customer metadata address mismatch" if the value differs and carries on.
84
- The webhook succeeds and the existing value is left untouched.
85
- - v3.1.2 and older: it returns an error when the customer has any `address`,
86
- even the same one. The org was already saved, so the data is correct, but
87
- Stripe gets a 500 and retries the event. Noisy in webhook logs, harmless
88
- for data; mention it if the user wonders about failing webhooks.
89
-
90
- Either way, do not set customer metadata `address` by hand, before or after
91
- creating the subscription, and do not treat an existing value pointing to
92
- another org as a sign of the wrong customer.
93
-
94
- The org's subscription `Email` is always overwritten with the Stripe customer
95
- email, so a customer email that differs from the org manager's replaces it.
96
-
97
- ## How a new product reaches the backend
98
-
99
- - On startup the backend syncs every active plan product (`InitializeStripeService`);
100
- a failure is logged, not fatal.
101
- - At runtime it reacts to `product.created`, `product.updated`,
102
- `product.deleted` webhooks (`handleProductUpsert`, `handleProductDelete`).
103
- It re-fetches the product to expand `default_price`. A product that goes
104
- inactive or loses a marker is removed from the cache.
105
- - `price.*` events are **not** handled. Create prices before the last product
106
- update, or touch the product afterwards (`clone-product.sh` does this).
107
-
108
- So a product created by hand shows up immediately only if the live webhook
109
- endpoint subscribes to `product.*`; otherwise at the next backend restart.
110
-
111
- ## Integrator plans
112
-
113
- `Subscriptions.IsIntegrator` is true when the org has its own
114
- `IntegratorLimits.MaxManagedOrgs > 0`, or when its subscription is active and
115
- the plan's `IntegratorLimits.MaxManagedOrgs > 0`. Name is irrelevant.
116
-
117
- **The free integrator plan is found structurally**, nothing else:
118
- `db/plans.go` `FreeIntegratorPlan` does a `FindOne` on
119
- `integratorLimits.maxManagedOrgs > 0 AND monthlyPrice == 0 AND yearlyPrice == 0`.
120
- No env var, config key or product id is involved at runtime (the
121
- `STRIPE_FREE_INTEGRATOR_PRODUCT_ID` variable and the hardcoded id in
122
- migration 0014 only rewrite old integer plan ids once, at migration time).
123
- `Integrator Starter` and `Custom` are not referenced anywhere in code either;
124
- every plan is generic.
125
-
126
- Consequences:
127
-
128
- - An org created with `integrator: true` (`POST /organizations`) fails with
129
- `404` code `40023` "subscription plan not found: free integrator plan not
130
- available" when no such plan exists, and nothing is persisted. Creating an
131
- active product with the three markers, `integratorLimits.maxManagedOrgs > 0`
132
- and either no recurring prices or zero-amount ones fixes it with no code
133
- change; `visibility=private` keeps it out of the catalog.
134
- - `FindOne` has no ordering, so two matching plans make the choice random.
135
- Never put `integratorLimits` on the default `Free` plan, and never let an
136
- integrator product be active while it still has no prices (a paid
137
- `Integrator Starter` copy with zero prices matches the selector).
138
- `clone-product.sh` creates copies inactive and activates them after their
139
- prices exist for this reason.
140
- - `DefaultPlan()` (the `Default=true` default-price marker on the `Free`
141
- product) is checked before the integrator branch for every org creation,
142
- so a broken default plan fails all signups with `400` code `40022`.
@@ -1,132 +0,0 @@
1
- # Per-customer plan products (Custom / Integrator Starter)
2
-
3
- ## Why a product per customization
4
-
5
- The backend reads every plan limit from the product's metadata (see
6
- `backend-contract.md`). Two customers with different limits therefore need two
7
- products. The catalog keeps one **template** per family:
8
-
9
- | Template name | Family | Distinguishing metadata |
10
- | -------------------- | ------------------------------------------------- | ----------------------------------------- |
11
- | `Custom` | high-limit plan negotiated per client | `customPlan: true` inside `organization` |
12
- | `Integrator Starter` | integrators managing orgs for their own customers | `integratorLimits: {"maxManagedOrgs": N}` |
13
-
14
- A customer copy is a new product named `<Template> - <org email>`, private,
15
- carrying the template's blocks with the agreed changes, plus these human-only
16
- keys:
17
-
18
- | Key | Value | Purpose |
19
- | ------------ | ----------------------- | ---------------------------------------------------------- |
20
- | `visibility` | `private` | keep it out of the public catalog (backend reads this one) |
21
- | `orgAddress` | the org's `0x…` address | find the copy from the org |
22
- | `orgEmail` | the org/customer email | find the copy from the customer |
23
- | `copiedFrom` | template `prod_…` id | trace where the limits came from |
24
- | `copiedAt` | ISO-8601 UTC timestamp | when it was cloned |
25
-
26
- Older copies may carry `restoredFrom` / `restoredAt` instead of
27
- `copiedFrom` / `copiedAt`; those came from a one-off migration. Write the
28
- `copied*` pair for new copies and leave old ones alone.
29
-
30
- ## Resolving the template
31
-
32
- Search is a substring match, so `name:'Custom'` also returns every
33
- `Custom - client@example.org`. Always filter to the exact name and require
34
- exactly one active hit:
35
-
36
- ```bash
37
- $sj products search --limit 100 --query "active:'true' AND name:'Custom'" \
38
- | jq '[.data[] | select(.name == "Custom")] | if length == 1 then .[0] else error("expected one template, got \(length)") end'
39
- ```
40
-
41
- Show the user the template's blocks pretty-printed before asking for changes:
42
-
43
- ```bash
44
- jq '.metadata | {organization: (.organization | fromjson), features: (.features | fromjson), votingTypes: (.votingTypes | fromjson), integratorLimits: ((.integratorLimits // "null") | fromjson)}'
45
- ```
46
-
47
- ## What to ask the user
48
-
49
- - **Overrides** per block, as key/value changes (e.g. "2FAemail to 10000",
50
- "maxCensus 80000", "whiteLabel true"). Keys must exist on the template; the
51
- script refuses unknown block names and unknown top-level keys inside a
52
- block, since the backend would silently ignore them. Check the spelling
53
- with the user before the dry run rather than after it refuses.
54
- - **Prices**: yearly and monthly amounts in cents. Default is the template
55
- amount; custom plans are negotiated, so ask rather than assume.
56
- - **Label**: short client name used in price nicknames
57
- (`Custom yearly (Client)`), so the price list stays readable.
58
- - **Org email**: defaults to the customer email; it becomes part of the
59
- product name.
60
-
61
- Write the overrides to a JSON file keyed by block:
62
-
63
- ```json
64
- { "features": { "2FAemail": 10000 }, "organization": { "maxCensus": 80000 } }
65
- ```
66
-
67
- ## Clone
68
-
69
- ```bash
70
- scripts/clone-product.sh \
71
- --template "Custom" \
72
- --org-email client@example.org \
73
- --org-address 0x0000000000000000000000000000000000000000 \
74
- --label "Client" \
75
- --override-file overrides.json \
76
- --yearly 100000 --monthly 10000 \
77
- --dry-run # first: paste the output into the confirmation table
78
- ```
79
-
80
- Without `--dry-run` it prints `{"product": "prod_…", "name": "…", "prices": {"year": "price_…", "month": "price_…"}}`.
81
-
82
- What the script does, in order, and why:
83
-
84
- 1. Reads the template and checks the three marker blocks parse as JSON.
85
- 2. Deep-merges the overrides into each block and re-serialises compactly.
86
- 3. `products create`, **inactive**, with name, description
87
- (`<template description> Custom copy of <template id> for <label> (<email>).`),
88
- the merged blocks and the keys above. No `default_price`: the catalog
89
- default marker lives on a default price's metadata and a copy must never
90
- become the default plan. Inactive because the backend syncs active
91
- products on `product.created`, and an integrator product synced before
92
- its prices exist has zero prices, which is exactly what the backend's
93
- free-integrator selector matches. An integrator signing up in that window
94
- would land on the client's plan.
95
- 4. One `prices create` per template interval (year, month), interval count,
96
- currency, amount and `tax_behavior` from the template unless overridden, nickname
97
- `<Template> yearly|monthly (<label>)`, and `freeTrialDays` copied if the
98
- template's price had it. It refuses a template with more than one active
99
- price per interval (the backend keeps the last one listed, so which to copy
100
- is ambiguous), a price with no `unit_amount` unless you pass the amount,
101
- and an integrator copy whose prices are all zero (it would compete with
102
- the free integrator plan).
103
- 5. `products update … active=true`: the product becomes visible to the
104
- backend only now, with both prices, through the `product.updated` webhook
105
- it listens to (`price.*` events are ignored).
106
-
107
- ## Verify the copy before using it
108
-
109
- ```bash
110
- $sj products retrieve prod_xxx | jq '{
111
- name, active, visibility: .metadata.visibility, copiedFrom: .metadata.copiedFrom, copiedAt: .metadata.copiedAt,
112
- orgAddress: .metadata.orgAddress, default_price,
113
- blocks_ok: ([.metadata.organization, .metadata.features, .metadata.votingTypes] | map(fromjson | type == "object") | all),
114
- managedOrgs: ((.metadata.integratorLimits // "{}") | fromjson | .maxManagedOrgs)
115
- }'
116
- $sj prices list --product prod_xxx --active | jq '[.data[] | {id, nickname, unit_amount, currency, interval: .recurring.interval}]'
117
- ```
118
-
119
- Expect: `active: true`, `visibility: "private"`, `default_price: null`,
120
- `blocks_ok: true`, exactly one price per interval, and for an integrator copy
121
- `managedOrgs > 0`.
122
-
123
- ## Undo
124
-
125
- Archive rather than delete, so invoices that reference the prices stay valid:
126
-
127
- ```bash
128
- $sj products update prod_xxx -d active=false
129
- ```
130
-
131
- The backend drops an inactive product from its plan cache on the next
132
- `product.updated` webhook or restart.