@parsrun/payments 0.1.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.
@@ -0,0 +1,388 @@
1
+ export { CardDetails, CreatePaymentIntentRequest, CreateRefundRequest, IyzicoConfig, Money, PaddleConfig, CreateCustomerRequest as ParsCreateCustomerRequest, CreateSubscriptionRequest as ParsCreateSubscriptionRequest, CurrencyCode as ParsCurrencyCode, PaymentIntent as ParsPaymentIntentType, PaymentMethod as ParsPaymentMethod, Price as ParsPrice, Subscription as ParsSubscription, SubscriptionStatus as ParsSubscriptionStatus, WebhookEvent as ParsWebhookEvent, WebhookEventType as ParsWebhookEventType, PaymentCustomer, PaymentIntentStatus, PaymentsConfig, PriceInterval, Refund, RefundStatus, StripeConfig, cardDetails, createCustomerRequest, createPaymentIntentRequest, createRefundRequest, createSubscriptionRequest, currencyCode, iyzicoConfig, money, paddleConfig, paymentIntent as parsPaymentIntent, price as parsPrice, subscription as parsSubscription, subscriptionStatus as parsSubscriptionStatus, paymentCustomer, paymentIntentStatus, paymentMethod, paymentsConfig, priceInterval, refund, refundStatus, stripeConfig, type, webhookEvent, webhookEventType } from '@parsrun/types';
2
+
3
+ /**
4
+ * @parsrun/payments - Type Definitions
5
+ * Payment types and interfaces
6
+ */
7
+
8
+ /**
9
+ * Payment provider type
10
+ */
11
+ type PaymentProviderType = "stripe" | "paddle" | "iyzico";
12
+ /**
13
+ * Currency code (ISO 4217)
14
+ */
15
+ type CurrencyCode = "USD" | "EUR" | "GBP" | "TRY" | "JPY" | "CAD" | "AUD" | string;
16
+ /**
17
+ * Payment status
18
+ */
19
+ type PaymentStatus = "pending" | "processing" | "succeeded" | "failed" | "canceled" | "refunded" | "partially_refunded";
20
+ /**
21
+ * Subscription status
22
+ */
23
+ type SubscriptionStatus = "active" | "past_due" | "unpaid" | "canceled" | "incomplete" | "incomplete_expired" | "trialing" | "paused";
24
+ /**
25
+ * Billing interval
26
+ */
27
+ type BillingInterval = "day" | "week" | "month" | "year";
28
+ /**
29
+ * Customer data
30
+ */
31
+ interface Customer {
32
+ /** Provider customer ID */
33
+ id: string;
34
+ /** Customer email */
35
+ email: string;
36
+ /** Customer name */
37
+ name?: string | undefined;
38
+ /** Phone number */
39
+ phone?: string | undefined;
40
+ /** Billing address */
41
+ address?: Address | undefined;
42
+ /** Custom metadata */
43
+ metadata?: Record<string, string> | undefined;
44
+ /** Provider-specific data */
45
+ providerData?: unknown;
46
+ }
47
+ /**
48
+ * Address
49
+ */
50
+ interface Address {
51
+ line1?: string | undefined;
52
+ line2?: string | undefined;
53
+ city?: string | undefined;
54
+ state?: string | undefined;
55
+ postalCode?: string | undefined;
56
+ country?: string | undefined;
57
+ }
58
+ /**
59
+ * Create customer options
60
+ */
61
+ interface CreateCustomerOptions {
62
+ email: string;
63
+ name?: string | undefined;
64
+ phone?: string | undefined;
65
+ address?: Address | undefined;
66
+ metadata?: Record<string, string> | undefined;
67
+ }
68
+ /**
69
+ * Product
70
+ */
71
+ interface Product {
72
+ /** Provider product ID */
73
+ id: string;
74
+ /** Product name */
75
+ name: string;
76
+ /** Description */
77
+ description?: string | undefined;
78
+ /** Active status */
79
+ active: boolean;
80
+ /** Custom metadata */
81
+ metadata?: Record<string, string> | undefined;
82
+ /** Provider-specific data */
83
+ providerData?: unknown;
84
+ }
85
+ /**
86
+ * Price
87
+ */
88
+ interface Price {
89
+ /** Provider price ID */
90
+ id: string;
91
+ /** Product ID */
92
+ productId: string;
93
+ /** Price in smallest currency unit (cents) */
94
+ unitAmount: number;
95
+ /** Currency */
96
+ currency: CurrencyCode;
97
+ /** Recurring billing details */
98
+ recurring?: {
99
+ interval: BillingInterval;
100
+ intervalCount: number;
101
+ } | undefined;
102
+ /** Active status */
103
+ active: boolean;
104
+ /** Custom metadata */
105
+ metadata?: Record<string, string> | undefined;
106
+ /** Provider-specific data */
107
+ providerData?: unknown;
108
+ }
109
+ /**
110
+ * Checkout line item
111
+ */
112
+ interface CheckoutLineItem {
113
+ /** Price ID */
114
+ priceId: string;
115
+ /** Quantity */
116
+ quantity: number;
117
+ }
118
+ /**
119
+ * Create checkout options
120
+ */
121
+ interface CreateCheckoutOptions {
122
+ /** Customer ID (optional, creates new if not provided) */
123
+ customerId?: string | undefined;
124
+ /** Customer email (for new customers) */
125
+ customerEmail?: string | undefined;
126
+ /** Line items */
127
+ lineItems: CheckoutLineItem[];
128
+ /** Success redirect URL */
129
+ successUrl: string;
130
+ /** Cancel redirect URL */
131
+ cancelUrl: string;
132
+ /** Checkout mode */
133
+ mode: "payment" | "subscription" | "setup";
134
+ /** Allow promotion codes */
135
+ allowPromotionCodes?: boolean | undefined;
136
+ /** Trial period days (subscription only) */
137
+ trialDays?: number | undefined;
138
+ /** Custom metadata */
139
+ metadata?: Record<string, string> | undefined;
140
+ /** Tenant ID for multi-tenant */
141
+ tenantId?: string | undefined;
142
+ }
143
+ /**
144
+ * Checkout session
145
+ */
146
+ interface CheckoutSession {
147
+ /** Provider session ID */
148
+ id: string;
149
+ /** Checkout URL */
150
+ url: string;
151
+ /** Customer ID */
152
+ customerId?: string | undefined;
153
+ /** Payment status */
154
+ status: "open" | "complete" | "expired";
155
+ /** Mode */
156
+ mode: "payment" | "subscription" | "setup";
157
+ /** Amount total */
158
+ amountTotal?: number | undefined;
159
+ /** Currency */
160
+ currency?: CurrencyCode | undefined;
161
+ /** Provider-specific data */
162
+ providerData?: unknown;
163
+ }
164
+ /**
165
+ * Subscription
166
+ */
167
+ interface Subscription {
168
+ /** Provider subscription ID */
169
+ id: string;
170
+ /** Customer ID */
171
+ customerId: string;
172
+ /** Status */
173
+ status: SubscriptionStatus;
174
+ /** Price ID */
175
+ priceId: string;
176
+ /** Product ID */
177
+ productId?: string | undefined;
178
+ /** Current period start */
179
+ currentPeriodStart: Date;
180
+ /** Current period end */
181
+ currentPeriodEnd: Date;
182
+ /** Cancel at period end */
183
+ cancelAtPeriodEnd: boolean;
184
+ /** Canceled at */
185
+ canceledAt?: Date | undefined;
186
+ /** Trial start */
187
+ trialStart?: Date | undefined;
188
+ /** Trial end */
189
+ trialEnd?: Date | undefined;
190
+ /** Custom metadata */
191
+ metadata?: Record<string, string> | undefined;
192
+ /** Provider-specific data */
193
+ providerData?: unknown;
194
+ }
195
+ /**
196
+ * Create subscription options
197
+ */
198
+ interface CreateSubscriptionOptions {
199
+ /** Customer ID */
200
+ customerId: string;
201
+ /** Price ID */
202
+ priceId: string;
203
+ /** Trial period days */
204
+ trialDays?: number | undefined;
205
+ /** Custom metadata */
206
+ metadata?: Record<string, string> | undefined;
207
+ /** Payment behavior */
208
+ paymentBehavior?: "default_incomplete" | "error_if_incomplete" | "allow_incomplete" | undefined;
209
+ }
210
+ /**
211
+ * Update subscription options
212
+ */
213
+ interface UpdateSubscriptionOptions {
214
+ /** New price ID */
215
+ priceId?: string | undefined;
216
+ /** Cancel at period end */
217
+ cancelAtPeriodEnd?: boolean | undefined;
218
+ /** Custom metadata */
219
+ metadata?: Record<string, string> | undefined;
220
+ /** Proration behavior */
221
+ prorationBehavior?: "create_prorations" | "none" | "always_invoice" | undefined;
222
+ }
223
+ /**
224
+ * Payment intent
225
+ */
226
+ interface PaymentIntent {
227
+ /** Provider payment ID */
228
+ id: string;
229
+ /** Amount */
230
+ amount: number;
231
+ /** Currency */
232
+ currency: CurrencyCode;
233
+ /** Status */
234
+ status: PaymentStatus;
235
+ /** Customer ID */
236
+ customerId?: string | undefined;
237
+ /** Provider-specific data */
238
+ providerData?: unknown;
239
+ }
240
+ /**
241
+ * Invoice
242
+ */
243
+ interface Invoice {
244
+ /** Provider invoice ID */
245
+ id: string;
246
+ /** Customer ID */
247
+ customerId: string;
248
+ /** Subscription ID */
249
+ subscriptionId?: string | undefined;
250
+ /** Status */
251
+ status: "draft" | "open" | "paid" | "void" | "uncollectible";
252
+ /** Amount due */
253
+ amountDue: number;
254
+ /** Amount paid */
255
+ amountPaid: number;
256
+ /** Currency */
257
+ currency: CurrencyCode;
258
+ /** Invoice URL */
259
+ hostedInvoiceUrl?: string | undefined;
260
+ /** PDF URL */
261
+ invoicePdf?: string | undefined;
262
+ /** Due date */
263
+ dueDate?: Date | undefined;
264
+ /** Provider-specific data */
265
+ providerData?: unknown;
266
+ }
267
+ /**
268
+ * Customer portal session
269
+ */
270
+ interface PortalSession {
271
+ /** Portal URL */
272
+ url: string;
273
+ /** Return URL */
274
+ returnUrl: string;
275
+ }
276
+ /**
277
+ * Create portal options
278
+ */
279
+ interface CreatePortalOptions {
280
+ /** Customer ID */
281
+ customerId: string;
282
+ /** Return URL */
283
+ returnUrl: string;
284
+ }
285
+ /**
286
+ * Webhook event types
287
+ */
288
+ type WebhookEventType = "checkout.session.completed" | "checkout.session.expired" | "customer.created" | "customer.updated" | "customer.deleted" | "subscription.created" | "subscription.updated" | "subscription.deleted" | "subscription.trial_will_end" | "payment.succeeded" | "payment.failed" | "invoice.created" | "invoice.paid" | "invoice.payment_failed" | "invoice.upcoming" | "refund.created" | "refund.updated";
289
+ /**
290
+ * Webhook event
291
+ */
292
+ interface WebhookEvent<T = unknown> {
293
+ /** Event ID */
294
+ id: string;
295
+ /** Event type */
296
+ type: WebhookEventType;
297
+ /** Event data */
298
+ data: T;
299
+ /** Created timestamp */
300
+ created: Date;
301
+ /** Provider type */
302
+ provider: PaymentProviderType;
303
+ /** Raw event data */
304
+ raw: unknown;
305
+ }
306
+ /**
307
+ * Webhook handler
308
+ */
309
+ type WebhookHandler<T = unknown> = (event: WebhookEvent<T>) => void | Promise<void>;
310
+ /**
311
+ * Payment provider interface
312
+ */
313
+ interface PaymentProvider {
314
+ /** Provider type */
315
+ readonly type: PaymentProviderType;
316
+ createCustomer(options: CreateCustomerOptions): Promise<Customer>;
317
+ getCustomer(customerId: string): Promise<Customer | null>;
318
+ updateCustomer(customerId: string, options: Partial<CreateCustomerOptions>): Promise<Customer>;
319
+ deleteCustomer(customerId: string): Promise<void>;
320
+ createCheckout(options: CreateCheckoutOptions): Promise<CheckoutSession>;
321
+ getCheckout(sessionId: string): Promise<CheckoutSession | null>;
322
+ createSubscription(options: CreateSubscriptionOptions): Promise<Subscription>;
323
+ getSubscription(subscriptionId: string): Promise<Subscription | null>;
324
+ updateSubscription(subscriptionId: string, options: UpdateSubscriptionOptions): Promise<Subscription>;
325
+ cancelSubscription(subscriptionId: string, cancelAtPeriodEnd?: boolean): Promise<Subscription>;
326
+ listSubscriptions(customerId: string): Promise<Subscription[]>;
327
+ createPortalSession(options: CreatePortalOptions): Promise<PortalSession>;
328
+ verifyWebhook(payload: string | Uint8Array, signature: string): Promise<WebhookEvent | null>;
329
+ getProduct?(productId: string): Promise<Product | null>;
330
+ getPrice?(priceId: string): Promise<Price | null>;
331
+ listPrices?(productId?: string): Promise<Price[]>;
332
+ }
333
+ /**
334
+ * Stripe provider config
335
+ */
336
+ interface StripeProviderConfig {
337
+ /** Stripe secret key */
338
+ secretKey: string;
339
+ /** Webhook signing secret */
340
+ webhookSecret?: string | undefined;
341
+ /** API version */
342
+ apiVersion?: string | undefined;
343
+ }
344
+ /**
345
+ * Paddle provider config
346
+ */
347
+ interface PaddleProviderConfig {
348
+ /** Paddle API key */
349
+ apiKey: string;
350
+ /** Paddle environment */
351
+ environment?: "sandbox" | "production" | undefined;
352
+ /** Webhook secret key */
353
+ webhookSecret?: string | undefined;
354
+ /** Seller ID */
355
+ sellerId?: string | undefined;
356
+ }
357
+ /**
358
+ * Payment service config
359
+ */
360
+ interface PaymentServiceConfig {
361
+ /** Payment provider */
362
+ provider: PaymentProvider;
363
+ /** Enable debug logging */
364
+ debug?: boolean | undefined;
365
+ }
366
+ /**
367
+ * Payment error
368
+ */
369
+ declare class PaymentError extends Error {
370
+ readonly code: string;
371
+ readonly cause?: unknown | undefined;
372
+ constructor(message: string, code: string, cause?: unknown | undefined);
373
+ }
374
+ /**
375
+ * Common payment error codes
376
+ */
377
+ declare const PaymentErrorCodes: {
378
+ readonly INVALID_CONFIG: "INVALID_CONFIG";
379
+ readonly CUSTOMER_NOT_FOUND: "CUSTOMER_NOT_FOUND";
380
+ readonly SUBSCRIPTION_NOT_FOUND: "SUBSCRIPTION_NOT_FOUND";
381
+ readonly CHECKOUT_FAILED: "CHECKOUT_FAILED";
382
+ readonly PAYMENT_FAILED: "PAYMENT_FAILED";
383
+ readonly WEBHOOK_VERIFICATION_FAILED: "WEBHOOK_VERIFICATION_FAILED";
384
+ readonly API_ERROR: "API_ERROR";
385
+ readonly RATE_LIMITED: "RATE_LIMITED";
386
+ };
387
+
388
+ export { type Address, type BillingInterval, type CheckoutLineItem, type CheckoutSession, type CreateCheckoutOptions, type CreateCustomerOptions, type CreatePortalOptions, type CreateSubscriptionOptions, type CurrencyCode, type Customer, type Invoice, type PaddleProviderConfig, PaymentError, PaymentErrorCodes, type PaymentIntent, type PaymentProvider, type PaymentProviderType, type PaymentServiceConfig, type PaymentStatus, type PortalSession, type Price, type Product, type StripeProviderConfig, type Subscription, type SubscriptionStatus, type UpdateSubscriptionOptions, type WebhookEvent, type WebhookEventType, type WebhookHandler };
package/dist/types.js ADDED
@@ -0,0 +1,74 @@
1
+ // src/types.ts
2
+ import {
3
+ type,
4
+ currencyCode,
5
+ money,
6
+ paymentCustomer,
7
+ createCustomerRequest,
8
+ cardDetails,
9
+ paymentMethod,
10
+ paymentIntentStatus,
11
+ paymentIntent,
12
+ createPaymentIntentRequest,
13
+ subscriptionStatus,
14
+ priceInterval,
15
+ price,
16
+ subscription,
17
+ createSubscriptionRequest,
18
+ refundStatus,
19
+ refund,
20
+ createRefundRequest,
21
+ webhookEventType,
22
+ webhookEvent,
23
+ stripeConfig,
24
+ paddleConfig,
25
+ iyzicoConfig,
26
+ paymentsConfig
27
+ } from "@parsrun/types";
28
+ var PaymentError = class extends Error {
29
+ constructor(message, code, cause) {
30
+ super(message);
31
+ this.code = code;
32
+ this.cause = cause;
33
+ this.name = "PaymentError";
34
+ }
35
+ };
36
+ var PaymentErrorCodes = {
37
+ INVALID_CONFIG: "INVALID_CONFIG",
38
+ CUSTOMER_NOT_FOUND: "CUSTOMER_NOT_FOUND",
39
+ SUBSCRIPTION_NOT_FOUND: "SUBSCRIPTION_NOT_FOUND",
40
+ CHECKOUT_FAILED: "CHECKOUT_FAILED",
41
+ PAYMENT_FAILED: "PAYMENT_FAILED",
42
+ WEBHOOK_VERIFICATION_FAILED: "WEBHOOK_VERIFICATION_FAILED",
43
+ API_ERROR: "API_ERROR",
44
+ RATE_LIMITED: "RATE_LIMITED"
45
+ };
46
+ export {
47
+ PaymentError,
48
+ PaymentErrorCodes,
49
+ cardDetails,
50
+ createCustomerRequest,
51
+ createPaymentIntentRequest,
52
+ createRefundRequest,
53
+ createSubscriptionRequest,
54
+ currencyCode,
55
+ iyzicoConfig,
56
+ money,
57
+ paddleConfig,
58
+ paymentIntent as parsPaymentIntent,
59
+ price as parsPrice,
60
+ subscription as parsSubscription,
61
+ subscriptionStatus as parsSubscriptionStatus,
62
+ paymentCustomer,
63
+ paymentIntentStatus,
64
+ paymentMethod,
65
+ paymentsConfig,
66
+ priceInterval,
67
+ refund,
68
+ refundStatus,
69
+ stripeConfig,
70
+ type,
71
+ webhookEvent,
72
+ webhookEventType
73
+ };
74
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * @parsrun/payments - Type Definitions\n * Payment types and interfaces\n */\n\n// Re-export types from @parsrun/types for convenience\nexport {\n type,\n currencyCode,\n money,\n paymentCustomer,\n createCustomerRequest,\n cardDetails,\n paymentMethod,\n paymentIntentStatus,\n paymentIntent as parsPaymentIntent,\n createPaymentIntentRequest,\n subscriptionStatus as parsSubscriptionStatus,\n priceInterval,\n price as parsPrice,\n subscription as parsSubscription,\n createSubscriptionRequest,\n refundStatus,\n refund,\n createRefundRequest,\n webhookEventType,\n webhookEvent,\n stripeConfig,\n paddleConfig,\n iyzicoConfig,\n paymentsConfig,\n type CurrencyCode as ParsCurrencyCode,\n type Money,\n type PaymentCustomer,\n type CreateCustomerRequest as ParsCreateCustomerRequest,\n type CardDetails,\n type PaymentMethod as ParsPaymentMethod,\n type PaymentIntentStatus,\n type PaymentIntent as ParsPaymentIntentType,\n type CreatePaymentIntentRequest,\n type SubscriptionStatus as ParsSubscriptionStatus,\n type PriceInterval,\n type Price as ParsPrice,\n type Subscription as ParsSubscription,\n type CreateSubscriptionRequest as ParsCreateSubscriptionRequest,\n type RefundStatus,\n type Refund,\n type CreateRefundRequest,\n type WebhookEventType as ParsWebhookEventType,\n type WebhookEvent as ParsWebhookEvent,\n type StripeConfig,\n type PaddleConfig,\n type IyzicoConfig,\n type PaymentsConfig,\n} from \"@parsrun/types\";\n\n/**\n * Payment provider type\n */\nexport type PaymentProviderType = \"stripe\" | \"paddle\" | \"iyzico\";\n\n/**\n * Currency code (ISO 4217)\n */\nexport type CurrencyCode = \"USD\" | \"EUR\" | \"GBP\" | \"TRY\" | \"JPY\" | \"CAD\" | \"AUD\" | string;\n\n/**\n * Payment status\n */\nexport type PaymentStatus =\n | \"pending\"\n | \"processing\"\n | \"succeeded\"\n | \"failed\"\n | \"canceled\"\n | \"refunded\"\n | \"partially_refunded\";\n\n/**\n * Subscription status\n */\nexport type SubscriptionStatus =\n | \"active\"\n | \"past_due\"\n | \"unpaid\"\n | \"canceled\"\n | \"incomplete\"\n | \"incomplete_expired\"\n | \"trialing\"\n | \"paused\";\n\n/**\n * Billing interval\n */\nexport type BillingInterval = \"day\" | \"week\" | \"month\" | \"year\";\n\n// ============================================================================\n// Customer\n// ============================================================================\n\n/**\n * Customer data\n */\nexport interface Customer {\n /** Provider customer ID */\n id: string;\n /** Customer email */\n email: string;\n /** Customer name */\n name?: string | undefined;\n /** Phone number */\n phone?: string | undefined;\n /** Billing address */\n address?: Address | undefined;\n /** Custom metadata */\n metadata?: Record<string, string> | undefined;\n /** Provider-specific data */\n providerData?: unknown;\n}\n\n/**\n * Address\n */\nexport interface Address {\n line1?: string | undefined;\n line2?: string | undefined;\n city?: string | undefined;\n state?: string | undefined;\n postalCode?: string | undefined;\n country?: string | undefined;\n}\n\n/**\n * Create customer options\n */\nexport interface CreateCustomerOptions {\n email: string;\n name?: string | undefined;\n phone?: string | undefined;\n address?: Address | undefined;\n metadata?: Record<string, string> | undefined;\n}\n\n// ============================================================================\n// Products & Prices\n// ============================================================================\n\n/**\n * Product\n */\nexport interface Product {\n /** Provider product ID */\n id: string;\n /** Product name */\n name: string;\n /** Description */\n description?: string | undefined;\n /** Active status */\n active: boolean;\n /** Custom metadata */\n metadata?: Record<string, string> | undefined;\n /** Provider-specific data */\n providerData?: unknown;\n}\n\n/**\n * Price\n */\nexport interface Price {\n /** Provider price ID */\n id: string;\n /** Product ID */\n productId: string;\n /** Price in smallest currency unit (cents) */\n unitAmount: number;\n /** Currency */\n currency: CurrencyCode;\n /** Recurring billing details */\n recurring?: {\n interval: BillingInterval;\n intervalCount: number;\n } | undefined;\n /** Active status */\n active: boolean;\n /** Custom metadata */\n metadata?: Record<string, string> | undefined;\n /** Provider-specific data */\n providerData?: unknown;\n}\n\n// ============================================================================\n// Checkout\n// ============================================================================\n\n/**\n * Checkout line item\n */\nexport interface CheckoutLineItem {\n /** Price ID */\n priceId: string;\n /** Quantity */\n quantity: number;\n}\n\n/**\n * Create checkout options\n */\nexport interface CreateCheckoutOptions {\n /** Customer ID (optional, creates new if not provided) */\n customerId?: string | undefined;\n /** Customer email (for new customers) */\n customerEmail?: string | undefined;\n /** Line items */\n lineItems: CheckoutLineItem[];\n /** Success redirect URL */\n successUrl: string;\n /** Cancel redirect URL */\n cancelUrl: string;\n /** Checkout mode */\n mode: \"payment\" | \"subscription\" | \"setup\";\n /** Allow promotion codes */\n allowPromotionCodes?: boolean | undefined;\n /** Trial period days (subscription only) */\n trialDays?: number | undefined;\n /** Custom metadata */\n metadata?: Record<string, string> | undefined;\n /** Tenant ID for multi-tenant */\n tenantId?: string | undefined;\n}\n\n/**\n * Checkout session\n */\nexport interface CheckoutSession {\n /** Provider session ID */\n id: string;\n /** Checkout URL */\n url: string;\n /** Customer ID */\n customerId?: string | undefined;\n /** Payment status */\n status: \"open\" | \"complete\" | \"expired\";\n /** Mode */\n mode: \"payment\" | \"subscription\" | \"setup\";\n /** Amount total */\n amountTotal?: number | undefined;\n /** Currency */\n currency?: CurrencyCode | undefined;\n /** Provider-specific data */\n providerData?: unknown;\n}\n\n// ============================================================================\n// Subscriptions\n// ============================================================================\n\n/**\n * Subscription\n */\nexport interface Subscription {\n /** Provider subscription ID */\n id: string;\n /** Customer ID */\n customerId: string;\n /** Status */\n status: SubscriptionStatus;\n /** Price ID */\n priceId: string;\n /** Product ID */\n productId?: string | undefined;\n /** Current period start */\n currentPeriodStart: Date;\n /** Current period end */\n currentPeriodEnd: Date;\n /** Cancel at period end */\n cancelAtPeriodEnd: boolean;\n /** Canceled at */\n canceledAt?: Date | undefined;\n /** Trial start */\n trialStart?: Date | undefined;\n /** Trial end */\n trialEnd?: Date | undefined;\n /** Custom metadata */\n metadata?: Record<string, string> | undefined;\n /** Provider-specific data */\n providerData?: unknown;\n}\n\n/**\n * Create subscription options\n */\nexport interface CreateSubscriptionOptions {\n /** Customer ID */\n customerId: string;\n /** Price ID */\n priceId: string;\n /** Trial period days */\n trialDays?: number | undefined;\n /** Custom metadata */\n metadata?: Record<string, string> | undefined;\n /** Payment behavior */\n paymentBehavior?: \"default_incomplete\" | \"error_if_incomplete\" | \"allow_incomplete\" | undefined;\n}\n\n/**\n * Update subscription options\n */\nexport interface UpdateSubscriptionOptions {\n /** New price ID */\n priceId?: string | undefined;\n /** Cancel at period end */\n cancelAtPeriodEnd?: boolean | undefined;\n /** Custom metadata */\n metadata?: Record<string, string> | undefined;\n /** Proration behavior */\n prorationBehavior?: \"create_prorations\" | \"none\" | \"always_invoice\" | undefined;\n}\n\n// ============================================================================\n// Payments & Invoices\n// ============================================================================\n\n/**\n * Payment intent\n */\nexport interface PaymentIntent {\n /** Provider payment ID */\n id: string;\n /** Amount */\n amount: number;\n /** Currency */\n currency: CurrencyCode;\n /** Status */\n status: PaymentStatus;\n /** Customer ID */\n customerId?: string | undefined;\n /** Provider-specific data */\n providerData?: unknown;\n}\n\n/**\n * Invoice\n */\nexport interface Invoice {\n /** Provider invoice ID */\n id: string;\n /** Customer ID */\n customerId: string;\n /** Subscription ID */\n subscriptionId?: string | undefined;\n /** Status */\n status: \"draft\" | \"open\" | \"paid\" | \"void\" | \"uncollectible\";\n /** Amount due */\n amountDue: number;\n /** Amount paid */\n amountPaid: number;\n /** Currency */\n currency: CurrencyCode;\n /** Invoice URL */\n hostedInvoiceUrl?: string | undefined;\n /** PDF URL */\n invoicePdf?: string | undefined;\n /** Due date */\n dueDate?: Date | undefined;\n /** Provider-specific data */\n providerData?: unknown;\n}\n\n// ============================================================================\n// Portal\n// ============================================================================\n\n/**\n * Customer portal session\n */\nexport interface PortalSession {\n /** Portal URL */\n url: string;\n /** Return URL */\n returnUrl: string;\n}\n\n/**\n * Create portal options\n */\nexport interface CreatePortalOptions {\n /** Customer ID */\n customerId: string;\n /** Return URL */\n returnUrl: string;\n}\n\n// ============================================================================\n// Webhooks\n// ============================================================================\n\n/**\n * Webhook event types\n */\nexport type WebhookEventType =\n // Checkout\n | \"checkout.session.completed\"\n | \"checkout.session.expired\"\n // Customer\n | \"customer.created\"\n | \"customer.updated\"\n | \"customer.deleted\"\n // Subscription\n | \"subscription.created\"\n | \"subscription.updated\"\n | \"subscription.deleted\"\n | \"subscription.trial_will_end\"\n // Payment\n | \"payment.succeeded\"\n | \"payment.failed\"\n // Invoice\n | \"invoice.created\"\n | \"invoice.paid\"\n | \"invoice.payment_failed\"\n | \"invoice.upcoming\"\n // Refund\n | \"refund.created\"\n | \"refund.updated\";\n\n/**\n * Webhook event\n */\nexport interface WebhookEvent<T = unknown> {\n /** Event ID */\n id: string;\n /** Event type */\n type: WebhookEventType;\n /** Event data */\n data: T;\n /** Created timestamp */\n created: Date;\n /** Provider type */\n provider: PaymentProviderType;\n /** Raw event data */\n raw: unknown;\n}\n\n/**\n * Webhook handler\n */\nexport type WebhookHandler<T = unknown> = (\n event: WebhookEvent<T>\n) => void | Promise<void>;\n\n// ============================================================================\n// Provider Interface\n// ============================================================================\n\n/**\n * Payment provider interface\n */\nexport interface PaymentProvider {\n /** Provider type */\n readonly type: PaymentProviderType;\n\n // Customer\n createCustomer(options: CreateCustomerOptions): Promise<Customer>;\n getCustomer(customerId: string): Promise<Customer | null>;\n updateCustomer(customerId: string, options: Partial<CreateCustomerOptions>): Promise<Customer>;\n deleteCustomer(customerId: string): Promise<void>;\n\n // Checkout\n createCheckout(options: CreateCheckoutOptions): Promise<CheckoutSession>;\n getCheckout(sessionId: string): Promise<CheckoutSession | null>;\n\n // Subscriptions\n createSubscription(options: CreateSubscriptionOptions): Promise<Subscription>;\n getSubscription(subscriptionId: string): Promise<Subscription | null>;\n updateSubscription(subscriptionId: string, options: UpdateSubscriptionOptions): Promise<Subscription>;\n cancelSubscription(subscriptionId: string, cancelAtPeriodEnd?: boolean): Promise<Subscription>;\n listSubscriptions(customerId: string): Promise<Subscription[]>;\n\n // Portal\n createPortalSession(options: CreatePortalOptions): Promise<PortalSession>;\n\n // Webhooks\n verifyWebhook(payload: string | Uint8Array, signature: string): Promise<WebhookEvent | null>;\n\n // Products & Prices (optional)\n getProduct?(productId: string): Promise<Product | null>;\n getPrice?(priceId: string): Promise<Price | null>;\n listPrices?(productId?: string): Promise<Price[]>;\n}\n\n// ============================================================================\n// Provider Config\n// ============================================================================\n\n/**\n * Stripe provider config\n */\nexport interface StripeProviderConfig {\n /** Stripe secret key */\n secretKey: string;\n /** Webhook signing secret */\n webhookSecret?: string | undefined;\n /** API version */\n apiVersion?: string | undefined;\n}\n\n/**\n * Paddle provider config\n */\nexport interface PaddleProviderConfig {\n /** Paddle API key */\n apiKey: string;\n /** Paddle environment */\n environment?: \"sandbox\" | \"production\" | undefined;\n /** Webhook secret key */\n webhookSecret?: string | undefined;\n /** Seller ID */\n sellerId?: string | undefined;\n}\n\n// ============================================================================\n// Service Config\n// ============================================================================\n\n/**\n * Payment service config\n */\nexport interface PaymentServiceConfig {\n /** Payment provider */\n provider: PaymentProvider;\n /** Enable debug logging */\n debug?: boolean | undefined;\n}\n\n// ============================================================================\n// Errors\n// ============================================================================\n\n/**\n * Payment error\n */\nexport class PaymentError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n public readonly cause?: unknown\n ) {\n super(message);\n this.name = \"PaymentError\";\n }\n}\n\n/**\n * Common payment error codes\n */\nexport const PaymentErrorCodes = {\n INVALID_CONFIG: \"INVALID_CONFIG\",\n CUSTOMER_NOT_FOUND: \"CUSTOMER_NOT_FOUND\",\n SUBSCRIPTION_NOT_FOUND: \"SUBSCRIPTION_NOT_FOUND\",\n CHECKOUT_FAILED: \"CHECKOUT_FAILED\",\n PAYMENT_FAILED: \"PAYMENT_FAILED\",\n WEBHOOK_VERIFICATION_FAILED: \"WEBHOOK_VERIFICATION_FAILED\",\n API_ERROR: \"API_ERROR\",\n RATE_LIMITED: \"RATE_LIMITED\",\n} as const;\n"],"mappings":";AAMA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACiB;AAAA,EACjB;AAAA,EACsB;AAAA,EACtB;AAAA,EACS;AAAA,EACO;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAwBK;AAseA,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACE,SACgB,MACA,OAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,oBAAoB;AAAA,EAC/B,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,wBAAwB;AAAA,EACxB,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,6BAA6B;AAAA,EAC7B,WAAW;AAAA,EACX,cAAc;AAChB;","names":[]}