@molecule/api-payments-stripe 1.0.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.
- package/LICENSE +115 -0
- package/dist/bondAdapter.d.ts +18 -0
- package/dist/bondAdapter.d.ts.map +1 -0
- package/dist/bondAdapter.js +406 -0
- package/dist/bondAdapter.js.map +1 -0
- package/dist/browser-guard.d.ts +2 -0
- package/dist/browser-guard.d.ts.map +1 -0
- package/dist/browser-guard.js +19 -0
- package/dist/browser-guard.js.map +1 -0
- package/dist/connect.d.ts +252 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +229 -0
- package/dist/connect.js.map +1 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +204 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +413 -0
- package/dist/provider.js.map +1 -0
- package/dist/secrets.d.ts +16 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +32 -0
- package/dist/secrets.js.map +1 -0
- package/dist/types.d.ts +78 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe payment provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* @see https://www.npmjs.com/package/stripe
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import Stripe from 'stripe';
|
|
9
|
+
import './secrets.js';
|
|
10
|
+
import type { NormalizedSubscription, SubscriptionStatus } from '@molecule/api-payments';
|
|
11
|
+
import type { CheckoutSessionResult, SubscriptionResult, SubscriptionUpdateParams, WebhookEventResult } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Returns the lazily-initialized Stripe client. Throws if `STRIPE_SECRET_KEY` is not set.
|
|
14
|
+
*
|
|
15
|
+
* @returns The shared `Stripe` SDK instance.
|
|
16
|
+
*/
|
|
17
|
+
export declare const getClient: () => Stripe;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a Stripe Checkout session for a new subscription.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Checkout configuration.
|
|
22
|
+
* @param options.priceId - The Stripe Price ID for the subscription line item.
|
|
23
|
+
* @param options.successUrl - URL to redirect to after successful payment.
|
|
24
|
+
* @param options.cancelUrl - URL to redirect to if the user cancels.
|
|
25
|
+
* @param options.customerId - Optional existing Stripe Customer ID.
|
|
26
|
+
* @param options.metadata - Optional key-value metadata to attach to the session.
|
|
27
|
+
* @param options.idempotencyKey - Optional idempotency key for safe request retries.
|
|
28
|
+
* @returns The checkout session ID and URL.
|
|
29
|
+
*/
|
|
30
|
+
export declare const createCheckoutSession: (options: {
|
|
31
|
+
priceId: string;
|
|
32
|
+
successUrl: string;
|
|
33
|
+
cancelUrl: string;
|
|
34
|
+
customerId?: string;
|
|
35
|
+
metadata?: Record<string, string>;
|
|
36
|
+
idempotencyKey?: string;
|
|
37
|
+
}) => Promise<CheckoutSessionResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a Stripe Billing Portal session so the user can manage their
|
|
40
|
+
* subscription (update payment method, cancel, view invoices) in Stripe's
|
|
41
|
+
* hosted portal.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Portal configuration.
|
|
44
|
+
* @param options.customerId - The Stripe Customer ID to open the portal for.
|
|
45
|
+
* @param options.returnUrl - URL Stripe returns the user to when they exit
|
|
46
|
+
* the portal. Falls back to APP_ORIGIN/ORIGIN when omitted.
|
|
47
|
+
* @returns The portal session ID and URL, or `null` when Stripe rejects the
|
|
48
|
+
* request (e.g. unknown customer).
|
|
49
|
+
*/
|
|
50
|
+
export declare const createPortalSession: (options: {
|
|
51
|
+
customerId: string;
|
|
52
|
+
returnUrl?: string;
|
|
53
|
+
}) => Promise<{
|
|
54
|
+
id: string;
|
|
55
|
+
url: string;
|
|
56
|
+
} | null>;
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves a Stripe Checkout session by ID, including the associated subscription.
|
|
59
|
+
*
|
|
60
|
+
* @param sessionId - The Stripe Checkout session ID.
|
|
61
|
+
* @returns The session ID, URL, and subscription ID (if a subscription was created).
|
|
62
|
+
*/
|
|
63
|
+
export declare const getCheckoutSession: (sessionId: string) => Promise<CheckoutSessionResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Retrieves a Stripe subscription by ID with expanded item data.
|
|
66
|
+
*
|
|
67
|
+
* @param subscriptionId - The Stripe subscription ID.
|
|
68
|
+
* @returns The normalized subscription result.
|
|
69
|
+
*/
|
|
70
|
+
export declare const getSubscription: (subscriptionId: string) => Promise<SubscriptionResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Immediately cancels a Stripe subscription.
|
|
73
|
+
*
|
|
74
|
+
* @param subscriptionId - The Stripe subscription ID to cancel.
|
|
75
|
+
* @returns The canceled subscription result.
|
|
76
|
+
*/
|
|
77
|
+
export declare const cancelSubscription: (subscriptionId: string) => Promise<SubscriptionResult>;
|
|
78
|
+
/**
|
|
79
|
+
* Updates a Stripe subscription (e.g. changes plan, sets cancel_at_period_end).
|
|
80
|
+
*
|
|
81
|
+
* @param subscriptionId - The Stripe subscription ID to update.
|
|
82
|
+
* @param params - The Stripe subscription update parameters.
|
|
83
|
+
* @returns The updated subscription result.
|
|
84
|
+
*/
|
|
85
|
+
export declare const updateSubscription: (subscriptionId: string, params: SubscriptionUpdateParams) => Promise<SubscriptionResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Verifies a Stripe webhook signature and parses the event payload.
|
|
88
|
+
* Requires `STRIPE_WEBHOOK_SECRET` env var.
|
|
89
|
+
*
|
|
90
|
+
* @param payload - The raw request body (string or Buffer).
|
|
91
|
+
* @param signature - The `stripe-signature` header value.
|
|
92
|
+
* @returns The verified webhook event with type and data.
|
|
93
|
+
*/
|
|
94
|
+
export declare const verifyWebhookSignature: (payload: string | Buffer, signature: string) => WebhookEventResult;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a Stripe SetupIntent for the saved-card flow.
|
|
97
|
+
*
|
|
98
|
+
* If `customerId` is not provided, a new Stripe customer is created and its
|
|
99
|
+
* ID is returned alongside the SetupIntent so the resource layer can persist
|
|
100
|
+
* the customer ID for future SetupIntents and detachments.
|
|
101
|
+
*
|
|
102
|
+
* @param options - SetupIntent creation options.
|
|
103
|
+
* @param options.customerId - Optional existing Stripe customer ID (`cus_...`).
|
|
104
|
+
* @param options.metadata - Optional metadata to attach to the SetupIntent.
|
|
105
|
+
* @param options.idempotencyKey - Optional idempotency key for safe retries.
|
|
106
|
+
* @returns The SetupIntent ID, client secret, and customer ID.
|
|
107
|
+
*/
|
|
108
|
+
export declare const createSetupIntent: (options: {
|
|
109
|
+
customerId?: string;
|
|
110
|
+
metadata?: Record<string, string>;
|
|
111
|
+
idempotencyKey?: string;
|
|
112
|
+
}) => Promise<{
|
|
113
|
+
id: string;
|
|
114
|
+
clientSecret: string;
|
|
115
|
+
customerId: string;
|
|
116
|
+
}>;
|
|
117
|
+
/**
|
|
118
|
+
* Retrieves a saved Stripe payment method (card) and returns normalized metadata.
|
|
119
|
+
*
|
|
120
|
+
* @param paymentMethodId - The Stripe payment method ID (`pm_...`).
|
|
121
|
+
* @returns Brand, last4, and expiry, or `null` if the lookup fails.
|
|
122
|
+
*/
|
|
123
|
+
export declare const retrievePaymentMethod: (paymentMethodId: string) => Promise<{
|
|
124
|
+
id: string;
|
|
125
|
+
brand: string;
|
|
126
|
+
last4: string;
|
|
127
|
+
expMonth: number;
|
|
128
|
+
expYear: number;
|
|
129
|
+
} | null>;
|
|
130
|
+
/**
|
|
131
|
+
* Detaches a saved Stripe payment method from its customer.
|
|
132
|
+
*
|
|
133
|
+
* @param paymentMethodId - The Stripe payment method ID (`pm_...`).
|
|
134
|
+
* @returns `true` if Stripe acknowledged the detach, `false` otherwise.
|
|
135
|
+
*/
|
|
136
|
+
export declare const detachPaymentMethod: (paymentMethodId: string) => Promise<boolean>;
|
|
137
|
+
/**
|
|
138
|
+
* Reports a usage-based OVERAGE charge to Stripe as a one-off invoice item
|
|
139
|
+
* against an existing customer (and, when given, attached to the open invoice
|
|
140
|
+
* of a specific subscription so it lands on the next cycle invoice).
|
|
141
|
+
*
|
|
142
|
+
* This is the supported, type-safe path on the installed Stripe SDK (v22):
|
|
143
|
+
* the legacy `subscriptionItems.createUsageRecord` API was removed in favor of
|
|
144
|
+
* metered-price meter events / invoice items. A positive-amount invoice item
|
|
145
|
+
* is the simplest cost-plus overage mechanism — Stripe aggregates open invoice
|
|
146
|
+
* items and bills them at the customer's cycle close, so repeated incremental
|
|
147
|
+
* calls accrete onto the same upcoming invoice.
|
|
148
|
+
*
|
|
149
|
+
* IDEMPOTENCY: the caller MUST pass a stable `idempotencyKey` derived from
|
|
150
|
+
* `(user, period, amount)` so a retry or a double-run within the same Stripe
|
|
151
|
+
* idempotency window (24h) is collapsed to a single invoice item and never
|
|
152
|
+
* double-charges (broker safety invariant 4).
|
|
153
|
+
*
|
|
154
|
+
* This function performs NO gating of its own — it charges whatever it is
|
|
155
|
+
* told to. The decision of WHETHER to charge (configured? opted-in? paid?
|
|
156
|
+
* over budget?) lives entirely in the molecule-dev billing module, which is
|
|
157
|
+
* the single inert/opt-in gate (safety invariants 1 + 2).
|
|
158
|
+
*
|
|
159
|
+
* @param options - Overage reporting options.
|
|
160
|
+
* @param options.customerId - The Stripe customer to bill (`cus_...`).
|
|
161
|
+
* @param options.amountCents - The overage amount in cents (must be `> 0`).
|
|
162
|
+
* @param options.currency - ISO currency (defaults to `usd`).
|
|
163
|
+
* @param options.priceId - The metered/overage Price id this reports against;
|
|
164
|
+
* recorded in metadata for reconciliation (the invoice item carries an
|
|
165
|
+
* explicit `amount`, so the price's unit amount is not used here).
|
|
166
|
+
* @param options.subscriptionId - Optional subscription to attach the item to
|
|
167
|
+
* so it bills on that subscription's cycle invoice.
|
|
168
|
+
* @param options.description - Human-readable line description.
|
|
169
|
+
* @param options.metadata - Extra reconciliation metadata (e.g. period).
|
|
170
|
+
* @param options.idempotencyKey - REQUIRED stable key (see IDEMPOTENCY above).
|
|
171
|
+
* @returns The created invoice item id + the amount actually reported.
|
|
172
|
+
*/
|
|
173
|
+
export declare const reportUsageOverage: (options: {
|
|
174
|
+
customerId: string;
|
|
175
|
+
amountCents: number;
|
|
176
|
+
currency?: string;
|
|
177
|
+
priceId: string;
|
|
178
|
+
subscriptionId?: string;
|
|
179
|
+
description?: string;
|
|
180
|
+
metadata?: Record<string, string>;
|
|
181
|
+
idempotencyKey: string;
|
|
182
|
+
}) => Promise<{
|
|
183
|
+
id: string;
|
|
184
|
+
amountCents: number;
|
|
185
|
+
}>;
|
|
186
|
+
/**
|
|
187
|
+
* Maps a raw Stripe subscription status string (e.g. `past_due`, `incomplete`)
|
|
188
|
+
* to the provider-agnostic `SubscriptionStatus`.
|
|
189
|
+
*
|
|
190
|
+
* Shared between `normalizeSubscription` (verify path) and the webhook adapter so
|
|
191
|
+
* both paths derive status identically.
|
|
192
|
+
* @param rawStatus - The raw Stripe `status` string, or `undefined` if absent.
|
|
193
|
+
* @returns The normalized `SubscriptionStatus` (`'unknown'` for unrecognized/missing).
|
|
194
|
+
*/
|
|
195
|
+
export declare const normalizeSubscriptionStatus: (rawStatus: string | undefined) => SubscriptionStatus;
|
|
196
|
+
/**
|
|
197
|
+
* Normalizes a Stripe-specific `SubscriptionResult` to the common
|
|
198
|
+
* `NormalizedSubscription` interface used across all payment providers.
|
|
199
|
+
*
|
|
200
|
+
* @param subscription - The Stripe subscription result to normalize.
|
|
201
|
+
* @returns A `NormalizedSubscription` with provider-agnostic fields.
|
|
202
|
+
*/
|
|
203
|
+
export declare const normalizeSubscription: (subscription: SubscriptionResult) => NormalizedSubscription;
|
|
204
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names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EAAE,MAAM,CAAC,CAAA;IACjC,cAAc,EAAE,MAAM,CAAA;CACvB,KAAG,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAmB9C,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GAAI,WAAW,MAAM,GAAG,SAAS,KAAG,kBAa3E,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,cAAc,kBAAkB,KAAG,sBAaxE,CAAA"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe payment provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* @see https://www.npmjs.com/package/stripe
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import Stripe from 'stripe';
|
|
9
|
+
import { getLogger } from '@molecule/api-bond';
|
|
10
|
+
const logger = getLogger();
|
|
11
|
+
// Side-effect import: registers this bond's secret definitions so the
|
|
12
|
+
// runtime registry is populated even when provider.js is imported directly
|
|
13
|
+
// (not through the package barrel).
|
|
14
|
+
import './secrets.js';
|
|
15
|
+
import { configNotConfiguredError } from '@molecule/api-secrets';
|
|
16
|
+
/**
|
|
17
|
+
* The lazily-initialized `Stripe` instance.
|
|
18
|
+
*
|
|
19
|
+
* @see http://npmjs.com/package/stripe
|
|
20
|
+
*/
|
|
21
|
+
let _client = null;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the lazily-initialized Stripe client. Throws if `STRIPE_SECRET_KEY` is not set.
|
|
24
|
+
*
|
|
25
|
+
* @returns The shared `Stripe` SDK instance.
|
|
26
|
+
*/
|
|
27
|
+
export const getClient = () => {
|
|
28
|
+
if (!_client) {
|
|
29
|
+
const key = process.env.STRIPE_SECRET_KEY;
|
|
30
|
+
if (!key) {
|
|
31
|
+
// Tag as a config-missing condition (not an internal error): the API error
|
|
32
|
+
// middleware maps `statusCode` + `errorKey` to a clean 503, and the message
|
|
33
|
+
// carries the registered definition's description + setup URL — the user
|
|
34
|
+
// sees exactly which key to set and where to get it, at the exact moment
|
|
35
|
+
// they're trying to upgrade to a paid plan.
|
|
36
|
+
throw configNotConfiguredError('STRIPE_SECRET_KEY', 'payments');
|
|
37
|
+
}
|
|
38
|
+
// Bound each request: Stripe's SDK default is an 80s timeout with automatic
|
|
39
|
+
// retries, so a Stripe slowdown during a signup/upgrade surge would pin
|
|
40
|
+
// request workers for over a minute each and cascade into a pool/worker
|
|
41
|
+
// exhaustion outage. Cap at 15s with two retries.
|
|
42
|
+
_client = new Stripe(key, { timeout: 15_000, maxNetworkRetries: 2 });
|
|
43
|
+
}
|
|
44
|
+
return _client;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Normalizes a Stripe `Subscription` object to the molecule `SubscriptionResult` type.
|
|
48
|
+
*
|
|
49
|
+
* @param sub - The raw Stripe subscription object.
|
|
50
|
+
* @returns A simplified `SubscriptionResult`.
|
|
51
|
+
*/
|
|
52
|
+
const toSubscriptionResult = (sub) => {
|
|
53
|
+
const firstItem = sub.items.data[0];
|
|
54
|
+
return {
|
|
55
|
+
id: sub.id,
|
|
56
|
+
status: sub.status,
|
|
57
|
+
customer: typeof sub.customer === 'string' ? sub.customer : sub.customer?.id,
|
|
58
|
+
items: {
|
|
59
|
+
data: sub.items.data.map((item) => ({
|
|
60
|
+
id: item.id,
|
|
61
|
+
price: item.price
|
|
62
|
+
? {
|
|
63
|
+
// The PRICE id is load-bearing for plan resolution: apps
|
|
64
|
+
// register their catalogue by the env-configured price ids,
|
|
65
|
+
// while `product` is the parent product — keep both.
|
|
66
|
+
id: item.price.id,
|
|
67
|
+
product: typeof item.price.product === 'string' ? item.price.product : undefined,
|
|
68
|
+
}
|
|
69
|
+
: undefined,
|
|
70
|
+
})),
|
|
71
|
+
},
|
|
72
|
+
current_period_start: firstItem?.current_period_start ?? 0,
|
|
73
|
+
current_period_end: firstItem?.current_period_end ?? 0,
|
|
74
|
+
cancel_at_period_end: sub.cancel_at_period_end,
|
|
75
|
+
canceled_at: sub.canceled_at,
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Creates a Stripe Checkout session for a new subscription.
|
|
80
|
+
*
|
|
81
|
+
* @param options - Checkout configuration.
|
|
82
|
+
* @param options.priceId - The Stripe Price ID for the subscription line item.
|
|
83
|
+
* @param options.successUrl - URL to redirect to after successful payment.
|
|
84
|
+
* @param options.cancelUrl - URL to redirect to if the user cancels.
|
|
85
|
+
* @param options.customerId - Optional existing Stripe Customer ID.
|
|
86
|
+
* @param options.metadata - Optional key-value metadata to attach to the session.
|
|
87
|
+
* @param options.idempotencyKey - Optional idempotency key for safe request retries.
|
|
88
|
+
* @returns The checkout session ID and URL.
|
|
89
|
+
*/
|
|
90
|
+
export const createCheckoutSession = async (options) => {
|
|
91
|
+
try {
|
|
92
|
+
const session = await getClient().checkout.sessions.create({
|
|
93
|
+
mode: 'subscription',
|
|
94
|
+
payment_method_types: ['card'],
|
|
95
|
+
line_items: [
|
|
96
|
+
{
|
|
97
|
+
price: options.priceId,
|
|
98
|
+
quantity: 1,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
success_url: options.successUrl,
|
|
102
|
+
cancel_url: options.cancelUrl,
|
|
103
|
+
customer: options.customerId,
|
|
104
|
+
metadata: options.metadata,
|
|
105
|
+
}, options.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : undefined);
|
|
106
|
+
return { id: session.id, url: session.url };
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
logger.error(`Error creating Stripe checkout session:`, error);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Creates a Stripe Billing Portal session so the user can manage their
|
|
115
|
+
* subscription (update payment method, cancel, view invoices) in Stripe's
|
|
116
|
+
* hosted portal.
|
|
117
|
+
*
|
|
118
|
+
* @param options - Portal configuration.
|
|
119
|
+
* @param options.customerId - The Stripe Customer ID to open the portal for.
|
|
120
|
+
* @param options.returnUrl - URL Stripe returns the user to when they exit
|
|
121
|
+
* the portal. Falls back to APP_ORIGIN/ORIGIN when omitted.
|
|
122
|
+
* @returns The portal session ID and URL, or `null` when Stripe rejects the
|
|
123
|
+
* request (e.g. unknown customer).
|
|
124
|
+
*/
|
|
125
|
+
export const createPortalSession = async (options) => {
|
|
126
|
+
try {
|
|
127
|
+
const returnUrl = options.returnUrl ?? process.env.APP_ORIGIN ?? process.env.ORIGIN ?? undefined;
|
|
128
|
+
const session = await getClient().billingPortal.sessions.create({
|
|
129
|
+
customer: options.customerId,
|
|
130
|
+
return_url: returnUrl,
|
|
131
|
+
});
|
|
132
|
+
return { id: session.id, url: session.url };
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
logger.error(`Error creating Stripe billing portal session:`, error);
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Retrieves a Stripe Checkout session by ID, including the associated subscription.
|
|
141
|
+
*
|
|
142
|
+
* @param sessionId - The Stripe Checkout session ID.
|
|
143
|
+
* @returns The session ID, URL, and subscription ID (if a subscription was created).
|
|
144
|
+
*/
|
|
145
|
+
export const getCheckoutSession = async (sessionId) => {
|
|
146
|
+
try {
|
|
147
|
+
const session = await getClient().checkout.sessions.retrieve(sessionId);
|
|
148
|
+
const subscription = typeof session.subscription === 'string'
|
|
149
|
+
? session.subscription
|
|
150
|
+
: session.subscription?.id;
|
|
151
|
+
return { id: session.id, url: session.url, subscription };
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
logger.error(`Error retrieving Stripe checkout session:`, error);
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Retrieves a Stripe subscription by ID with expanded item data.
|
|
160
|
+
*
|
|
161
|
+
* @param subscriptionId - The Stripe subscription ID.
|
|
162
|
+
* @returns The normalized subscription result.
|
|
163
|
+
*/
|
|
164
|
+
export const getSubscription = async (subscriptionId) => {
|
|
165
|
+
try {
|
|
166
|
+
const subscription = await getClient().subscriptions.retrieve(subscriptionId, {
|
|
167
|
+
expand: ['items.data'],
|
|
168
|
+
});
|
|
169
|
+
return toSubscriptionResult(subscription);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
logger.error(`Error retrieving Stripe subscription:`, error);
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Immediately cancels a Stripe subscription.
|
|
178
|
+
*
|
|
179
|
+
* @param subscriptionId - The Stripe subscription ID to cancel.
|
|
180
|
+
* @returns The canceled subscription result.
|
|
181
|
+
*/
|
|
182
|
+
export const cancelSubscription = async (subscriptionId) => {
|
|
183
|
+
try {
|
|
184
|
+
const subscription = await getClient().subscriptions.cancel(subscriptionId);
|
|
185
|
+
return toSubscriptionResult(subscription);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
logger.error(`Error canceling Stripe subscription:`, error);
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Updates a Stripe subscription (e.g. changes plan, sets cancel_at_period_end).
|
|
194
|
+
*
|
|
195
|
+
* @param subscriptionId - The Stripe subscription ID to update.
|
|
196
|
+
* @param params - The Stripe subscription update parameters.
|
|
197
|
+
* @returns The updated subscription result.
|
|
198
|
+
*/
|
|
199
|
+
export const updateSubscription = async (subscriptionId, params) => {
|
|
200
|
+
try {
|
|
201
|
+
const subscription = await getClient().subscriptions.update(subscriptionId, params);
|
|
202
|
+
return toSubscriptionResult(subscription);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
logger.error(`Error updating Stripe subscription:`, error);
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Verifies a Stripe webhook signature and parses the event payload.
|
|
211
|
+
* Requires `STRIPE_WEBHOOK_SECRET` env var.
|
|
212
|
+
*
|
|
213
|
+
* @param payload - The raw request body (string or Buffer).
|
|
214
|
+
* @param signature - The `stripe-signature` header value.
|
|
215
|
+
* @returns The verified webhook event with type and data.
|
|
216
|
+
*/
|
|
217
|
+
export const verifyWebhookSignature = (payload, signature) => {
|
|
218
|
+
const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
|
|
219
|
+
if (!webhookSecret) {
|
|
220
|
+
// Same actionable config-missing treatment as getClient(): the error names
|
|
221
|
+
// the exact key + setup URL (from the registered secret definition) so a
|
|
222
|
+
// misconfigured server is distinguishable from a forged/bad signature —
|
|
223
|
+
// "Missing Stripe webhook secret" read like a request-parsing bug and sent
|
|
224
|
+
// integrators debugging their webhook wiring instead of their .env.
|
|
225
|
+
throw configNotConfiguredError('STRIPE_WEBHOOK_SECRET', 'payment webhook verification');
|
|
226
|
+
}
|
|
227
|
+
const event = getClient().webhooks.constructEvent(payload, signature, webhookSecret);
|
|
228
|
+
return {
|
|
229
|
+
type: event.type,
|
|
230
|
+
data: { object: event.data.object },
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Creates a Stripe SetupIntent for the saved-card flow.
|
|
235
|
+
*
|
|
236
|
+
* If `customerId` is not provided, a new Stripe customer is created and its
|
|
237
|
+
* ID is returned alongside the SetupIntent so the resource layer can persist
|
|
238
|
+
* the customer ID for future SetupIntents and detachments.
|
|
239
|
+
*
|
|
240
|
+
* @param options - SetupIntent creation options.
|
|
241
|
+
* @param options.customerId - Optional existing Stripe customer ID (`cus_...`).
|
|
242
|
+
* @param options.metadata - Optional metadata to attach to the SetupIntent.
|
|
243
|
+
* @param options.idempotencyKey - Optional idempotency key for safe retries.
|
|
244
|
+
* @returns The SetupIntent ID, client secret, and customer ID.
|
|
245
|
+
*/
|
|
246
|
+
export const createSetupIntent = async (options) => {
|
|
247
|
+
try {
|
|
248
|
+
const client = getClient();
|
|
249
|
+
let customerId = options.customerId;
|
|
250
|
+
if (!customerId) {
|
|
251
|
+
const customer = await client.customers.create({ metadata: options.metadata }, options.idempotencyKey
|
|
252
|
+
? { idempotencyKey: `${options.idempotencyKey}:customer` }
|
|
253
|
+
: undefined);
|
|
254
|
+
customerId = customer.id;
|
|
255
|
+
}
|
|
256
|
+
const setupIntent = await client.setupIntents.create({
|
|
257
|
+
customer: customerId,
|
|
258
|
+
payment_method_types: ['card'],
|
|
259
|
+
usage: 'off_session',
|
|
260
|
+
metadata: options.metadata,
|
|
261
|
+
}, options.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : undefined);
|
|
262
|
+
if (!setupIntent.client_secret) {
|
|
263
|
+
throw new Error('Stripe SetupIntent missing client_secret');
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
id: setupIntent.id,
|
|
267
|
+
clientSecret: setupIntent.client_secret,
|
|
268
|
+
customerId,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
logger.error('Error creating Stripe SetupIntent:', error);
|
|
273
|
+
throw error;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Retrieves a saved Stripe payment method (card) and returns normalized metadata.
|
|
278
|
+
*
|
|
279
|
+
* @param paymentMethodId - The Stripe payment method ID (`pm_...`).
|
|
280
|
+
* @returns Brand, last4, and expiry, or `null` if the lookup fails.
|
|
281
|
+
*/
|
|
282
|
+
export const retrievePaymentMethod = async (paymentMethodId) => {
|
|
283
|
+
try {
|
|
284
|
+
const pm = await getClient().paymentMethods.retrieve(paymentMethodId);
|
|
285
|
+
if (!pm.card)
|
|
286
|
+
return null;
|
|
287
|
+
return {
|
|
288
|
+
id: pm.id,
|
|
289
|
+
brand: pm.card.brand,
|
|
290
|
+
last4: pm.card.last4,
|
|
291
|
+
expMonth: pm.card.exp_month,
|
|
292
|
+
expYear: pm.card.exp_year,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
logger.error('Error retrieving Stripe payment method:', error);
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Detaches a saved Stripe payment method from its customer.
|
|
302
|
+
*
|
|
303
|
+
* @param paymentMethodId - The Stripe payment method ID (`pm_...`).
|
|
304
|
+
* @returns `true` if Stripe acknowledged the detach, `false` otherwise.
|
|
305
|
+
*/
|
|
306
|
+
export const detachPaymentMethod = async (paymentMethodId) => {
|
|
307
|
+
try {
|
|
308
|
+
await getClient().paymentMethods.detach(paymentMethodId);
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
logger.error('Error detaching Stripe payment method:', error);
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* Reports a usage-based OVERAGE charge to Stripe as a one-off invoice item
|
|
318
|
+
* against an existing customer (and, when given, attached to the open invoice
|
|
319
|
+
* of a specific subscription so it lands on the next cycle invoice).
|
|
320
|
+
*
|
|
321
|
+
* This is the supported, type-safe path on the installed Stripe SDK (v22):
|
|
322
|
+
* the legacy `subscriptionItems.createUsageRecord` API was removed in favor of
|
|
323
|
+
* metered-price meter events / invoice items. A positive-amount invoice item
|
|
324
|
+
* is the simplest cost-plus overage mechanism — Stripe aggregates open invoice
|
|
325
|
+
* items and bills them at the customer's cycle close, so repeated incremental
|
|
326
|
+
* calls accrete onto the same upcoming invoice.
|
|
327
|
+
*
|
|
328
|
+
* IDEMPOTENCY: the caller MUST pass a stable `idempotencyKey` derived from
|
|
329
|
+
* `(user, period, amount)` so a retry or a double-run within the same Stripe
|
|
330
|
+
* idempotency window (24h) is collapsed to a single invoice item and never
|
|
331
|
+
* double-charges (broker safety invariant 4).
|
|
332
|
+
*
|
|
333
|
+
* This function performs NO gating of its own — it charges whatever it is
|
|
334
|
+
* told to. The decision of WHETHER to charge (configured? opted-in? paid?
|
|
335
|
+
* over budget?) lives entirely in the molecule-dev billing module, which is
|
|
336
|
+
* the single inert/opt-in gate (safety invariants 1 + 2).
|
|
337
|
+
*
|
|
338
|
+
* @param options - Overage reporting options.
|
|
339
|
+
* @param options.customerId - The Stripe customer to bill (`cus_...`).
|
|
340
|
+
* @param options.amountCents - The overage amount in cents (must be `> 0`).
|
|
341
|
+
* @param options.currency - ISO currency (defaults to `usd`).
|
|
342
|
+
* @param options.priceId - The metered/overage Price id this reports against;
|
|
343
|
+
* recorded in metadata for reconciliation (the invoice item carries an
|
|
344
|
+
* explicit `amount`, so the price's unit amount is not used here).
|
|
345
|
+
* @param options.subscriptionId - Optional subscription to attach the item to
|
|
346
|
+
* so it bills on that subscription's cycle invoice.
|
|
347
|
+
* @param options.description - Human-readable line description.
|
|
348
|
+
* @param options.metadata - Extra reconciliation metadata (e.g. period).
|
|
349
|
+
* @param options.idempotencyKey - REQUIRED stable key (see IDEMPOTENCY above).
|
|
350
|
+
* @returns The created invoice item id + the amount actually reported.
|
|
351
|
+
*/
|
|
352
|
+
export const reportUsageOverage = async (options) => {
|
|
353
|
+
try {
|
|
354
|
+
const invoiceItem = await getClient().invoiceItems.create({
|
|
355
|
+
customer: options.customerId,
|
|
356
|
+
amount: Math.round(options.amountCents),
|
|
357
|
+
currency: options.currency ?? 'usd',
|
|
358
|
+
description: options.description,
|
|
359
|
+
...(options.subscriptionId ? { subscription: options.subscriptionId } : {}),
|
|
360
|
+
metadata: { ...options.metadata, overagePriceId: options.priceId },
|
|
361
|
+
}, { idempotencyKey: options.idempotencyKey });
|
|
362
|
+
return { id: invoiceItem.id, amountCents: invoiceItem.amount };
|
|
363
|
+
}
|
|
364
|
+
catch (error) {
|
|
365
|
+
// Never log the customer id or amounts at error level beyond the bare fact.
|
|
366
|
+
logger.error('Error reporting Stripe usage overage:', error);
|
|
367
|
+
throw error;
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Maps a raw Stripe subscription status string (e.g. `past_due`, `incomplete`)
|
|
372
|
+
* to the provider-agnostic `SubscriptionStatus`.
|
|
373
|
+
*
|
|
374
|
+
* Shared between `normalizeSubscription` (verify path) and the webhook adapter so
|
|
375
|
+
* both paths derive status identically.
|
|
376
|
+
* @param rawStatus - The raw Stripe `status` string, or `undefined` if absent.
|
|
377
|
+
* @returns The normalized `SubscriptionStatus` (`'unknown'` for unrecognized/missing).
|
|
378
|
+
*/
|
|
379
|
+
export const normalizeSubscriptionStatus = (rawStatus) => {
|
|
380
|
+
const statusMap = {
|
|
381
|
+
active: 'active',
|
|
382
|
+
canceled: 'canceled',
|
|
383
|
+
incomplete: 'pending',
|
|
384
|
+
incomplete_expired: 'expired',
|
|
385
|
+
past_due: 'past_due',
|
|
386
|
+
paused: 'paused',
|
|
387
|
+
trialing: 'trialing',
|
|
388
|
+
unpaid: 'past_due',
|
|
389
|
+
};
|
|
390
|
+
return (rawStatus && statusMap[rawStatus]) || 'unknown';
|
|
391
|
+
};
|
|
392
|
+
/**
|
|
393
|
+
* Normalizes a Stripe-specific `SubscriptionResult` to the common
|
|
394
|
+
* `NormalizedSubscription` interface used across all payment providers.
|
|
395
|
+
*
|
|
396
|
+
* @param subscription - The Stripe subscription result to normalize.
|
|
397
|
+
* @returns A `NormalizedSubscription` with provider-agnostic fields.
|
|
398
|
+
*/
|
|
399
|
+
export const normalizeSubscription = (subscription) => {
|
|
400
|
+
return {
|
|
401
|
+
provider: 'stripe',
|
|
402
|
+
subscriptionId: subscription.id,
|
|
403
|
+
productId: subscription.items.data[0]?.price?.product || '',
|
|
404
|
+
status: normalizeSubscriptionStatus(subscription.status),
|
|
405
|
+
isActive: subscription.status === 'active' || subscription.status === 'trialing',
|
|
406
|
+
currentPeriodStart: subscription.current_period_start * 1000,
|
|
407
|
+
currentPeriodEnd: subscription.current_period_end * 1000,
|
|
408
|
+
willRenew: !subscription.cancel_at_period_end,
|
|
409
|
+
canceledAt: subscription.canceled_at ? subscription.canceled_at * 1000 : undefined,
|
|
410
|
+
rawData: subscription,
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAC1B,sEAAsE;AACtE,2EAA2E;AAC3E,oCAAoC;AACpC,OAAO,cAAc,CAAA;AAGrB,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAShE;;;;GAIG;AACH,IAAI,OAAO,GAAkB,IAAI,CAAA;AAEjC;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAW,EAAE;IACpC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAA;QACzC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,2EAA2E;YAC3E,4EAA4E;YAC5E,yEAAyE;YACzE,yEAAyE;YACzE,4CAA4C;YAC5C,MAAM,wBAAwB,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAA;QACjE,CAAC;QACD,4EAA4E;QAC5E,wEAAwE;QACxE,wEAAwE;QACxE,kDAAkD;QAClD,OAAO,GAAG,IAAI,MAAM,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,EAAE,CAAC,CAAA;IACtE,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,CAAC,GAAwB,EAAsB,EAAE;IAC5E,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,C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;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,YAAgC,EAA0B,EAAE;IAChG,OAAO;QACL,QAAQ,EAAE,QAAQ;QAClB,cAAc,EAAE,YAAY,CAAC,EAAE;QAC/B,SAAS,EAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAkB,IAAI,EAAE;QACvE,MAAM,EAAE,2BAA2B,CAAC,YAAY,CAAC,MAAM,CAAC;QACxD,QAAQ,EAAE,YAAY,CAAC,MAAM,KAAK,QAAQ,IAAI,YAAY,CAAC,MAAM,KAAK,UAAU;QAChF,kBAAkB,EAAE,YAAY,CAAC,oBAAoB,GAAG,IAAI;QAC5D,gBAAgB,EAAE,YAAY,CAAC,kBAAkB,GAAG,IAAI;QACxD,SAAS,EAAE,CAAC,YAAY,CAAC,oBAAoB;QAC7C,UAAU,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS;QAClF,OAAO,EAAE,YAAkD;KAC5D,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe secret definitions — self-registered at import time so the
|
|
3
|
+
* runtime secrets registry (`@molecule/api-secrets`) can drive boot-time
|
|
4
|
+
* configuration reports and actionable "not configured" errors.
|
|
5
|
+
*
|
|
6
|
+
* Content is derived MECHANICALLY from this package's mlcl registry secrets
|
|
7
|
+
* entry (label/instructions/setupUrl/example) via the fleet formula, so
|
|
8
|
+
* packages sharing a key register byte-identical definitions and
|
|
9
|
+
* registration order never matters.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import type { SecretDefinition } from '@molecule/api-secrets';
|
|
14
|
+
/** Secret definitions required by the Stripe payments bond. */
|
|
15
|
+
export declare const stripeSecretDefinitions: SecretDefinition[];
|
|
16
|
+
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAG7D,+DAA+D;AAC/D,eAAO,MAAM,uBAAuB,EAAE,gBAAgB,EAiBrD,CAAA"}
|