@funnelfox/billing 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,204 @@
1
+ /**
2
+ * TypeScript definitions for @funnelfox/billing SDK
3
+ */
4
+
5
+ export interface SDKConfig {
6
+ orgId: string;
7
+ baseUrl?: string;
8
+ region?: string;
9
+ sandbox?: boolean;
10
+ }
11
+
12
+ export interface APIConfig {
13
+ baseUrl?: string;
14
+ region?: string;
15
+ }
16
+
17
+ export interface Customer {
18
+ email: string;
19
+ externalId: string;
20
+ countryCode?: string;
21
+ }
22
+
23
+ export interface CheckoutConfig {
24
+ customer: Customer;
25
+ priceId: string;
26
+ container: string;
27
+ clientMetadata?: Record<string, any>;
28
+ universalCheckoutOptions?: PrimerCheckoutOptions;
29
+ }
30
+
31
+ export interface CheckoutConfigWithCallbacks extends CheckoutConfig {
32
+ onSuccess?: (result: PaymentResult) => void;
33
+ onError?: (error: Error) => void;
34
+ onStatusChange?: (newState: CheckoutState, oldState?: CheckoutState) => void;
35
+ onDestroy?: () => void;
36
+ }
37
+
38
+ export interface CreateCheckoutOptions extends CheckoutConfigWithCallbacks {
39
+ orgId?: string;
40
+ apiConfig?: APIConfig;
41
+ }
42
+
43
+ export interface PrimerCheckoutOptions {
44
+ paymentHandling?: 'MANUAL' | 'AUTO';
45
+ apiVersion?: string;
46
+ paypal?: {
47
+ buttonColor?: 'blue' | 'gold' | 'silver' | 'white' | 'black';
48
+ paymentFlow?: 'PREFER_VAULT' | 'VAULT_ONLY' | 'CHECKOUT_ONLY';
49
+ };
50
+ }
51
+
52
+ export interface PaymentResult {
53
+ orderId: string;
54
+ status: 'succeeded' | 'failed' | 'cancelled' | 'processing';
55
+ transactionId?: string;
56
+ failureReason?: string;
57
+ metadata?: Record<string, any>;
58
+ }
59
+
60
+ export type CheckoutEventName =
61
+ | 'success'
62
+ | 'error'
63
+ | 'status-change'
64
+ | 'destroy';
65
+
66
+ export type CheckoutState =
67
+ | 'initializing'
68
+ | 'ready'
69
+ | 'processing'
70
+ | 'action_required'
71
+ | 'updating'
72
+ | 'completed'
73
+ | 'error'
74
+ | 'destroyed';
75
+
76
+ export interface CheckoutStatus {
77
+ id: string;
78
+ state: CheckoutState;
79
+ orderId: string | null;
80
+ priceId: string;
81
+ isDestroyed: boolean;
82
+ }
83
+
84
+ export interface CheckoutInstance {
85
+ readonly id: string;
86
+ readonly state: CheckoutState;
87
+ readonly orderId: string | null;
88
+ readonly isDestroyed: boolean;
89
+
90
+ updatePrice(newPriceId: string): Promise<void>;
91
+ getStatus(): CheckoutStatus;
92
+ destroy(): Promise<void>;
93
+ getContainer(): Element | null;
94
+ isInState(state: CheckoutState): boolean;
95
+ isReady(): boolean;
96
+ isProcessing(): boolean;
97
+
98
+ on(eventName: 'success', handler: (result: PaymentResult) => void): this;
99
+ on(eventName: 'error', handler: (error: Error) => void): this;
100
+ on(
101
+ eventName: 'status-change',
102
+ handler: (newState: CheckoutState, oldState?: CheckoutState) => void
103
+ ): this;
104
+ on(eventName: 'destroy', handler: () => void): this;
105
+ on(eventName: CheckoutEventName, handler: (...args: any[]) => void): this;
106
+
107
+ off(eventName: CheckoutEventName, handler?: Function): this;
108
+ once(eventName: CheckoutEventName, handler: Function): this;
109
+ }
110
+
111
+ // Error classes
112
+ export declare class FunnefoxSDKError extends Error {
113
+ code: string;
114
+ details: any;
115
+ constructor(message: string, code?: string, details?: any);
116
+ }
117
+
118
+ export declare class ValidationError extends FunnefoxSDKError {
119
+ field: string;
120
+ value: any;
121
+ constructor(field: string, message: string, value?: any);
122
+ }
123
+
124
+ export declare class APIError extends FunnefoxSDKError {
125
+ statusCode: number | null;
126
+ errorCode: string | null;
127
+ errorType: string | null;
128
+ requestId: string | null;
129
+ response: any;
130
+ constructor(
131
+ message: string,
132
+ statusCode?: number | null,
133
+ options?: {
134
+ errorCode?: string;
135
+ errorType?: string;
136
+ requestId?: string;
137
+ response?: any;
138
+ }
139
+ );
140
+ }
141
+
142
+ export declare class PrimerError extends FunnefoxSDKError {
143
+ primerError: any;
144
+ constructor(message: string, primerError?: any);
145
+ }
146
+
147
+ export declare class CheckoutError extends FunnefoxSDKError {
148
+ phase: string | null;
149
+ constructor(message: string, phase?: string);
150
+ }
151
+
152
+ export declare class ConfigurationError extends FunnefoxSDKError {
153
+ constructor(message: string);
154
+ }
155
+
156
+ export declare class NetworkError extends FunnefoxSDKError {
157
+ originalError: any;
158
+ constructor(message: string, originalError?: any);
159
+ }
160
+
161
+ // Constants
162
+ export declare const SDK_VERSION: string;
163
+ export declare const CHECKOUT_STATES: Record<string, CheckoutState>;
164
+ export declare const EVENTS: Record<string, CheckoutEventName>;
165
+ export declare const ERROR_CODES: Record<string, string>;
166
+
167
+ // Individual function exports
168
+ export declare function configure(config: SDKConfig): void;
169
+ export declare function createCheckout(
170
+ options: CreateCheckoutOptions
171
+ ): Promise<CheckoutInstance>;
172
+ export declare function showUniversalCheckout(
173
+ clientToken: string,
174
+ options: any
175
+ ): Promise<any>;
176
+
177
+ export interface CreateClientSessionOptions {
178
+ priceId: string;
179
+ externalId: string;
180
+ email: string;
181
+ orgId?: string;
182
+ apiConfig?: APIConfig;
183
+ clientMetadata?: Record<string, any>;
184
+ countryCode?: string;
185
+ }
186
+
187
+ export interface ClientSessionData {
188
+ clientToken: string;
189
+ orderId: string;
190
+ type: string;
191
+ }
192
+
193
+ export declare function createClientSession(params: CreateClientSessionOptions): Promise<ClientSessionData>;
194
+
195
+ // Billing namespace
196
+ export declare const Billing: {
197
+ configure: typeof configure;
198
+ createCheckout: typeof createCheckout;
199
+ showUniversalCheckout: typeof showUniversalCheckout;
200
+ createClientSession: typeof createClientSession;
201
+ };
202
+
203
+ // Default export is Billing namespace
204
+ export default Billing;
@@ -0,0 +1,2 @@
1
+ // Re-export all types for ESM build
2
+ export * from './funnelfox-billing';