@stripe-sdk/core 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/README.md +700 -0
- package/dist/client/index.d.mts +198 -0
- package/dist/client/index.d.ts +198 -0
- package/dist/client/index.js +517 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.mjs +506 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/index-D8rM_YD4.d.mts +375 -0
- package/dist/index-D8rM_YD4.d.ts +375 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1800 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1708 -0
- package/dist/index.mjs.map +1 -0
- package/dist/next/index.d.mts +65 -0
- package/dist/next/index.d.ts +65 -0
- package/dist/next/index.js +450 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/index.mjs +443 -0
- package/dist/next/index.mjs.map +1 -0
- package/dist/server/index.d.mts +115 -0
- package/dist/server/index.d.ts +115 -0
- package/dist/server/index.js +1290 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +1208 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/webhooks/index.d.mts +2 -0
- package/dist/server/webhooks/index.d.ts +2 -0
- package/dist/server/webhooks/index.js +156 -0
- package/dist/server/webhooks/index.js.map +1 -0
- package/dist/server/webhooks/index.mjs +152 -0
- package/dist/server/webhooks/index.mjs.map +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import Stripe__default from 'stripe';
|
|
2
|
+
|
|
3
|
+
interface StripeSDKConfig {
|
|
4
|
+
secretKey: string;
|
|
5
|
+
publishableKey: string;
|
|
6
|
+
webhookSecret?: string;
|
|
7
|
+
apiVersion?: Stripe__default.LatestApiVersion;
|
|
8
|
+
appInfo?: Stripe__default.AppInfo;
|
|
9
|
+
}
|
|
10
|
+
interface CreatePaymentIntentInput {
|
|
11
|
+
amount: number;
|
|
12
|
+
currency: string;
|
|
13
|
+
customerId?: string;
|
|
14
|
+
paymentMethodId?: string;
|
|
15
|
+
metadata?: Record<string, string>;
|
|
16
|
+
description?: string;
|
|
17
|
+
receiptEmail?: string;
|
|
18
|
+
setupFutureUsage?: 'on_session' | 'off_session';
|
|
19
|
+
automaticPaymentMethods?: boolean;
|
|
20
|
+
returnUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
interface ConfirmPaymentInput {
|
|
23
|
+
paymentIntentId: string;
|
|
24
|
+
paymentMethodId?: string;
|
|
25
|
+
returnUrl?: string;
|
|
26
|
+
}
|
|
27
|
+
interface CreateCheckoutSessionInput {
|
|
28
|
+
mode: 'payment' | 'subscription' | 'setup';
|
|
29
|
+
lineItems: Array<{
|
|
30
|
+
priceId: string;
|
|
31
|
+
quantity: number;
|
|
32
|
+
}>;
|
|
33
|
+
successUrl: string;
|
|
34
|
+
cancelUrl: string;
|
|
35
|
+
customerId?: string;
|
|
36
|
+
customerEmail?: string;
|
|
37
|
+
metadata?: Record<string, string>;
|
|
38
|
+
allowPromotionCodes?: boolean;
|
|
39
|
+
shippingAddressCollection?: {
|
|
40
|
+
allowedCountries: string[];
|
|
41
|
+
};
|
|
42
|
+
billingAddressCollection?: 'auto' | 'required';
|
|
43
|
+
trialPeriodDays?: number;
|
|
44
|
+
taxIdCollection?: boolean;
|
|
45
|
+
automaticTax?: boolean;
|
|
46
|
+
locale?: string;
|
|
47
|
+
}
|
|
48
|
+
interface CreatePaymentLinkInput {
|
|
49
|
+
lineItems: Array<{
|
|
50
|
+
priceId: string;
|
|
51
|
+
quantity: number;
|
|
52
|
+
adjustableQuantity?: {
|
|
53
|
+
enabled: boolean;
|
|
54
|
+
minimum?: number;
|
|
55
|
+
maximum?: number;
|
|
56
|
+
};
|
|
57
|
+
}>;
|
|
58
|
+
metadata?: Record<string, string>;
|
|
59
|
+
afterCompletion?: {
|
|
60
|
+
type: 'redirect' | 'hosted_confirmation';
|
|
61
|
+
redirectUrl?: string;
|
|
62
|
+
};
|
|
63
|
+
allowPromotionCodes?: boolean;
|
|
64
|
+
automaticTax?: boolean;
|
|
65
|
+
billingAddressCollection?: 'auto' | 'required';
|
|
66
|
+
shippingAddressCollection?: {
|
|
67
|
+
allowedCountries: string[];
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
interface CreateCustomerInput {
|
|
71
|
+
email?: string;
|
|
72
|
+
name?: string;
|
|
73
|
+
phone?: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
metadata?: Record<string, string>;
|
|
76
|
+
paymentMethodId?: string;
|
|
77
|
+
address?: {
|
|
78
|
+
line1?: string;
|
|
79
|
+
line2?: string;
|
|
80
|
+
city?: string;
|
|
81
|
+
state?: string;
|
|
82
|
+
postalCode?: string;
|
|
83
|
+
country?: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
interface UpdateCustomerInput {
|
|
87
|
+
customerId: string;
|
|
88
|
+
email?: string;
|
|
89
|
+
name?: string;
|
|
90
|
+
phone?: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
metadata?: Record<string, string>;
|
|
93
|
+
defaultPaymentMethodId?: string;
|
|
94
|
+
address?: {
|
|
95
|
+
line1?: string;
|
|
96
|
+
line2?: string;
|
|
97
|
+
city?: string;
|
|
98
|
+
state?: string;
|
|
99
|
+
postalCode?: string;
|
|
100
|
+
country?: string;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
interface ListCustomersInput {
|
|
104
|
+
limit?: number;
|
|
105
|
+
startingAfter?: string;
|
|
106
|
+
endingBefore?: string;
|
|
107
|
+
email?: string;
|
|
108
|
+
}
|
|
109
|
+
interface CreateSubscriptionInput {
|
|
110
|
+
customerId: string;
|
|
111
|
+
priceId: string;
|
|
112
|
+
quantity?: number;
|
|
113
|
+
metadata?: Record<string, string>;
|
|
114
|
+
trialPeriodDays?: number;
|
|
115
|
+
couponId?: string;
|
|
116
|
+
promotionCodeId?: string;
|
|
117
|
+
paymentBehavior?: 'default_incomplete' | 'error_if_incomplete' | 'allow_incomplete' | 'pending_if_incomplete';
|
|
118
|
+
cancelAtPeriodEnd?: boolean;
|
|
119
|
+
billingCycleAnchor?: number;
|
|
120
|
+
prorationBehavior?: 'create_prorations' | 'none' | 'always_invoice';
|
|
121
|
+
items?: Array<{
|
|
122
|
+
priceId: string;
|
|
123
|
+
quantity?: number;
|
|
124
|
+
}>;
|
|
125
|
+
}
|
|
126
|
+
interface UpdateSubscriptionInput {
|
|
127
|
+
subscriptionId: string;
|
|
128
|
+
priceId?: string;
|
|
129
|
+
quantity?: number;
|
|
130
|
+
metadata?: Record<string, string>;
|
|
131
|
+
cancelAtPeriodEnd?: boolean;
|
|
132
|
+
prorationBehavior?: 'create_prorations' | 'none' | 'always_invoice';
|
|
133
|
+
couponId?: string;
|
|
134
|
+
items?: Array<{
|
|
135
|
+
id?: string;
|
|
136
|
+
priceId: string;
|
|
137
|
+
quantity?: number;
|
|
138
|
+
}>;
|
|
139
|
+
}
|
|
140
|
+
interface CancelSubscriptionInput {
|
|
141
|
+
subscriptionId: string;
|
|
142
|
+
cancelAtPeriodEnd?: boolean;
|
|
143
|
+
cancellationDetails?: {
|
|
144
|
+
comment?: string;
|
|
145
|
+
feedback?: 'customer_service' | 'low_quality' | 'missing_features' | 'other' | 'switched_service' | 'too_complex' | 'too_expensive' | 'unused';
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
interface CreateProductInput {
|
|
149
|
+
name: string;
|
|
150
|
+
description?: string;
|
|
151
|
+
images?: string[];
|
|
152
|
+
metadata?: Record<string, string>;
|
|
153
|
+
active?: boolean;
|
|
154
|
+
defaultPriceData?: {
|
|
155
|
+
unitAmount: number;
|
|
156
|
+
currency: string;
|
|
157
|
+
recurring?: {
|
|
158
|
+
interval: 'day' | 'week' | 'month' | 'year';
|
|
159
|
+
intervalCount?: number;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
interface UpdateProductInput {
|
|
164
|
+
productId: string;
|
|
165
|
+
name?: string;
|
|
166
|
+
description?: string;
|
|
167
|
+
images?: string[];
|
|
168
|
+
metadata?: Record<string, string>;
|
|
169
|
+
active?: boolean;
|
|
170
|
+
}
|
|
171
|
+
interface CreatePriceInput {
|
|
172
|
+
productId: string;
|
|
173
|
+
unitAmount: number;
|
|
174
|
+
currency: string;
|
|
175
|
+
recurring?: {
|
|
176
|
+
interval: 'day' | 'week' | 'month' | 'year';
|
|
177
|
+
intervalCount?: number;
|
|
178
|
+
};
|
|
179
|
+
metadata?: Record<string, string>;
|
|
180
|
+
active?: boolean;
|
|
181
|
+
nickname?: string;
|
|
182
|
+
lookupKey?: string;
|
|
183
|
+
billingScheme?: 'per_unit' | 'tiered';
|
|
184
|
+
tiers?: Array<{
|
|
185
|
+
upTo: number | 'inf';
|
|
186
|
+
unitAmount?: number;
|
|
187
|
+
flatAmount?: number;
|
|
188
|
+
}>;
|
|
189
|
+
tiersMode?: 'graduated' | 'volume';
|
|
190
|
+
}
|
|
191
|
+
interface CreateInvoiceInput {
|
|
192
|
+
customerId: string;
|
|
193
|
+
collectionMethod?: 'charge_automatically' | 'send_invoice';
|
|
194
|
+
daysUntilDue?: number;
|
|
195
|
+
metadata?: Record<string, string>;
|
|
196
|
+
description?: string;
|
|
197
|
+
autoAdvance?: boolean;
|
|
198
|
+
}
|
|
199
|
+
interface CreateInvoiceItemInput {
|
|
200
|
+
customerId: string;
|
|
201
|
+
invoiceId?: string;
|
|
202
|
+
priceId?: string;
|
|
203
|
+
amount?: number;
|
|
204
|
+
currency?: string;
|
|
205
|
+
description?: string;
|
|
206
|
+
quantity?: number;
|
|
207
|
+
metadata?: Record<string, string>;
|
|
208
|
+
}
|
|
209
|
+
interface CreateRefundInput {
|
|
210
|
+
paymentIntentId?: string;
|
|
211
|
+
chargeId?: string;
|
|
212
|
+
amount?: number;
|
|
213
|
+
reason?: 'duplicate' | 'fraudulent' | 'requested_by_customer';
|
|
214
|
+
metadata?: Record<string, string>;
|
|
215
|
+
}
|
|
216
|
+
interface UpdateDisputeInput {
|
|
217
|
+
disputeId: string;
|
|
218
|
+
evidence?: {
|
|
219
|
+
customerName?: string;
|
|
220
|
+
customerEmailAddress?: string;
|
|
221
|
+
customerCommunication?: string;
|
|
222
|
+
productDescription?: string;
|
|
223
|
+
shippingDocumentation?: string;
|
|
224
|
+
serviceDocumentation?: string;
|
|
225
|
+
uncategorizedText?: string;
|
|
226
|
+
};
|
|
227
|
+
metadata?: Record<string, string>;
|
|
228
|
+
submit?: boolean;
|
|
229
|
+
}
|
|
230
|
+
interface CreateConnectAccountInput {
|
|
231
|
+
type: 'standard' | 'express' | 'custom';
|
|
232
|
+
country?: string;
|
|
233
|
+
email?: string;
|
|
234
|
+
capabilities?: {
|
|
235
|
+
cardPayments?: {
|
|
236
|
+
requested: boolean;
|
|
237
|
+
};
|
|
238
|
+
transfers?: {
|
|
239
|
+
requested: boolean;
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
businessType?: 'individual' | 'company' | 'non_profit' | 'government_entity';
|
|
243
|
+
metadata?: Record<string, string>;
|
|
244
|
+
}
|
|
245
|
+
interface CreateAccountLinkInput {
|
|
246
|
+
accountId: string;
|
|
247
|
+
refreshUrl: string;
|
|
248
|
+
returnUrl: string;
|
|
249
|
+
type: 'account_onboarding' | 'account_update';
|
|
250
|
+
}
|
|
251
|
+
interface CreateTransferInput {
|
|
252
|
+
amount: number;
|
|
253
|
+
currency: string;
|
|
254
|
+
destinationAccountId: string;
|
|
255
|
+
description?: string;
|
|
256
|
+
metadata?: Record<string, string>;
|
|
257
|
+
sourceTransaction?: string;
|
|
258
|
+
}
|
|
259
|
+
interface CreateCouponInput {
|
|
260
|
+
percentOff?: number;
|
|
261
|
+
amountOff?: number;
|
|
262
|
+
currency?: string;
|
|
263
|
+
duration: 'forever' | 'once' | 'repeating';
|
|
264
|
+
durationInMonths?: number;
|
|
265
|
+
maxRedemptions?: number;
|
|
266
|
+
redeemBy?: number;
|
|
267
|
+
name?: string;
|
|
268
|
+
metadata?: Record<string, string>;
|
|
269
|
+
}
|
|
270
|
+
interface CreatePromotionCodeInput {
|
|
271
|
+
couponId: string;
|
|
272
|
+
code?: string;
|
|
273
|
+
active?: boolean;
|
|
274
|
+
maxRedemptions?: number;
|
|
275
|
+
expiresAt?: number;
|
|
276
|
+
metadata?: Record<string, string>;
|
|
277
|
+
restrictions?: {
|
|
278
|
+
firstTimeTransaction?: boolean;
|
|
279
|
+
minimumAmount?: number;
|
|
280
|
+
minimumAmountCurrency?: string;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
interface CreateSetupIntentInput {
|
|
284
|
+
customerId?: string;
|
|
285
|
+
paymentMethodTypes?: string[];
|
|
286
|
+
usage?: 'on_session' | 'off_session';
|
|
287
|
+
metadata?: Record<string, string>;
|
|
288
|
+
}
|
|
289
|
+
interface CreatePortalSessionInput {
|
|
290
|
+
customerId: string;
|
|
291
|
+
returnUrl: string;
|
|
292
|
+
configuration?: string;
|
|
293
|
+
}
|
|
294
|
+
type WebhookEventType = 'payment_intent.succeeded' | 'payment_intent.payment_failed' | 'payment_intent.canceled' | 'payment_intent.created' | 'payment_intent.processing' | 'checkout.session.completed' | 'checkout.session.expired' | 'customer.created' | 'customer.updated' | 'customer.deleted' | 'customer.subscription.created' | 'customer.subscription.updated' | 'customer.subscription.deleted' | 'customer.subscription.trial_will_end' | 'customer.subscription.paused' | 'customer.subscription.resumed' | 'invoice.created' | 'invoice.finalized' | 'invoice.paid' | 'invoice.payment_succeeded' | 'invoice.payment_failed' | 'invoice.upcoming' | 'invoice.voided' | 'charge.succeeded' | 'charge.failed' | 'charge.refunded' | 'charge.dispute.created' | 'charge.dispute.updated' | 'charge.dispute.closed' | 'product.created' | 'product.updated' | 'product.deleted' | 'price.created' | 'price.updated' | 'price.deleted' | 'payment_method.attached' | 'payment_method.detached' | 'payment_method.updated' | 'setup_intent.succeeded' | 'setup_intent.setup_failed' | 'account.updated' | 'payout.created' | 'payout.paid' | 'payout.failed' | string;
|
|
295
|
+
type WebhookHandler = (event: Stripe__default.Event) => Promise<void> | void;
|
|
296
|
+
interface WebhookHandlerMap {
|
|
297
|
+
[eventType: string]: WebhookHandler;
|
|
298
|
+
}
|
|
299
|
+
interface PaginationInput {
|
|
300
|
+
limit?: number;
|
|
301
|
+
startingAfter?: string;
|
|
302
|
+
endingBefore?: string;
|
|
303
|
+
}
|
|
304
|
+
interface SDKResponse<T> {
|
|
305
|
+
data: T;
|
|
306
|
+
error: null;
|
|
307
|
+
}
|
|
308
|
+
interface SDKError {
|
|
309
|
+
data: null;
|
|
310
|
+
error: {
|
|
311
|
+
message: string;
|
|
312
|
+
type: string;
|
|
313
|
+
code?: string;
|
|
314
|
+
statusCode?: number;
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
type SDKResult<T> = SDKResponse<T> | SDKError;
|
|
318
|
+
|
|
319
|
+
interface WebhookConfig {
|
|
320
|
+
secret?: string;
|
|
321
|
+
handlers: WebhookHandlerMap;
|
|
322
|
+
onError?: (error: Error, event?: Stripe__default.Event) => void | Promise<void>;
|
|
323
|
+
onUnhandledEvent?: (event: Stripe__default.Event) => void | Promise<void>;
|
|
324
|
+
}
|
|
325
|
+
declare function createWebhookHandler(config: WebhookConfig): (body: string | Buffer, signature: string) => Promise<{
|
|
326
|
+
received: true;
|
|
327
|
+
type: string;
|
|
328
|
+
}>;
|
|
329
|
+
/**
|
|
330
|
+
* Helper for Next.js App Router webhook route
|
|
331
|
+
*
|
|
332
|
+
* Usage in app/api/webhooks/stripe/route.ts:
|
|
333
|
+
*
|
|
334
|
+
* ```ts
|
|
335
|
+
* import { createNextWebhookHandler } from '@stripe-sdk/core/webhooks';
|
|
336
|
+
*
|
|
337
|
+
* export const POST = createNextWebhookHandler({
|
|
338
|
+
* handlers: {
|
|
339
|
+
* 'payment_intent.succeeded': async (event) => { ... },
|
|
340
|
+
* 'customer.subscription.created': async (event) => { ... },
|
|
341
|
+
* },
|
|
342
|
+
* });
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
declare function createNextWebhookHandler(config: WebhookConfig): (request: Request) => Promise<Response>;
|
|
346
|
+
/**
|
|
347
|
+
* Helper for Next.js Pages Router webhook route
|
|
348
|
+
*
|
|
349
|
+
* Usage in pages/api/webhooks/stripe.ts:
|
|
350
|
+
*
|
|
351
|
+
* ```ts
|
|
352
|
+
* import { createPagesWebhookHandler } from '@stripe-sdk/core/webhooks';
|
|
353
|
+
*
|
|
354
|
+
* export const config = { api: { bodyParser: false } };
|
|
355
|
+
*
|
|
356
|
+
* export default createPagesWebhookHandler({
|
|
357
|
+
* handlers: {
|
|
358
|
+
* 'payment_intent.succeeded': async (event) => { ... },
|
|
359
|
+
* },
|
|
360
|
+
* });
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
declare function createPagesWebhookHandler(webhookConfig: WebhookConfig): (req: {
|
|
364
|
+
method?: string;
|
|
365
|
+
headers: Record<string, string | string[] | undefined>;
|
|
366
|
+
body?: unknown;
|
|
367
|
+
on?: (event: string, cb: (...args: unknown[]) => void) => void;
|
|
368
|
+
}, res: {
|
|
369
|
+
status: (code: number) => {
|
|
370
|
+
json: (data: unknown) => void;
|
|
371
|
+
end: () => void;
|
|
372
|
+
};
|
|
373
|
+
}) => Promise<void>;
|
|
374
|
+
|
|
375
|
+
export { createNextWebhookHandler as A, createPagesWebhookHandler as B, type CancelSubscriptionInput as C, createWebhookHandler as D, type WebhookConfig as E, type ListCustomersInput as L, type PaginationInput as P, type SDKError as S, type UpdateCustomerInput as U, type WebhookEventType as W, type ConfirmPaymentInput as a, type CreateAccountLinkInput as b, type CreateCheckoutSessionInput as c, type CreateConnectAccountInput as d, type CreateCouponInput as e, type CreateCustomerInput as f, type CreateInvoiceInput as g, type CreateInvoiceItemInput as h, type CreatePaymentIntentInput as i, type CreatePaymentLinkInput as j, type CreatePortalSessionInput as k, type CreatePriceInput as l, type CreateProductInput as m, type CreatePromotionCodeInput as n, type CreateRefundInput as o, type CreateSetupIntentInput as p, type CreateSubscriptionInput as q, type CreateTransferInput as r, type SDKResponse as s, type SDKResult as t, type StripeSDKConfig as u, type UpdateDisputeInput as v, type UpdateProductInput as w, type UpdateSubscriptionInput as x, type WebhookHandler as y, type WebhookHandlerMap as z };
|