@yaks/stripe 0.0.0-stage → 0.2.36

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.
package/plans.js ADDED
@@ -0,0 +1,463 @@
1
+ // What Stripe sells a party as @yaks/host's `Plans`: a customer minted once,
2
+ // a subscription bought through Checkout and managed in the customer portal,
3
+ // its trial moved to give time free, a one-off Checkout in payment mode for
4
+ // something paid for once, and the events Stripe posts about either read into
5
+ // the host's words (`changed`, which ./doors.ts hears them with).
6
+ //
7
+ // Checkout runs under Managed Payments: Stripe is the merchant of record, so
8
+ // it sells, collects and remits the tax, and the parameters it controls
9
+ // (automatic_tax, payment_method_types, tax_id_collection, customer_update,
10
+ // invoice_creation) must not be sent at all, so none of them appear below.
11
+ // A plan paid by invoice (`invoice`) cannot be: Managed Payments covers no
12
+ // subscription made outside Checkout, so on those the account itself is the
13
+ // seller. Its invoices take whatever the account's invoice settings allow
14
+ // (card, bank transfer), and a check is marked paid in the Dashboard. Stripe
15
+ // calls such a subscription `active` before anything is paid, so its status is
16
+ // read with its latest invoice (`statusOf`), and it holds no plan until its
17
+ // first period is paid for.
18
+ //
19
+ // Which tier a subscription buys is read off its price, never off metadata a
20
+ // checkout wrote: a plan changed in the portal moves the price and nothing
21
+ // else. A price a tier no longer sells but keeps (`kept`), because a raise
22
+ // leaves its subscribers on what they signed up for, still buys that tier. A
23
+ // paying price no tier lists buys the first tier the options name, so a
24
+ // subscription made before a later tier existed reads as it did.
25
+ import { ask, found, idOf, list, minimum } from "./mod.js";
26
+ import { checkout } from "./checkout.js";
27
+ import { addOnPrice, invoiceMethods, invoiceOnce } from "./invoices.js";
28
+ import { refund } from "./refunds.js";
29
+ // `past_due` keeps the plan on purpose: Stripe retries a failed card for days
30
+ // before it gives up, and taking somebody's apps away on the first decline is
31
+ // the wall T-32756 says not to build. When Stripe does give up the status
32
+ // becomes `canceled` or `unpaid`. `incomplete` is a subscription whose first
33
+ // payment has not come. Stripe never moves a subscription out of `canceled`
34
+ // or `incomplete_expired`, which is what makes `ended` final.
35
+ let STANDING = {
36
+ active: 'paying',
37
+ trialing: 'paying',
38
+ past_due: 'owing',
39
+ incomplete: 'awaiting',
40
+ canceled: 'ended',
41
+ incomplete_expired: 'ended'
42
+ };
43
+ /// standing('trialing') -> 'paying'
44
+ /// standing('incomplete') -> 'awaiting'
45
+ /// standing('unpaid') -> 'lapsed'
46
+ /** Where a subscription with this status stands. */ export let standing = (status)=>Object.hasOwn(STANDING, status) ? STANDING[status] : 'lapsed';
47
+ /// when(0) -> '1970-01-01T00:00:00.000Z'
48
+ /// when(null) -> null
49
+ /** A Stripe time, in seconds, as an ISO date. */ export let when = (unix)=>unix == null ? null : new Date(unix * 1000).toISOString();
50
+ /** When the paid-for period runs out. The field moved off the subscription
51
+ * onto each of its items in API version 2025-03-31.basil, and the webhook
52
+ * endpoint pins no version of its own, so the version it sends can move under
53
+ * us. Either shape is read: the latest item wins, since a subscription of
54
+ * these has one item. */ export let periodEnd = (sub)=>{
55
+ if (sub.current_period_end != null) return sub.current_period_end;
56
+ let ends = (sub.items?.data ?? []).map((i)=>i.current_period_end).filter((n)=>typeof n == 'number');
57
+ return ends.length ? Math.max(...ends) : null;
58
+ };
59
+ /** When the current period began, read off either shape as `periodEnd`
60
+ * reads its end. */ export let periodStart = (sub)=>{
61
+ if (sub.current_period_start != null) return sub.current_period_start;
62
+ let starts = (sub.items?.data ?? []).map((i)=>i.current_period_start).filter((n)=>typeof n == 'number');
63
+ return starts.length ? Math.max(...starts) : null;
64
+ };
65
+ /** Stripe's status for a subscription, with an invoiced one's invoice read
66
+ * into it. Stripe calls a subscription sent its invoices `active` the moment
67
+ * it is made and `past_due` once an invoice is late, and neither is a plan
68
+ * paid for. Its first billed period, the one starting when it was made or
69
+ * when its trial ends, holds once that period's invoice is paid: until then
70
+ * it is `incomplete`, as Stripe says of a charged subscription whose first
71
+ * payment has not come, and a trial given free (`trialFor`) is no payment.
72
+ * A later period holds while its invoice is not yet due, and one past due is
73
+ * `unpaid`: nothing retries a check. The latest invoice is read only where it
74
+ * was expanded, and one that was not is taken as unpaid. */ export let statusOf = (sub)=>{
75
+ let status = sub.status ?? '';
76
+ if (sub.collection_method != 'send_invoice') return status;
77
+ if (status == 'past_due') return 'unpaid';
78
+ if (status != 'active' && status != 'trialing') return status;
79
+ let bill = typeof sub.latest_invoice == 'object' ? sub.latest_invoice : null;
80
+ let paid = bill?.status == 'paid' && (bill.total ?? 0) > 0;
81
+ let first = (periodStart(sub) ?? 0) <= (sub.trial_end ?? sub.start_date ?? sub.created ?? 0);
82
+ return first && !paid ? 'incomplete' : status;
83
+ };
84
+ /** The tier a subscription's price buys: the first of `prices` listing one of
85
+ * its items' prices, else the first of `kept` listing one, else the first of
86
+ * `prices`. */ export let tierFor = (sub, { prices = {}, kept = {} } = {})=>{
87
+ let bought = (sub.items?.data ?? []).map((i)=>idOf(i.price));
88
+ let buys = (ids = [])=>ids.some((p)=>!!p && bought.includes(p));
89
+ let found = Object.entries(prices).find(([, by])=>buys(Object.values(by))) ?? Object.entries(kept).find(([, ids])=>buys(ids));
90
+ return found?.[0] ?? Object.keys(prices)[0] ?? '';
91
+ };
92
+ /** When a subscription with this status stops, set only when it will not
93
+ * renew, so "cancelled, but paid through the 14th" is one row to read: an
94
+ * explicit `cancel_at`, else the period end it is riding out, else, for one
95
+ * already over, when it ended. */ export let ending = (sub, status)=>{
96
+ let end = periodEnd(sub);
97
+ return when(sub.cancel_at ?? (sub.cancel_at_period_end ? end : null) ?? (standing(status) == 'ended' ? sub.ended_at ?? sub.canceled_at ?? end : null));
98
+ };
99
+ let cadence = (sub, tier, pricing)=>{
100
+ let prices = pricing?.prices?.[tier];
101
+ let items = sub.items?.data ?? [];
102
+ let known = items.find(({ price })=>idOf(price) == prices?.month || idOf(price) == prices?.year);
103
+ let id = idOf(known?.price);
104
+ if (id && id == prices?.year) return 'year';
105
+ if (id && id == prices?.month) return 'month';
106
+ let [only] = items;
107
+ let interval = items.length == 1 && typeof only.price == 'object' ? only.price?.recurring?.interval : undefined;
108
+ if (interval == 'month' || interval == 'year') return interval;
109
+ };
110
+ /** A Stripe subscription in the host's words. */ export let read = (sub, pricing)=>{
111
+ let status = statusOf(sub);
112
+ let tier = tierFor(sub, pricing);
113
+ let per = cadence(sub, tier, pricing);
114
+ return {
115
+ id: sub.id ?? '',
116
+ payer: idOf(sub.customer),
117
+ tier,
118
+ ...per ? {
119
+ per
120
+ } : {},
121
+ status,
122
+ until: when(periodEnd(sub)),
123
+ ending: ending(sub, status),
124
+ tags: {
125
+ ...sub.metadata
126
+ }
127
+ };
128
+ };
129
+ /** The trial a subscription bought while time given free runs starts with,
130
+ * so the free time is kept and the first charge falls when it ends. Stripe
131
+ * takes a trial ending no sooner than two days away, so one ending sooner is
132
+ * two days. */ export let trialFor = (free, now)=>free ? {
133
+ trial_end: Math.floor(Math.max(Date.parse(free), now + 49 * 60 * 60_000) / 1000)
134
+ } : {};
135
+ // What a Stripe object was tagged with: its own metadata, over the copy of
136
+ // its subscription's an invoice carries under `parent`.
137
+ let tagsOf = (o)=>{
138
+ let parent = o.parent;
139
+ return {
140
+ ...parent?.subscription_details?.metadata,
141
+ ...o.metadata
142
+ };
143
+ };
144
+ /** The tax code a one-off purchase is sold under: artificial intelligence as
145
+ * a service, cloud based, for business use, which Managed Payments takes
146
+ * (its eligibility page). A product made inline carries its own. */ export let ONCE_TAX = 'txcd_10105002';
147
+ let path = (subscription)=>`/v1/subscriptions/${encodeURIComponent(subscription)}`;
148
+ // A subscription with its latest invoice, which an invoiced one is read by.
149
+ let EXPAND = {
150
+ expand: [
151
+ 'latest_invoice'
152
+ ]
153
+ };
154
+ let expanded = (subscription)=>`${path(subscription)}?expand[]=latest_invoice`;
155
+ /** Stripe's plans, every call made with `options` as they read at the
156
+ * time. */ export let plans = (options)=>{
157
+ let now = ()=>options.clock?.now() ?? Date.now();
158
+ let invoicing = ()=>({
159
+ key: options.invoiceKey,
160
+ clock: options.clock
161
+ });
162
+ let price = (tier, per)=>options.prices?.[tier]?.[per];
163
+ let subscription = async (id)=>{
164
+ let sub = await found(options, expanded(id));
165
+ return sub && read(sub, options);
166
+ };
167
+ let charges = async (id)=>{
168
+ let sub = await ask(options, path(id));
169
+ let end = Math.max(sub.trial_end ?? 0, periodEnd(sub) ?? 0);
170
+ return end ? new Date(end * 1000).toISOString() : null;
171
+ };
172
+ return {
173
+ on: ()=>!!options.key,
174
+ offers: (tier, per)=>!!options.key && !!price(tier, per),
175
+ standing,
176
+ payer: async ({ email, name, tags, key })=>{
177
+ let made = await ask(options, '/v1/customers', {
178
+ email,
179
+ name,
180
+ metadata: tags
181
+ }, undefined, 'POST', key);
182
+ let customer = String(made.id ?? '');
183
+ if (!customer) throw new Error('stripe made a customer with no id');
184
+ return customer;
185
+ },
186
+ billed: async (payer)=>{
187
+ let c = await ask(options, `/v1/customers/${encodeURIComponent(payer)}`);
188
+ return c.deleted ? null : {
189
+ email: String(c.email ?? ''),
190
+ name: String(c.name ?? '')
191
+ };
192
+ },
193
+ checkout: async (asked)=>{
194
+ let bought = price(asked.tier, asked.per);
195
+ if (!bought) {
196
+ throw new Error(`stripe has no price for ${asked.tier} by the ${asked.per}`);
197
+ }
198
+ // Everything here survives Managed Payments, verified against the
199
+ // account rather than assumed: the reference rides
200
+ // `client_reference_id` for the session and the tags ride
201
+ // `subscription_data[metadata]` for the subscription, which every later
202
+ // `customer.subscription.*` event is read by. `allow_promotion_codes`
203
+ // puts the code box on Stripe's page, the only place one belongs, since
204
+ // Stripe is the seller and owns the price it charges.
205
+ return await checkout(options, asked, {
206
+ mode: 'subscription',
207
+ customer: asked.payer,
208
+ line_items: {
209
+ 0: {
210
+ price: bought,
211
+ quantity: 1
212
+ }
213
+ },
214
+ success_url: asked.done,
215
+ cancel_url: asked.cancel,
216
+ client_reference_id: asked.reference,
217
+ metadata: asked.tags,
218
+ subscription_data: {
219
+ metadata: asked.tags,
220
+ ...trialFor(asked.trial, now())
221
+ },
222
+ managed_payments: {
223
+ enabled: true
224
+ },
225
+ allow_promotion_codes: true
226
+ });
227
+ },
228
+ // A subscription sent its invoices rather than charged, made here and not
229
+ // at Checkout: the invoices go to the customer's email, so the address
230
+ // asked for becomes the customer's, and its name the organization's
231
+ // where one is given. No payment method is named, so the invoice offers
232
+ // what the account's invoice settings do. Stripe finalizes the first
233
+ // invoice within the hour and emails it; each renewal's is sent the day
234
+ // the period turns, due `due` days on. It is answered with its first
235
+ // invoice, unpaid, so it reads as awaiting it (`statusOf`).
236
+ invoice: async (asked)=>{
237
+ let bought = price(asked.tier, asked.per);
238
+ if (!bought) {
239
+ throw new Error(`stripe has no price for ${asked.tier} by the ${asked.per}`);
240
+ }
241
+ await ask(options, `/v1/customers/${encodeURIComponent(asked.payer)}`, {
242
+ email: asked.to.email,
243
+ name: asked.to.name || undefined
244
+ });
245
+ let addOn = asked.addOn;
246
+ let start = addOn && Date.parse(addOn.start) / 1000;
247
+ let renewal = addOn && Date.parse(addOn.renewal) / 1000;
248
+ let future = start != null && start > now() / 1000;
249
+ let contract = addOn ? {
250
+ payment_settings: invoiceMethods,
251
+ billing_cycle_anchor: renewal,
252
+ ...future ? {
253
+ trial_end: start
254
+ } : {
255
+ backdate_start_date: start
256
+ }
257
+ } : trialFor(asked.trial, now());
258
+ let made = await ask(options, '/v1/subscriptions', {
259
+ customer: asked.payer,
260
+ items: [
261
+ {
262
+ price: bought,
263
+ quantity: 1
264
+ },
265
+ ...addOn ? [
266
+ await addOnPrice(invoicing(), addOn)
267
+ ] : []
268
+ ],
269
+ collection_method: 'send_invoice',
270
+ days_until_due: asked.due,
271
+ metadata: asked.tags,
272
+ ...contract,
273
+ ...EXPAND
274
+ }, undefined, 'POST', asked.key);
275
+ if (!made.id) throw new Error('stripe made a subscription with no id');
276
+ return {
277
+ subscription: read(made, options),
278
+ at: when(made.created) ?? new Date(now()).toISOString()
279
+ };
280
+ },
281
+ invoicingOn: ()=>!!options.key && !!options.invoiceKey,
282
+ addOn: async (id, item)=>{
283
+ let sub = await ask(options, path(id));
284
+ let items = sub.items?.data ?? [];
285
+ let held = items.find((it)=>it.metadata?.yaks_add_on == item.key);
286
+ let tier = tierFor(sub, options);
287
+ if (sub.collection_method != 'send_invoice' || cadence(sub, tier, options) != 'year' || sub.status == 'canceled' || sub.status == 'incomplete_expired') {
288
+ return 'Support contracts require a yearly plan paid by invoice.';
289
+ }
290
+ let end = when(periodEnd(sub))?.slice(0, 10);
291
+ if (end != item.renewal) {
292
+ return `The yearly plan renews on ${end ?? 'an unknown date'}. Use the plan renewal date.`;
293
+ }
294
+ if (typeof held?.price == 'object' && held.price?.unit_amount == item.cents) return null;
295
+ let price = await addOnPrice(invoicing(), item);
296
+ await ask(options, path(id), {
297
+ items: [
298
+ {
299
+ ...price,
300
+ id: held?.id
301
+ }
302
+ ],
303
+ payment_settings: invoiceMethods,
304
+ proration_behavior: held ? 'none' : 'create_prorations'
305
+ }, undefined, 'POST', `add-on|${id}|${item.key}|${idOf(held?.price)}|${item.cents}`);
306
+ return null;
307
+ },
308
+ invoiceOnce: (asked)=>invoiceOnce(invoicing(), asked),
309
+ minimum,
310
+ // Payment mode under Managed Payments, the price made inline with its
311
+ // tax code and tax included, as every price here is: no dashboard price
312
+ // to keep in step. The tags ride the session's own metadata, which the
313
+ // event saying it was paid carries back whole.
314
+ once: async (asked)=>{
315
+ let made = await ask(options, '/v1/checkout/sessions', {
316
+ mode: 'payment',
317
+ customer: asked.payer,
318
+ line_items: {
319
+ 0: {
320
+ price_data: {
321
+ currency: asked.currency.toLowerCase(),
322
+ unit_amount: asked.cents,
323
+ tax_behavior: 'inclusive',
324
+ product_data: {
325
+ name: asked.name,
326
+ tax_code: ONCE_TAX
327
+ }
328
+ },
329
+ quantity: 1
330
+ }
331
+ },
332
+ success_url: asked.done,
333
+ cancel_url: asked.cancel,
334
+ client_reference_id: asked.reference,
335
+ metadata: asked.tags,
336
+ payment_intent_data: {
337
+ metadata: asked.tags
338
+ },
339
+ managed_payments: {
340
+ enabled: true
341
+ }
342
+ });
343
+ let url = String(made.url ?? '');
344
+ if (!url) throw new Error('stripe made a checkout session with no url');
345
+ return url;
346
+ },
347
+ // The session names the payment it made and what it took, and the
348
+ // refund is made on the platform's own account.
349
+ refunded: async ({ key, checkout, tags, cents })=>{
350
+ let session = await ask(options, `/v1/checkout/sessions/${encodeURIComponent(checkout)}`);
351
+ let payment = idOf(session.payment_intent);
352
+ if (!payment) throw new Error(`stripe holds no payment for ${checkout}`);
353
+ return await refund(options, undefined, {
354
+ key,
355
+ payment,
356
+ amount: cents ?? Number(session.amount_total ?? 0),
357
+ tags
358
+ });
359
+ },
360
+ // The portal needs a configuration on the account; without one Stripe
361
+ // refuses, and the refusal throws.
362
+ portal: async (payer, back)=>{
363
+ let made = await ask(options, '/v1/billing_portal/sessions', {
364
+ customer: payer,
365
+ return_url: back
366
+ });
367
+ let url = String(made.url ?? '');
368
+ if (!url) throw new Error('stripe made a portal session with no url');
369
+ return url;
370
+ },
371
+ subscription,
372
+ subscriptions: async (payer)=>{
373
+ let out = [];
374
+ for await (let sub of list(options, '/v1/subscriptions', {
375
+ customer: payer,
376
+ status: 'all',
377
+ 'expand[]': 'data.latest_invoice'
378
+ }))out.push(read(sub, options));
379
+ return out;
380
+ },
381
+ charges,
382
+ // The trial set to end then, prorating nothing.
383
+ postpone: async (id, until)=>{
384
+ let next = await charges(id);
385
+ if (next && Date.parse(next) >= Date.parse(until)) return;
386
+ await ask(options, path(id), {
387
+ trial_end: Math.floor(Date.parse(until) / 1000),
388
+ proration_behavior: 'none'
389
+ });
390
+ }
391
+ };
392
+ };
393
+ /** A verified event Stripe posted to the platform's own endpoint, read: a
394
+ * `customer.subscription.*` event carries its subscription whole, save an
395
+ * invoiced one's latest invoice, so that one is asked for with it, and a
396
+ * checkout session or an invoice names it, which one GET answers. An
397
+ * invoice's name for it moved under `parent` in API 2025-03-31.basil, and the
398
+ * old field is read too, for the reason `periodEnd` reads both. A checkout
399
+ * session in payment mode is a purchase: completed, its money there or on
400
+ * its way, and `checkout.session.async_payment_succeeded` when what was on
401
+ * its way arrives. */ export let changed = (options)=>(event)=>{
402
+ let e = event ?? {};
403
+ let o = e.data?.object ?? {};
404
+ let reference = o.client_reference_id;
405
+ let now = options.clock?.now() ?? Date.now();
406
+ let at = new Date((e.created ?? Math.floor(now / 1000)) * 1000).toISOString();
407
+ let live = e.livemode !== false;
408
+ let referred = typeof reference == 'string' && reference ? {
409
+ reference
410
+ } : {};
411
+ let details = e.type == 'checkout.session.completed' ? o.customer_details : undefined;
412
+ let payer = typeof details?.name == 'string' && details.name.trim() ? {
413
+ payerName: {
414
+ name: details.name,
415
+ ...typeof details.email == 'string' ? {
416
+ email: details.email
417
+ } : {}
418
+ }
419
+ } : {};
420
+ if ((e.type ?? '').startsWith('checkout.session.') && o.mode == 'payment') {
421
+ return {
422
+ about: 'purchase',
423
+ at,
424
+ live,
425
+ checkout: String(o.id ?? ''),
426
+ paid: o.payment_status == 'paid',
427
+ tags: tagsOf(o),
428
+ ...referred,
429
+ ...payer
430
+ };
431
+ }
432
+ let parent = o.parent ?? {};
433
+ let itself = (e.type ?? '').startsWith('customer.subscription.');
434
+ let whole = itself && o.collection_method != 'send_invoice';
435
+ let named = idOf(itself ? o.id : o.subscription ?? parent.subscription_details?.subscription);
436
+ // A completed checkout says where its payer is billed, when Stripe asked
437
+ // (under Managed Payments, what tax needs: at least the country). Only
438
+ // the town, state and country are read of it.
439
+ let address = details?.address;
440
+ let billed = address && Object.fromEntries([
441
+ 'city',
442
+ 'state',
443
+ 'country'
444
+ ].flatMap((k)=>address[k] ? [
445
+ [
446
+ k,
447
+ String(address[k])
448
+ ]
449
+ ] : []));
450
+ return {
451
+ about: 'subscription',
452
+ at,
453
+ live,
454
+ tags: tagsOf(o),
455
+ ...referred,
456
+ ...payer,
457
+ ...billed && Object.keys(billed).length ? {
458
+ billed
459
+ } : {},
460
+ subscription: ()=>whole ? Promise.resolve(read(o, options)) : named ? plans(options).subscription(named) : Promise.resolve(undefined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