backend-manager 5.0.85 → 5.0.87

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 (40) hide show
  1. package/CLAUDE.md +53 -1
  2. package/package.json +1 -1
  3. package/src/cli/commands/base-command.js +5 -1
  4. package/src/cli/commands/serve.js +1 -2
  5. package/src/manager/cron/daily/ghostii-auto-publisher.js +10 -19
  6. package/src/manager/events/firestore/payments-webhooks/on-write.js +351 -56
  7. package/src/manager/events/firestore/payments-webhooks/transitions/index.js +148 -0
  8. package/src/manager/events/firestore/payments-webhooks/transitions/one-time/purchase-completed.js +16 -0
  9. package/src/manager/events/firestore/payments-webhooks/transitions/one-time/purchase-failed.js +15 -0
  10. package/src/manager/events/firestore/payments-webhooks/transitions/subscription/cancellation-requested.js +15 -0
  11. package/src/manager/events/firestore/payments-webhooks/transitions/subscription/new-subscription.js +18 -0
  12. package/src/manager/events/firestore/payments-webhooks/transitions/subscription/payment-failed.js +15 -0
  13. package/src/manager/events/firestore/payments-webhooks/transitions/subscription/payment-recovered.js +14 -0
  14. package/src/manager/events/firestore/payments-webhooks/transitions/subscription/plan-changed.js +16 -0
  15. package/src/manager/events/firestore/payments-webhooks/transitions/subscription/subscription-cancelled.js +16 -0
  16. package/src/manager/index.js +26 -36
  17. package/src/manager/libraries/{stripe.js → payment-processors/stripe.js} +57 -2
  18. package/src/manager/libraries/payment-processors/test.js +141 -0
  19. package/src/manager/routes/app/get.js +5 -22
  20. package/src/manager/routes/payments/intent/post.js +38 -23
  21. package/src/manager/routes/payments/intent/processors/stripe.js +112 -44
  22. package/src/manager/routes/payments/intent/processors/test.js +139 -76
  23. package/src/manager/routes/payments/webhook/post.js +14 -5
  24. package/src/manager/routes/payments/webhook/processors/stripe.js +75 -9
  25. package/src/manager/schemas/payments/intent/post.js +1 -1
  26. package/src/test/test-accounts.js +10 -1
  27. package/templates/backend-manager-config.json +16 -4
  28. package/test/events/payments/journey-payments-cancel.js +6 -0
  29. package/test/events/payments/journey-payments-failure.js +114 -0
  30. package/test/events/payments/journey-payments-suspend.js +6 -0
  31. package/test/events/payments/journey-payments-trial.js +12 -0
  32. package/test/events/payments/journey-payments-upgrade.js +17 -0
  33. package/test/fixtures/stripe/checkout-session-completed.json +130 -0
  34. package/test/fixtures/stripe/invoice-payment-failed.json +148 -0
  35. package/test/fixtures/stripe/invoice-subscription-payment-failed.json +28 -0
  36. package/test/helpers/stripe-parse-webhook.js +447 -0
  37. package/test/helpers/stripe-to-unified.js +59 -59
  38. package/test/routes/payments/intent.js +3 -3
  39. package/test/routes/payments/webhook.js +2 -2
  40. package/src/manager/libraries/test.js +0 -27
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Test: Stripe toUnified()
2
+ * Test: Stripe toUnifiedSubscription()
3
3
  * Unit tests for the Stripe library's raw subscription → unified subscription transformation
4
4
  *
5
5
  * Tests the pure function directly — no emulator, no Firestore, no HTTP
6
6
  */
7
- const Stripe = require('../../src/manager/libraries/stripe.js');
7
+ const Stripe = require('../../src/manager/libraries/payment-processors/stripe.js');
8
8
 
9
9
  // Real Stripe CLI fixtures (generated via `stripe trigger`)
10
10
  const FIXTURE_ACTIVE = require('../fixtures/stripe/subscription-active.json');
@@ -34,12 +34,12 @@ const MOCK_CONFIG = {
34
34
  },
35
35
  };
36
36
 
37
- function toUnified(rawSubscription, options) {
38
- return Stripe.toUnified(rawSubscription, { config: MOCK_CONFIG, ...options });
37
+ function toUnifiedSubscription(rawSubscription, options) {
38
+ return Stripe.toUnifiedSubscription(rawSubscription, { config: MOCK_CONFIG, ...options });
39
39
  }
40
40
 
41
41
  module.exports = {
42
- description: 'Stripe toUnified() transformation',
42
+ description: 'Stripe toUnifiedSubscription() transformation',
43
43
  type: 'group',
44
44
 
45
45
  tests: [
@@ -48,7 +48,7 @@ module.exports = {
48
48
  {
49
49
  name: 'status-active',
50
50
  async run({ assert }) {
51
- const result = toUnified({ status: 'active' });
51
+ const result = toUnifiedSubscription({ status: 'active' });
52
52
  assert.equal(result.status, 'active', 'Stripe active → unified active');
53
53
  },
54
54
  },
@@ -56,7 +56,7 @@ module.exports = {
56
56
  {
57
57
  name: 'status-trialing',
58
58
  async run({ assert }) {
59
- const result = toUnified({ status: 'trialing', trial_start: 1000, trial_end: 2000 });
59
+ const result = toUnifiedSubscription({ status: 'trialing', trial_start: 1000, trial_end: 2000 });
60
60
  assert.equal(result.status, 'active', 'Stripe trialing → unified active');
61
61
  },
62
62
  },
@@ -64,7 +64,7 @@ module.exports = {
64
64
  {
65
65
  name: 'status-past-due',
66
66
  async run({ assert }) {
67
- const result = toUnified({ status: 'past_due' });
67
+ const result = toUnifiedSubscription({ status: 'past_due' });
68
68
  assert.equal(result.status, 'suspended', 'Stripe past_due → unified suspended');
69
69
  },
70
70
  },
@@ -72,7 +72,7 @@ module.exports = {
72
72
  {
73
73
  name: 'status-unpaid',
74
74
  async run({ assert }) {
75
- const result = toUnified({ status: 'unpaid' });
75
+ const result = toUnifiedSubscription({ status: 'unpaid' });
76
76
  assert.equal(result.status, 'suspended', 'Stripe unpaid → unified suspended');
77
77
  },
78
78
  },
@@ -80,7 +80,7 @@ module.exports = {
80
80
  {
81
81
  name: 'status-canceled',
82
82
  async run({ assert }) {
83
- const result = toUnified({ status: 'canceled' });
83
+ const result = toUnifiedSubscription({ status: 'canceled' });
84
84
  assert.equal(result.status, 'cancelled', 'Stripe canceled → unified cancelled');
85
85
  },
86
86
  },
@@ -88,7 +88,7 @@ module.exports = {
88
88
  {
89
89
  name: 'status-incomplete',
90
90
  async run({ assert }) {
91
- const result = toUnified({ status: 'incomplete' });
91
+ const result = toUnifiedSubscription({ status: 'incomplete' });
92
92
  assert.equal(result.status, 'cancelled', 'Stripe incomplete → unified cancelled');
93
93
  },
94
94
  },
@@ -96,7 +96,7 @@ module.exports = {
96
96
  {
97
97
  name: 'status-incomplete-expired',
98
98
  async run({ assert }) {
99
- const result = toUnified({ status: 'incomplete_expired' });
99
+ const result = toUnifiedSubscription({ status: 'incomplete_expired' });
100
100
  assert.equal(result.status, 'cancelled', 'Stripe incomplete_expired → unified cancelled');
101
101
  },
102
102
  },
@@ -104,7 +104,7 @@ module.exports = {
104
104
  {
105
105
  name: 'status-unknown-defaults-to-cancelled',
106
106
  async run({ assert }) {
107
- const result = toUnified({ status: 'some_future_status' });
107
+ const result = toUnifiedSubscription({ status: 'some_future_status' });
108
108
  assert.equal(result.status, 'cancelled', 'Unknown status → cancelled');
109
109
  },
110
110
  },
@@ -114,7 +114,7 @@ module.exports = {
114
114
  {
115
115
  name: 'product-resolves-monthly-price',
116
116
  async run({ assert }) {
117
- const result = toUnified({ plan: { id: 'price_plus_monthly' } });
117
+ const result = toUnifiedSubscription({ plan: { id: 'price_plus_monthly' } });
118
118
  assert.equal(result.product.id, 'plus', 'Should resolve to plus');
119
119
  assert.equal(result.product.name, 'Plus', 'Should have correct name');
120
120
  },
@@ -123,7 +123,7 @@ module.exports = {
123
123
  {
124
124
  name: 'product-resolves-annual-price',
125
125
  async run({ assert }) {
126
- const result = toUnified({ plan: { id: 'price_pro_annually' } });
126
+ const result = toUnifiedSubscription({ plan: { id: 'price_pro_annually' } });
127
127
  assert.equal(result.product.id, 'pro', 'Should resolve to pro');
128
128
  assert.equal(result.product.name, 'Pro', 'Should have correct name');
129
129
  },
@@ -132,7 +132,7 @@ module.exports = {
132
132
  {
133
133
  name: 'product-resolves-from-items-array',
134
134
  async run({ assert }) {
135
- const result = toUnified({
135
+ const result = toUnifiedSubscription({
136
136
  items: { data: [{ price: { id: 'price_plus_monthly' } }] },
137
137
  });
138
138
  assert.equal(result.product.id, 'plus', 'Should resolve from items.data[0].price.id');
@@ -142,7 +142,7 @@ module.exports = {
142
142
  {
143
143
  name: 'product-falls-back-to-basic-on-unknown-price',
144
144
  async run({ assert }) {
145
- const result = toUnified({ plan: { id: 'price_nonexistent' } });
145
+ const result = toUnifiedSubscription({ plan: { id: 'price_nonexistent' } });
146
146
  assert.equal(result.product.id, 'basic', 'Unknown price → basic');
147
147
  assert.equal(result.product.name, 'Basic', 'Unknown price → Basic name');
148
148
  },
@@ -151,7 +151,7 @@ module.exports = {
151
151
  {
152
152
  name: 'product-falls-back-to-basic-on-missing-plan',
153
153
  async run({ assert }) {
154
- const result = toUnified({});
154
+ const result = toUnifiedSubscription({});
155
155
  assert.equal(result.product.id, 'basic', 'No plan → basic');
156
156
  },
157
157
  },
@@ -159,7 +159,7 @@ module.exports = {
159
159
  {
160
160
  name: 'product-falls-back-to-basic-without-config',
161
161
  async run({ assert }) {
162
- const result = Stripe.toUnified({ plan: { id: 'price_plus_monthly' } }, {});
162
+ const result = Stripe.toUnifiedSubscription({ plan: { id: 'price_plus_monthly' } }, {});
163
163
  assert.equal(result.product.id, 'basic', 'No config → basic');
164
164
  },
165
165
  },
@@ -169,7 +169,7 @@ module.exports = {
169
169
  {
170
170
  name: 'frequency-month',
171
171
  async run({ assert }) {
172
- const result = toUnified({ plan: { interval: 'month' } });
172
+ const result = toUnifiedSubscription({ plan: { interval: 'month' } });
173
173
  assert.equal(result.payment.frequency, 'monthly', 'month → monthly');
174
174
  },
175
175
  },
@@ -177,7 +177,7 @@ module.exports = {
177
177
  {
178
178
  name: 'frequency-year',
179
179
  async run({ assert }) {
180
- const result = toUnified({ plan: { interval: 'year' } });
180
+ const result = toUnifiedSubscription({ plan: { interval: 'year' } });
181
181
  assert.equal(result.payment.frequency, 'annually', 'year → annually');
182
182
  },
183
183
  },
@@ -185,7 +185,7 @@ module.exports = {
185
185
  {
186
186
  name: 'frequency-week',
187
187
  async run({ assert }) {
188
- const result = toUnified({ plan: { interval: 'week' } });
188
+ const result = toUnifiedSubscription({ plan: { interval: 'week' } });
189
189
  assert.equal(result.payment.frequency, 'weekly', 'week → weekly');
190
190
  },
191
191
  },
@@ -193,7 +193,7 @@ module.exports = {
193
193
  {
194
194
  name: 'frequency-day',
195
195
  async run({ assert }) {
196
- const result = toUnified({ plan: { interval: 'day' } });
196
+ const result = toUnifiedSubscription({ plan: { interval: 'day' } });
197
197
  assert.equal(result.payment.frequency, 'daily', 'day → daily');
198
198
  },
199
199
  },
@@ -201,7 +201,7 @@ module.exports = {
201
201
  {
202
202
  name: 'frequency-null-when-missing',
203
203
  async run({ assert }) {
204
- const result = toUnified({});
204
+ const result = toUnifiedSubscription({});
205
205
  assert.equal(result.payment.frequency, null, 'Missing interval → null');
206
206
  },
207
207
  },
@@ -209,7 +209,7 @@ module.exports = {
209
209
  {
210
210
  name: 'frequency-from-items-recurring',
211
211
  async run({ assert }) {
212
- const result = toUnified({
212
+ const result = toUnifiedSubscription({
213
213
  items: { data: [{ price: { recurring: { interval: 'year' } } }] },
214
214
  });
215
215
  assert.equal(result.payment.frequency, 'annually', 'items recurring year → annually');
@@ -221,7 +221,7 @@ module.exports = {
221
221
  {
222
222
  name: 'trial-claimed-when-both-dates-present',
223
223
  async run({ assert }) {
224
- const result = toUnified({ trial_start: 1700000000, trial_end: 1701209600 });
224
+ const result = toUnifiedSubscription({ trial_start: 1700000000, trial_end: 1701209600 });
225
225
  assert.equal(result.trial.claimed, true, 'Both trial dates → claimed');
226
226
  assert.ok(result.trial.expires.timestampUNIX > 0, 'Trial expires should be set');
227
227
  },
@@ -230,7 +230,7 @@ module.exports = {
230
230
  {
231
231
  name: 'trial-not-claimed-when-no-dates',
232
232
  async run({ assert }) {
233
- const result = toUnified({});
233
+ const result = toUnifiedSubscription({});
234
234
  assert.equal(result.trial.claimed, false, 'No trial dates → not claimed');
235
235
  },
236
236
  },
@@ -238,7 +238,7 @@ module.exports = {
238
238
  {
239
239
  name: 'trial-not-claimed-when-only-start',
240
240
  async run({ assert }) {
241
- const result = toUnified({ trial_start: 1700000000 });
241
+ const result = toUnifiedSubscription({ trial_start: 1700000000 });
242
242
  assert.equal(result.trial.claimed, false, 'Only trial_start → not claimed');
243
243
  },
244
244
  },
@@ -246,7 +246,7 @@ module.exports = {
246
246
  {
247
247
  name: 'trial-not-claimed-when-null-dates',
248
248
  async run({ assert }) {
249
- const result = toUnified({ trial_start: null, trial_end: null });
249
+ const result = toUnifiedSubscription({ trial_start: null, trial_end: null });
250
250
  assert.equal(result.trial.claimed, false, 'Null trial dates → not claimed');
251
251
  },
252
252
  },
@@ -257,7 +257,7 @@ module.exports = {
257
257
  name: 'cancellation-pending-when-cancel-at-period-end',
258
258
  async run({ assert }) {
259
259
  const futureTimestamp = Math.floor(Date.now() / 1000) + 86400 * 30;
260
- const result = toUnified({
260
+ const result = toUnifiedSubscription({
261
261
  cancel_at_period_end: true,
262
262
  cancel_at: futureTimestamp,
263
263
  current_period_end: futureTimestamp,
@@ -271,7 +271,7 @@ module.exports = {
271
271
  name: 'cancellation-pending-uses-period-end-when-no-cancel-at',
272
272
  async run({ assert }) {
273
273
  const futureTimestamp = Math.floor(Date.now() / 1000) + 86400 * 30;
274
- const result = toUnified({
274
+ const result = toUnifiedSubscription({
275
275
  cancel_at_period_end: true,
276
276
  current_period_end: futureTimestamp,
277
277
  });
@@ -283,7 +283,7 @@ module.exports = {
283
283
  name: 'cancellation-already-cancelled',
284
284
  async run({ assert }) {
285
285
  const pastTimestamp = Math.floor(Date.now() / 1000) - 86400;
286
- const result = toUnified({
286
+ const result = toUnifiedSubscription({
287
287
  cancel_at_period_end: false,
288
288
  canceled_at: pastTimestamp,
289
289
  });
@@ -295,7 +295,7 @@ module.exports = {
295
295
  {
296
296
  name: 'cancellation-none',
297
297
  async run({ assert }) {
298
- const result = toUnified({
298
+ const result = toUnifiedSubscription({
299
299
  cancel_at_period_end: false,
300
300
  canceled_at: null,
301
301
  });
@@ -309,7 +309,7 @@ module.exports = {
309
309
  name: 'expires-from-period-end',
310
310
  async run({ assert }) {
311
311
  const futureTimestamp = Math.floor(Date.now() / 1000) + 86400 * 30;
312
- const result = toUnified({ current_period_end: futureTimestamp });
312
+ const result = toUnifiedSubscription({ current_period_end: futureTimestamp });
313
313
  assert.ok(result.expires.timestampUNIX > 0, 'Should have expiration');
314
314
  },
315
315
  },
@@ -317,7 +317,7 @@ module.exports = {
317
317
  {
318
318
  name: 'expires-defaults-to-epoch-when-missing',
319
319
  async run({ assert }) {
320
- const result = toUnified({});
320
+ const result = toUnifiedSubscription({});
321
321
  assert.equal(result.expires.timestampUNIX, 0, 'Missing period_end → epoch');
322
322
  },
323
323
  },
@@ -326,7 +326,7 @@ module.exports = {
326
326
  name: 'start-date-from-raw',
327
327
  async run({ assert }) {
328
328
  const startTimestamp = Math.floor(Date.now() / 1000) - 86400 * 30;
329
- const result = toUnified({ start_date: startTimestamp });
329
+ const result = toUnifiedSubscription({ start_date: startTimestamp });
330
330
  assert.ok(result.payment.startDate.timestampUNIX > 0, 'Should have start date');
331
331
  },
332
332
  },
@@ -334,7 +334,7 @@ module.exports = {
334
334
  {
335
335
  name: 'start-date-defaults-to-epoch-when-missing',
336
336
  async run({ assert }) {
337
- const result = toUnified({});
337
+ const result = toUnifiedSubscription({});
338
338
  assert.equal(result.payment.startDate.timestampUNIX, 0, 'Missing start_date → epoch');
339
339
  },
340
340
  },
@@ -344,7 +344,7 @@ module.exports = {
344
344
  {
345
345
  name: 'payment-processor-always-stripe',
346
346
  async run({ assert }) {
347
- const result = toUnified({});
347
+ const result = toUnifiedSubscription({});
348
348
  assert.equal(result.payment.processor, 'stripe', 'Processor should always be stripe');
349
349
  },
350
350
  },
@@ -352,7 +352,7 @@ module.exports = {
352
352
  {
353
353
  name: 'payment-resource-id-from-subscription-id',
354
354
  async run({ assert }) {
355
- const result = toUnified({ id: 'sub_abc123' });
355
+ const result = toUnifiedSubscription({ id: 'sub_abc123' });
356
356
  assert.equal(result.payment.resourceId, 'sub_abc123', 'resourceId should be subscription ID');
357
357
  },
358
358
  },
@@ -360,7 +360,7 @@ module.exports = {
360
360
  {
361
361
  name: 'payment-resource-id-null-when-missing',
362
362
  async run({ assert }) {
363
- const result = toUnified({});
363
+ const result = toUnifiedSubscription({});
364
364
  assert.equal(result.payment.resourceId, null, 'Missing ID → null resourceId');
365
365
  },
366
366
  },
@@ -368,7 +368,7 @@ module.exports = {
368
368
  {
369
369
  name: 'payment-event-metadata-passed-through',
370
370
  async run({ assert }) {
371
- const result = toUnified({}, { eventName: 'customer.subscription.created', eventId: 'evt_123' });
371
+ const result = toUnifiedSubscription({}, { eventName: 'customer.subscription.created', eventId: 'evt_123' });
372
372
  assert.equal(result.payment.updatedBy.event.name, 'customer.subscription.created', 'Event name passed through');
373
373
  assert.equal(result.payment.updatedBy.event.id, 'evt_123', 'Event ID passed through');
374
374
  },
@@ -377,7 +377,7 @@ module.exports = {
377
377
  {
378
378
  name: 'payment-event-metadata-null-when-missing',
379
379
  async run({ assert }) {
380
- const result = toUnified({});
380
+ const result = toUnifiedSubscription({});
381
381
  assert.equal(result.payment.updatedBy.event.name, null, 'Missing event name → null');
382
382
  assert.equal(result.payment.updatedBy.event.id, null, 'Missing event ID → null');
383
383
  },
@@ -389,7 +389,7 @@ module.exports = {
389
389
  name: 'full-active-subscription-shape',
390
390
  async run({ assert }) {
391
391
  const now = Math.floor(Date.now() / 1000);
392
- const result = toUnified({
392
+ const result = toUnifiedSubscription({
393
393
  id: 'sub_full_test',
394
394
  status: 'active',
395
395
  plan: { id: 'price_pro_monthly', interval: 'month' },
@@ -425,7 +425,7 @@ module.exports = {
425
425
  {
426
426
  name: 'empty-subscription-gets-safe-defaults',
427
427
  async run({ assert }) {
428
- const result = toUnified({});
428
+ const result = toUnifiedSubscription({});
429
429
 
430
430
  assert.equal(result.product.id, 'basic', 'Empty → basic product');
431
431
  assert.equal(result.status, 'cancelled', 'Empty → cancelled (no status field)');
@@ -442,7 +442,7 @@ module.exports = {
442
442
  {
443
443
  name: 'fixture-active-status',
444
444
  async run({ assert }) {
445
- const result = toUnified(FIXTURE_ACTIVE);
445
+ const result = toUnifiedSubscription(FIXTURE_ACTIVE);
446
446
  assert.equal(result.status, 'active', 'Real active fixture → active');
447
447
  assert.equal(result.payment.processor, 'stripe', 'Processor is stripe');
448
448
  assert.equal(result.payment.resourceId, FIXTURE_ACTIVE.id, 'resourceId matches fixture ID');
@@ -452,7 +452,7 @@ module.exports = {
452
452
  {
453
453
  name: 'fixture-active-frequency',
454
454
  async run({ assert }) {
455
- const result = toUnified(FIXTURE_ACTIVE);
455
+ const result = toUnifiedSubscription(FIXTURE_ACTIVE);
456
456
  assert.equal(result.payment.frequency, 'monthly', 'Real active fixture → monthly');
457
457
  },
458
458
  },
@@ -460,7 +460,7 @@ module.exports = {
460
460
  {
461
461
  name: 'fixture-active-dates',
462
462
  async run({ assert }) {
463
- const result = toUnified(FIXTURE_ACTIVE);
463
+ const result = toUnifiedSubscription(FIXTURE_ACTIVE);
464
464
  assert.ok(result.expires.timestampUNIX > 0, 'Should have real expiration');
465
465
  assert.ok(result.payment.startDate.timestampUNIX > 0, 'Should have real start date');
466
466
  assert.equal(result.trial.claimed, false, 'No trial on active fixture');
@@ -472,7 +472,7 @@ module.exports = {
472
472
  name: 'fixture-active-product-falls-back',
473
473
  async run({ assert }) {
474
474
  // Fixture price IDs won't match our mock config, so it should fall back to basic
475
- const result = toUnified(FIXTURE_ACTIVE);
475
+ const result = toUnifiedSubscription(FIXTURE_ACTIVE);
476
476
  assert.equal(result.product.id, 'basic', 'Unknown price → basic fallback');
477
477
  },
478
478
  },
@@ -480,7 +480,7 @@ module.exports = {
480
480
  {
481
481
  name: 'fixture-canceled-status',
482
482
  async run({ assert }) {
483
- const result = toUnified(FIXTURE_CANCELED);
483
+ const result = toUnifiedSubscription(FIXTURE_CANCELED);
484
484
  assert.equal(result.status, 'cancelled', 'Real canceled fixture → cancelled');
485
485
  assert.equal(result.cancellation.pending, false, 'Not pending — already cancelled');
486
486
  assert.ok(result.cancellation.date.timestampUNIX > 0, 'Should have cancellation date');
@@ -492,7 +492,7 @@ module.exports = {
492
492
  async run({ assert }) {
493
493
  assert.ok(FIXTURE_CANCELED.ended_at, 'Canceled fixture should have ended_at');
494
494
  assert.ok(FIXTURE_CANCELED.canceled_at, 'Canceled fixture should have canceled_at');
495
- const result = toUnified(FIXTURE_CANCELED);
495
+ const result = toUnifiedSubscription(FIXTURE_CANCELED);
496
496
  assert.equal(result.payment.resourceId, FIXTURE_CANCELED.id, 'resourceId matches');
497
497
  },
498
498
  },
@@ -500,7 +500,7 @@ module.exports = {
500
500
  {
501
501
  name: 'fixture-trialing-status',
502
502
  async run({ assert }) {
503
- const result = toUnified(FIXTURE_TRIALING);
503
+ const result = toUnifiedSubscription(FIXTURE_TRIALING);
504
504
  assert.equal(result.status, 'active', 'Real trialing fixture → active');
505
505
  assert.equal(result.trial.claimed, true, 'Trialing fixture → trial claimed');
506
506
  assert.ok(result.trial.expires.timestampUNIX > 0, 'Trial expiration should be set');
@@ -512,7 +512,7 @@ module.exports = {
512
512
  async run({ assert }) {
513
513
  assert.ok(FIXTURE_TRIALING.trial_start, 'Trialing fixture should have trial_start');
514
514
  assert.ok(FIXTURE_TRIALING.trial_end, 'Trialing fixture should have trial_end');
515
- const result = toUnified(FIXTURE_TRIALING);
515
+ const result = toUnifiedSubscription(FIXTURE_TRIALING);
516
516
  assert.equal(result.cancellation.pending, false, 'No cancellation on trialing fixture');
517
517
  assert.equal(result.payment.frequency, 'monthly', 'Trialing fixture → monthly');
518
518
  },
@@ -525,7 +525,7 @@ module.exports = {
525
525
  const names = ['active', 'canceled', 'trialing'];
526
526
 
527
527
  for (let i = 0; i < fixtures.length; i++) {
528
- const result = toUnified(fixtures[i]);
528
+ const result = toUnifiedSubscription(fixtures[i]);
529
529
  const label = names[i];
530
530
 
531
531
  assert.ok(result.product, `${label}: should have product`);
@@ -549,7 +549,7 @@ module.exports = {
549
549
  name: 'combo-trialing-with-pending-cancel',
550
550
  async run({ assert }) {
551
551
  const now = Math.floor(Date.now() / 1000);
552
- const result = toUnified({
552
+ const result = toUnifiedSubscription({
553
553
  id: 'sub_trial_cancel',
554
554
  status: 'trialing',
555
555
  trial_start: now - 86400 * 3,
@@ -573,7 +573,7 @@ module.exports = {
573
573
  name: 'combo-trial-payment-fails',
574
574
  async run({ assert }) {
575
575
  const now = Math.floor(Date.now() / 1000);
576
- const result = toUnified({
576
+ const result = toUnifiedSubscription({
577
577
  id: 'sub_trial_fail',
578
578
  status: 'incomplete_expired',
579
579
  trial_start: now - 86400 * 14,
@@ -596,7 +596,7 @@ module.exports = {
596
596
  name: 'combo-active-with-past-trial',
597
597
  async run({ assert }) {
598
598
  const now = Math.floor(Date.now() / 1000);
599
- const result = toUnified({
599
+ const result = toUnifiedSubscription({
600
600
  id: 'sub_past_trial',
601
601
  status: 'active',
602
602
  trial_start: now - 86400 * 30,
@@ -619,7 +619,7 @@ module.exports = {
619
619
  name: 'combo-pending-cancel-reactivated',
620
620
  async run({ assert }) {
621
621
  const now = Math.floor(Date.now() / 1000);
622
- const result = toUnified({
622
+ const result = toUnifiedSubscription({
623
623
  id: 'sub_reactivated',
624
624
  status: 'active',
625
625
  cancel_at_period_end: false,
@@ -641,7 +641,7 @@ module.exports = {
641
641
  name: 'combo-suspended-with-pending-cancel',
642
642
  async run({ assert }) {
643
643
  const now = Math.floor(Date.now() / 1000);
644
- const result = toUnified({
644
+ const result = toUnifiedSubscription({
645
645
  id: 'sub_suspended_cancel',
646
646
  status: 'past_due',
647
647
  cancel_at_period_end: true,
@@ -663,7 +663,7 @@ module.exports = {
663
663
  name: 'combo-trialing-past-due',
664
664
  async run({ assert }) {
665
665
  const now = Math.floor(Date.now() / 1000);
666
- const result = toUnified({
666
+ const result = toUnifiedSubscription({
667
667
  id: 'sub_trial_past_due',
668
668
  status: 'past_due',
669
669
  trial_start: now - 86400 * 14,
@@ -56,16 +56,16 @@ module.exports = {
56
56
  },
57
57
 
58
58
  {
59
- name: 'rejects-missing-frequency',
59
+ name: 'rejects-missing-frequency-for-subscription',
60
60
  async run({ http, assert, config }) {
61
- const paidProduct = config.payment.products.find(p => p.id !== 'basic' && p.prices);
61
+ const paidProduct = config.payment.products.find(p => p.id !== 'basic' && p.type === 'subscription' && p.prices);
62
62
 
63
63
  const response = await http.as('basic').post('payments/intent', {
64
64
  processor: 'stripe',
65
65
  productId: paidProduct.id,
66
66
  });
67
67
 
68
- assert.isError(response, 400, 'Should reject missing frequency');
68
+ assert.isError(response, 400, 'Should reject missing frequency for subscription product');
69
69
  },
70
70
  },
71
71
 
@@ -73,8 +73,8 @@ module.exports = {
73
73
  assert.ok(doc, 'Webhook doc should exist in Firestore');
74
74
  assert.equal(doc.processor, 'stripe', 'Processor should be stripe');
75
75
  assert.ok(
76
- doc.status === 'pending' || doc.status === 'processing' || doc.status === 'completed',
77
- 'Status should be pending, processing, or completed',
76
+ doc.status === 'pending' || doc.status === 'processing' || doc.status === 'completed' || doc.status === 'failed',
77
+ 'Status should be pending, processing, completed, or failed',
78
78
  );
79
79
 
80
80
  // Clean up
@@ -1,27 +0,0 @@
1
- const Stripe = require('./stripe.js');
2
-
3
- /**
4
- * Test processor library
5
- * Delegates to Stripe's toUnified() since test processor generates Stripe-shaped data
6
- * Stamps processor as 'test' to distinguish from real Stripe subscriptions
7
- */
8
- const Test = {
9
- /**
10
- * No-op init — test processor doesn't need an external SDK
11
- */
12
- init() {
13
- return null;
14
- },
15
-
16
- /**
17
- * Transform raw subscription into unified shape
18
- * Delegates to Stripe's toUnified (same data shape), stamps processor as 'test'
19
- */
20
- toUnified(rawSubscription, options) {
21
- const unified = Stripe.toUnified(rawSubscription, options);
22
- unified.payment.processor = 'test';
23
- return unified;
24
- },
25
- };
26
-
27
- module.exports = Test;