Commit 319a675
authored
fix(billing): stop the webhook from forcing free on an unresolvable price (#3974)
* fix(billing): stop the webhook from forcing free on an unresolvable price
customer.subscription.{updated,created} and invoice.payment_succeeded
resolved an unmappable Stripe price (no config.stripe.prices entry AND
no valid metadata.planId — e.g. a manually-sold enterprise price) to a
hardcoded 'free' fallback, silently downgrading a paying org on the
next webhook delivery. #3964 fixed the same defect on the admin
(409 abort) and reconcile (skip-comparison) call sites but explicitly
left the webhook's fallback in place, since a webhook cannot abort
mid-flight.
resolvePlan now retains the org/subscription's already-loaded current
plan on an unresolvable price instead of forcing 'free', and emits
billing.webhook.plan_unresolved (mirrors the billing.refund.unresolved
alert pattern already used in this file) so ops can review. Only a
subscription with zero prior plan reference anywhere (a genuinely new
org/customer) still defaults to 'free' — the least-harmful default for
a fresh signup. A genuinely-free priceId/metadata mapping still
resolves 'free' normally, unaffected.
Closes #3970
Claude-Session: https://claude.ai/code/session_01WfNC8bt1TgL4AsiYgCEGup
* fix(billing): wire the plan_unresolved ops alert listener
billing.webhook.plan_unresolved (#3970) was emitted from
billing.webhook.service.js but had no billingEvents.on() listener —
EventEmitter.emit silently no-ops with zero listeners, so the
manual-review alert never reached the ops/ntfy channel. Registers the
listener in billing.init.js mirroring the billing.refund.unresolved /
billing.reconciliation.divergence pattern exactly (logger.error with
ntfyPriority: 4 — same "manual review" priority as those two siblings).
Adds the matching unit test case.
Claude-Session: https://claude.ai/code/session_01WfNC8bt1TgL4AsiYgCEGup1 parent 82b5cf0 commit 319a675
8 files changed
Lines changed: 280 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
237 | 253 | | |
238 | 254 | | |
239 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
69 | 79 | | |
| 80 | + | |
| 81 | + | |
70 | 82 | | |
71 | 83 | | |
72 | | - | |
73 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
74 | 112 | | |
75 | 113 | | |
76 | 114 | | |
| |||
369 | 407 | | |
370 | 408 | | |
371 | 409 | | |
372 | | - | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
373 | 414 | | |
374 | 415 | | |
375 | 416 | | |
| |||
407 | 448 | | |
408 | 449 | | |
409 | 450 | | |
410 | | - | |
411 | 451 | | |
412 | 452 | | |
413 | 453 | | |
| |||
633 | 673 | | |
634 | 674 | | |
635 | 675 | | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
636 | 679 | | |
637 | 680 | | |
638 | 681 | | |
639 | 682 | | |
640 | 683 | | |
641 | 684 | | |
642 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
643 | 688 | | |
644 | 689 | | |
645 | 690 | | |
| |||
649 | 694 | | |
650 | 695 | | |
651 | 696 | | |
652 | | - | |
653 | | - | |
654 | 697 | | |
655 | 698 | | |
656 | 699 | | |
| |||
1120 | 1163 | | |
1121 | 1164 | | |
1122 | 1165 | | |
1123 | | - | |
1124 | 1166 | | |
1125 | 1167 | | |
1126 | 1168 | | |
| |||
1145 | 1187 | | |
1146 | 1188 | | |
1147 | 1189 | | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
1148 | 1194 | | |
1149 | 1195 | | |
1150 | 1196 | | |
| |||
1179 | 1225 | | |
1180 | 1226 | | |
1181 | 1227 | | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
1182 | 1231 | | |
1183 | 1232 | | |
1184 | 1233 | | |
| |||
1197 | 1246 | | |
1198 | 1247 | | |
1199 | 1248 | | |
1200 | | - | |
1201 | 1249 | | |
1202 | 1250 | | |
1203 | 1251 | | |
| |||
Lines changed: 54 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| 94 | + | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
| |||
249 | 251 | | |
250 | 252 | | |
251 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
252 | 303 | | |
253 | 304 | | |
254 | 305 | | |
| |||
259 | 310 | | |
260 | 311 | | |
261 | 312 | | |
| 313 | + | |
262 | 314 | | |
263 | 315 | | |
264 | 316 | | |
265 | | - | |
266 | | - | |
| 317 | + | |
| 318 | + | |
267 | 319 | | |
268 | 320 | | |
269 | 321 | | |
| |||
Lines changed: 10 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
300 | | - | |
301 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
302 | 303 | | |
| 304 | + | |
303 | 305 | | |
304 | 306 | | |
305 | 307 | | |
| |||
316 | 318 | | |
317 | 319 | | |
318 | 320 | | |
319 | | - | |
| 321 | + | |
320 | 322 | | |
321 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
322 | 329 | | |
323 | 330 | | |
324 | 331 | | |
| |||
0 commit comments