@flopay/shared 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.
- package/README.md +147 -0
- package/dist/index.cjs +307 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +602 -0
- package/dist/index.d.ts +602 -0
- package/dist/index.mjs +254 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +39 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
/** Discriminated error types returned by the FloPay SDK. */
|
|
2
|
+
type FloPayErrorType = 'validation_error' | 'api_error' | 'authentication_error' | 'rate_limit_error' | 'network_error';
|
|
3
|
+
/**
|
|
4
|
+
* Custom error class for all FloPay SDK errors.
|
|
5
|
+
*
|
|
6
|
+
* Extends the native `Error` and adds structured fields that mirror
|
|
7
|
+
* Stripe-style error responses for familiarity.
|
|
8
|
+
*/
|
|
9
|
+
declare class FloPayError extends Error {
|
|
10
|
+
readonly type: FloPayErrorType;
|
|
11
|
+
readonly code?: string;
|
|
12
|
+
readonly declineCode?: string;
|
|
13
|
+
readonly param?: string;
|
|
14
|
+
constructor(message: string, type: FloPayErrorType, options?: {
|
|
15
|
+
code?: string;
|
|
16
|
+
declineCode?: string;
|
|
17
|
+
param?: string;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** Create a validation error (e.g. missing required field). */
|
|
21
|
+
declare function validationError(message: string, param?: string): FloPayError;
|
|
22
|
+
/** Create an API error (e.g. upstream provider returned an error). */
|
|
23
|
+
declare function apiError(message: string, code?: string): FloPayError;
|
|
24
|
+
/** Create an authentication error (e.g. invalid publishable key). */
|
|
25
|
+
declare function authenticationError(message: string): FloPayError;
|
|
26
|
+
/** Create a rate limit error. */
|
|
27
|
+
declare function rateLimitError(message: string): FloPayError;
|
|
28
|
+
/** Create a network error (e.g. fetch failed). */
|
|
29
|
+
declare function networkError(message: string): FloPayError;
|
|
30
|
+
|
|
31
|
+
/** Theme variables that map to CSS custom properties on FloPay elements. */
|
|
32
|
+
interface FloPayThemeVariables {
|
|
33
|
+
colorPrimary?: string;
|
|
34
|
+
colorBackground?: string;
|
|
35
|
+
colorText?: string;
|
|
36
|
+
colorDanger?: string;
|
|
37
|
+
borderRadius?: string;
|
|
38
|
+
fontFamily?: string;
|
|
39
|
+
fontSizeBase?: string;
|
|
40
|
+
spacingUnit?: string;
|
|
41
|
+
}
|
|
42
|
+
/** Controls the visual appearance of all FloPay elements. */
|
|
43
|
+
interface FloPayAppearance {
|
|
44
|
+
theme?: 'default' | 'flat' | 'night' | 'none';
|
|
45
|
+
variables?: FloPayThemeVariables;
|
|
46
|
+
/** CSS-like rules keyed by selector (e.g. `".Input"`, `".Label"`). */
|
|
47
|
+
rules?: Record<string, Record<string, string>>;
|
|
48
|
+
}
|
|
49
|
+
/** A customer attached to a checkout session. */
|
|
50
|
+
interface Customer {
|
|
51
|
+
id: string;
|
|
52
|
+
email: string;
|
|
53
|
+
firstName?: string;
|
|
54
|
+
lastName?: string;
|
|
55
|
+
gender?: string;
|
|
56
|
+
city?: string;
|
|
57
|
+
state?: string;
|
|
58
|
+
country?: string;
|
|
59
|
+
zip?: string;
|
|
60
|
+
}
|
|
61
|
+
/** Recurring interval configuration for subscription line items. */
|
|
62
|
+
interface RecurringInterval {
|
|
63
|
+
interval: 'month' | 'year';
|
|
64
|
+
intervalCount?: number;
|
|
65
|
+
}
|
|
66
|
+
/** Inline product data when no pre-created price is referenced. */
|
|
67
|
+
interface PriceData {
|
|
68
|
+
currency: string;
|
|
69
|
+
unitAmount: number;
|
|
70
|
+
productData: {
|
|
71
|
+
name: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
};
|
|
74
|
+
recurring?: RecurringInterval;
|
|
75
|
+
}
|
|
76
|
+
/** A single line item within a checkout session. */
|
|
77
|
+
interface LineItem {
|
|
78
|
+
/** Reference to a pre-created price object on the provider. */
|
|
79
|
+
price?: string;
|
|
80
|
+
/** Inline price data (used when no `price` reference exists). */
|
|
81
|
+
priceData?: PriceData;
|
|
82
|
+
quantity: number;
|
|
83
|
+
}
|
|
84
|
+
/** Checkout mode controlling the payment UI behavior. */
|
|
85
|
+
type CheckoutMode = 'full' | 'auto' | 'confirm';
|
|
86
|
+
/** A one-time item from a checkout session response. */
|
|
87
|
+
interface CheckoutSessionItem {
|
|
88
|
+
uuid: string;
|
|
89
|
+
checkoutSessionId: string;
|
|
90
|
+
providerItemId: string;
|
|
91
|
+
providerItemName: string;
|
|
92
|
+
providerItemDescription?: string | null;
|
|
93
|
+
quantity: number;
|
|
94
|
+
totalAmount: number;
|
|
95
|
+
overrideAmount: number | null;
|
|
96
|
+
currency: string;
|
|
97
|
+
metadata?: Record<string, unknown> | null;
|
|
98
|
+
}
|
|
99
|
+
/** A subscription plan from a checkout session response. */
|
|
100
|
+
interface CheckoutSessionSubscription {
|
|
101
|
+
uuid: string;
|
|
102
|
+
checkoutSessionId: string;
|
|
103
|
+
providerPlanId: string;
|
|
104
|
+
providerPlanName: string;
|
|
105
|
+
providerPlanDescription?: string | null;
|
|
106
|
+
quantity: number;
|
|
107
|
+
totalAmount: number;
|
|
108
|
+
overrideAmount: number | null;
|
|
109
|
+
currency: string;
|
|
110
|
+
isUpdate?: boolean;
|
|
111
|
+
metadata?: Record<string, unknown> | null;
|
|
112
|
+
}
|
|
113
|
+
/** Represents a FloPay checkout session. */
|
|
114
|
+
interface CheckoutSession {
|
|
115
|
+
id: string;
|
|
116
|
+
clientSecret: string;
|
|
117
|
+
mode: 'payment' | 'subscription' | 'setup';
|
|
118
|
+
status: 'open' | 'complete' | 'expired';
|
|
119
|
+
amount: number;
|
|
120
|
+
currency: string;
|
|
121
|
+
lineItems?: LineItem[];
|
|
122
|
+
customer?: Customer;
|
|
123
|
+
metadata?: Record<string, string>;
|
|
124
|
+
checkoutMode?: CheckoutMode;
|
|
125
|
+
items?: CheckoutSessionItem[];
|
|
126
|
+
subscriptions?: CheckoutSessionSubscription[];
|
|
127
|
+
successUrl?: string;
|
|
128
|
+
cancelUrl?: string;
|
|
129
|
+
coupons?: string[];
|
|
130
|
+
createdAt?: string;
|
|
131
|
+
gateway?: BillingProvider;
|
|
132
|
+
gatewayData?: {
|
|
133
|
+
publishableKey?: string | null;
|
|
134
|
+
};
|
|
135
|
+
accountData?: {
|
|
136
|
+
userId: string;
|
|
137
|
+
email: string;
|
|
138
|
+
firstName: string;
|
|
139
|
+
lastName: string;
|
|
140
|
+
gender?: string | null;
|
|
141
|
+
city?: string | null;
|
|
142
|
+
state?: string | null;
|
|
143
|
+
country?: string | null;
|
|
144
|
+
zip?: string | null;
|
|
145
|
+
};
|
|
146
|
+
tagsData?: TagsData;
|
|
147
|
+
}
|
|
148
|
+
/** The result of a payment confirmation attempt. */
|
|
149
|
+
interface PaymentResult {
|
|
150
|
+
status: 'succeeded' | 'processing' | 'requires_action' | 'failed';
|
|
151
|
+
paymentIntentId?: string;
|
|
152
|
+
error?: FloPayError;
|
|
153
|
+
}
|
|
154
|
+
/** Parameters for confirming a payment. */
|
|
155
|
+
interface ConfirmPaymentParams {
|
|
156
|
+
clientSecret: string;
|
|
157
|
+
/** Optional redirect URL after 3-D Secure or wallet authentication. */
|
|
158
|
+
returnUrl?: string;
|
|
159
|
+
}
|
|
160
|
+
/** Result from creating a payment method (tokenizing card fields). */
|
|
161
|
+
interface CreatePaymentMethodResult {
|
|
162
|
+
paymentMethodId: string | null;
|
|
163
|
+
error?: FloPayError;
|
|
164
|
+
}
|
|
165
|
+
/** Parameters for confirming a card payment with a known client secret. */
|
|
166
|
+
interface ConfirmCardPaymentParams {
|
|
167
|
+
clientSecret: string;
|
|
168
|
+
paymentMethodId: string;
|
|
169
|
+
}
|
|
170
|
+
/** Result from confirming a card payment. */
|
|
171
|
+
interface ConfirmCardPaymentResult {
|
|
172
|
+
status: 'succeeded' | 'processing' | 'requires_action' | 'requires_capture' | 'failed';
|
|
173
|
+
paymentIntentId?: string;
|
|
174
|
+
paymentMethodId?: string;
|
|
175
|
+
error?: FloPayError;
|
|
176
|
+
}
|
|
177
|
+
/** The type of payment element to render. */
|
|
178
|
+
type ElementType = 'payment' | 'card' | 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'address';
|
|
179
|
+
/** Emitted when an element's internal state changes. */
|
|
180
|
+
interface ElementChangeEvent {
|
|
181
|
+
elementType: ElementType;
|
|
182
|
+
complete: boolean;
|
|
183
|
+
empty: boolean;
|
|
184
|
+
error?: {
|
|
185
|
+
message: string;
|
|
186
|
+
type: string;
|
|
187
|
+
};
|
|
188
|
+
/** Only populated for non-sensitive fields (e.g. address). */
|
|
189
|
+
value?: Record<string, unknown>;
|
|
190
|
+
}
|
|
191
|
+
/** Configuration options when creating an element. */
|
|
192
|
+
interface ElementOptions {
|
|
193
|
+
appearance?: FloPayAppearance;
|
|
194
|
+
/** Client secret for the PaymentIntent or SetupIntent. When present, Stripe uses it directly. */
|
|
195
|
+
clientSecret?: string;
|
|
196
|
+
/**
|
|
197
|
+
* Total amount in the smallest currency unit (e.g. cents).
|
|
198
|
+
* Used when no `clientSecret` is available — Stripe Elements needs
|
|
199
|
+
* `mode` + `amount` + `currency` to render without a server-side intent.
|
|
200
|
+
*/
|
|
201
|
+
amount?: number;
|
|
202
|
+
/** ISO 4217 currency code (lowercase). Used with `amount` when no `clientSecret`. */
|
|
203
|
+
currency?: string;
|
|
204
|
+
/** How payment methods are created. 'manual' = tokenize only, 'auto' = Stripe handles it. */
|
|
205
|
+
paymentMethodCreation?: 'manual' | 'auto';
|
|
206
|
+
layout?: 'tabs' | 'accordion' | 'auto';
|
|
207
|
+
defaultValues?: Record<string, unknown>;
|
|
208
|
+
readOnly?: boolean;
|
|
209
|
+
/** Address element mode: 'billing' or 'shipping'. */
|
|
210
|
+
mode?: 'billing' | 'shipping';
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* A payment element that has been created and can be mounted into the DOM.
|
|
214
|
+
*
|
|
215
|
+
* TODO: In a future phase, each MountedElement will render inside an iframe
|
|
216
|
+
* for PCI DSS SAQ-A compliance. For now, it wraps the underlying provider
|
|
217
|
+
* element directly.
|
|
218
|
+
*/
|
|
219
|
+
interface MountedElement {
|
|
220
|
+
mount(container: HTMLElement): void;
|
|
221
|
+
unmount(): void;
|
|
222
|
+
update(options: Partial<ElementOptions>): void;
|
|
223
|
+
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
224
|
+
off(event: string, handler: (...args: unknown[]) => void): void;
|
|
225
|
+
destroy(): void;
|
|
226
|
+
}
|
|
227
|
+
/** Top-level configuration for initializing FloPay. */
|
|
228
|
+
interface FloPayConfig {
|
|
229
|
+
publishableKey: string;
|
|
230
|
+
/** Billing API base URL (e.g. https://api.stage.flopay.com). */
|
|
231
|
+
billingApiUrl?: string;
|
|
232
|
+
locale?: string;
|
|
233
|
+
appearance?: FloPayAppearance;
|
|
234
|
+
apiVersion?: string;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Abstraction layer for payment providers.
|
|
238
|
+
*
|
|
239
|
+
* Currently only Stripe is implemented (`StripeAdapter`). The interface
|
|
240
|
+
* ensures that adding new providers (Chargebee, Recurly, etc.) will not
|
|
241
|
+
* require changes in consumer code.
|
|
242
|
+
*/
|
|
243
|
+
interface PaymentProviderAdapter {
|
|
244
|
+
readonly name: string;
|
|
245
|
+
initialize(config: FloPayConfig): Promise<void>;
|
|
246
|
+
createElement(type: ElementType, options: ElementOptions): Promise<MountedElement>;
|
|
247
|
+
/** Retrieve an existing element by type, or `null` if not yet created. */
|
|
248
|
+
getElement(type: ElementType): MountedElement | null;
|
|
249
|
+
/** Submit elements for validation (Stripe `elements.submit()`). */
|
|
250
|
+
submitElements(): Promise<{
|
|
251
|
+
error?: FloPayError;
|
|
252
|
+
}>;
|
|
253
|
+
/** Create a payment method from the current elements (tokenize card). */
|
|
254
|
+
createPaymentMethod(): Promise<CreatePaymentMethodResult>;
|
|
255
|
+
/** Confirm a card payment with a known client secret and payment method. */
|
|
256
|
+
confirmCardPayment(params: ConfirmCardPaymentParams): Promise<ConfirmCardPaymentResult>;
|
|
257
|
+
confirmPayment(params: ConfirmPaymentParams): Promise<PaymentResult>;
|
|
258
|
+
/**
|
|
259
|
+
* Create a PayPal payment: create PM → create intent → confirm with redirect.
|
|
260
|
+
* Returns the confirmed PaymentIntent ID if completed inline, or redirects to PayPal.
|
|
261
|
+
*/
|
|
262
|
+
confirmPayPalPayment(params: {
|
|
263
|
+
billingApiUrl: string;
|
|
264
|
+
sessionId: string;
|
|
265
|
+
email: string;
|
|
266
|
+
returnUrl: string;
|
|
267
|
+
}): Promise<ConfirmCardPaymentResult>;
|
|
268
|
+
/**
|
|
269
|
+
* Resume a PayPal payment after redirect return.
|
|
270
|
+
* Checks URL params for payment_intent + redirect_status.
|
|
271
|
+
*/
|
|
272
|
+
resumePayPalPayment(): Promise<ConfirmCardPaymentResult | null>;
|
|
273
|
+
/**
|
|
274
|
+
* Get the raw underlying provider instance (e.g. Stripe object).
|
|
275
|
+
* Used internally for creating secondary Elements groups (e.g. PayPal).
|
|
276
|
+
*/
|
|
277
|
+
getRawProvider(): unknown;
|
|
278
|
+
/**
|
|
279
|
+
* Create a secondary Elements group for PayPal.
|
|
280
|
+
* PayPal can't share Elements with card fields that use paymentMethodCreation: 'manual'.
|
|
281
|
+
*/
|
|
282
|
+
createPayPalElements(options: ElementOptions): unknown;
|
|
283
|
+
destroy(): void;
|
|
284
|
+
}
|
|
285
|
+
/** Supported upstream billing providers. */
|
|
286
|
+
type BillingProvider = 'recurly' | 'chargebee' | 'stripe';
|
|
287
|
+
/** Token payload produced by client-side tokenization. */
|
|
288
|
+
interface TokenizedBody {
|
|
289
|
+
id?: string;
|
|
290
|
+
type?: string;
|
|
291
|
+
threeDSecureActionResultTokenId?: string;
|
|
292
|
+
isPaypal?: boolean;
|
|
293
|
+
}
|
|
294
|
+
/** Checkout mode: tokenize client-side or redirect to hosted page. */
|
|
295
|
+
type CheckoutModeKind = 'tokenize' | 'redirect';
|
|
296
|
+
/** Provider-agnostic normalized checkout session. */
|
|
297
|
+
interface NormalizedCheckoutSession {
|
|
298
|
+
provider: BillingProvider;
|
|
299
|
+
mode: CheckoutModeKind;
|
|
300
|
+
data: {
|
|
301
|
+
hostedUrl?: string;
|
|
302
|
+
clientToken?: string;
|
|
303
|
+
session?: CheckoutSession;
|
|
304
|
+
chargebee?: {
|
|
305
|
+
site?: string;
|
|
306
|
+
publishableKey?: string;
|
|
307
|
+
dropInToken?: string;
|
|
308
|
+
sessionId?: string;
|
|
309
|
+
};
|
|
310
|
+
stripe?: {
|
|
311
|
+
clientSecret?: string;
|
|
312
|
+
publishableKey?: string;
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
raw?: unknown;
|
|
316
|
+
}
|
|
317
|
+
/** A one-time purchase item for checkout session creation. */
|
|
318
|
+
interface CheckoutItem {
|
|
319
|
+
/** The provider's item/product ID (e.g. Stripe price ID, Recurly plan code). */
|
|
320
|
+
providerItemId: string;
|
|
321
|
+
/** Display name for the item. */
|
|
322
|
+
providerItemName?: string | null;
|
|
323
|
+
/** Defaults to 1. */
|
|
324
|
+
quantity?: number;
|
|
325
|
+
/** The regular (full) price in the given currency. */
|
|
326
|
+
totalAmount: number;
|
|
327
|
+
/** A discounted price to charge instead of totalAmount. */
|
|
328
|
+
overrideAmount?: number | null;
|
|
329
|
+
/** ISO 4217 currency code. Defaults to 'USD'. */
|
|
330
|
+
currency?: string;
|
|
331
|
+
}
|
|
332
|
+
/** A recurring subscription plan for checkout session creation. */
|
|
333
|
+
interface CheckoutSubscription {
|
|
334
|
+
/** The provider's plan ID. */
|
|
335
|
+
providerPlanId: string;
|
|
336
|
+
/** Display name for the plan. */
|
|
337
|
+
providerPlanName?: string | null;
|
|
338
|
+
/** Defaults to 1. */
|
|
339
|
+
quantity?: number;
|
|
340
|
+
/** The regular (full) price in the given currency. */
|
|
341
|
+
totalAmount: number;
|
|
342
|
+
/** A discounted price to charge instead of totalAmount. */
|
|
343
|
+
overrideAmount?: number | null;
|
|
344
|
+
/** ISO 4217 currency code. Defaults to 'USD'. */
|
|
345
|
+
currency?: string;
|
|
346
|
+
}
|
|
347
|
+
/** Buyer's account information for session creation. */
|
|
348
|
+
interface CheckoutAccount {
|
|
349
|
+
userId: string;
|
|
350
|
+
firstName?: string;
|
|
351
|
+
lastName?: string;
|
|
352
|
+
email: string;
|
|
353
|
+
country?: string | null;
|
|
354
|
+
gender?: string | null;
|
|
355
|
+
city?: string | null;
|
|
356
|
+
state?: string | null;
|
|
357
|
+
zip?: string | null;
|
|
358
|
+
}
|
|
359
|
+
/** Analytics / pixel tags forwarded to the checkout page. */
|
|
360
|
+
interface TagsData {
|
|
361
|
+
googleContainerId?: string | null;
|
|
362
|
+
sessionId?: string | null;
|
|
363
|
+
testEventCode?: string | null;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Parameters for creating a checkout session via the billing API.
|
|
367
|
+
* Mirrors the `CreateCheckoutSessionOptions` from clicktech-core-ui.
|
|
368
|
+
*/
|
|
369
|
+
interface CreateSessionParams {
|
|
370
|
+
/** Base URL of the billing API, e.g. https://billing.clicktech.com */
|
|
371
|
+
billingApiUrl: string;
|
|
372
|
+
/** Base URL of the checkout frontend, e.g. https://checkout.clicktech.com */
|
|
373
|
+
checkoutBaseUrl: string;
|
|
374
|
+
/** The client ID for the checkout session. */
|
|
375
|
+
clientId: string;
|
|
376
|
+
/** One-time purchase items. */
|
|
377
|
+
items?: CheckoutItem[];
|
|
378
|
+
/** Recurring subscription plans. */
|
|
379
|
+
subscriptions?: CheckoutSubscription[];
|
|
380
|
+
/** Buyer's account information. */
|
|
381
|
+
account: CheckoutAccount;
|
|
382
|
+
/** URL to redirect to after successful payment. */
|
|
383
|
+
successUrl: string;
|
|
384
|
+
/** URL to redirect to if the user cancels. */
|
|
385
|
+
cancelUrl: string;
|
|
386
|
+
/**
|
|
387
|
+
* Checkout mode sent to the billing API.
|
|
388
|
+
* - 'confirm' – show a payment confirmation page (default)
|
|
389
|
+
* - 'auto' – skip confirmation when a payment method is already on file
|
|
390
|
+
* - 'full' – full checkout flow
|
|
391
|
+
*/
|
|
392
|
+
checkoutMode?: 'confirm' | 'auto' | 'full';
|
|
393
|
+
/** Coupon codes to apply. */
|
|
394
|
+
couponCodes?: string[];
|
|
395
|
+
/** Pixel / analytics tags forwarded to the checkout page. */
|
|
396
|
+
tagsData?: TagsData;
|
|
397
|
+
/** Extra query params appended to the checkout redirect URL. */
|
|
398
|
+
redirectParams?: Record<string, string>;
|
|
399
|
+
/** Whether to set the checkout_data cookie. Defaults to true. */
|
|
400
|
+
setCookie?: boolean;
|
|
401
|
+
/** Request timeout in milliseconds. Defaults to 12000. */
|
|
402
|
+
timeoutMs?: number;
|
|
403
|
+
/** UTM and funnel tracking metadata. */
|
|
404
|
+
utmMetadata?: Record<string, string | null | undefined>[];
|
|
405
|
+
}
|
|
406
|
+
/** Result from creating a checkout session. */
|
|
407
|
+
type CheckoutSessionResult = {
|
|
408
|
+
status: 201;
|
|
409
|
+
redirectUrl: string;
|
|
410
|
+
} | {
|
|
411
|
+
status: 204;
|
|
412
|
+
} | {
|
|
413
|
+
status: number;
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* Data submitted when processing a payment (tokenized card/wallet data).
|
|
417
|
+
* Mirrors checkout project's ProcessCheckoutBodyDto.
|
|
418
|
+
*/
|
|
419
|
+
interface ProcessPaymentParams {
|
|
420
|
+
sessionId: string;
|
|
421
|
+
tokenizedData?: TokenizedBody;
|
|
422
|
+
accountData: {
|
|
423
|
+
userId: string;
|
|
424
|
+
email: string;
|
|
425
|
+
firstName: string;
|
|
426
|
+
lastName: string;
|
|
427
|
+
zip?: string;
|
|
428
|
+
country?: string;
|
|
429
|
+
};
|
|
430
|
+
chv?: string;
|
|
431
|
+
}
|
|
432
|
+
/** Parameters for creating a customer. */
|
|
433
|
+
interface CreateCustomerParams {
|
|
434
|
+
email: string;
|
|
435
|
+
name?: string;
|
|
436
|
+
metadata?: Record<string, string>;
|
|
437
|
+
}
|
|
438
|
+
/** Parameters for updating a customer. */
|
|
439
|
+
interface UpdateCustomerParams {
|
|
440
|
+
email?: string;
|
|
441
|
+
name?: string;
|
|
442
|
+
metadata?: Record<string, string>;
|
|
443
|
+
}
|
|
444
|
+
/** A webhook event from FloPay. */
|
|
445
|
+
interface WebhookEvent {
|
|
446
|
+
id: string;
|
|
447
|
+
type: string;
|
|
448
|
+
data: Record<string, unknown>;
|
|
449
|
+
created: number;
|
|
450
|
+
}
|
|
451
|
+
/** Currency information mapped to a country. */
|
|
452
|
+
interface CurrencyInfo {
|
|
453
|
+
currency: string;
|
|
454
|
+
symbol: string;
|
|
455
|
+
country: string;
|
|
456
|
+
countryCode: string;
|
|
457
|
+
/** 0 = no tax, 1 = tax (VAT) applies. */
|
|
458
|
+
tax: number;
|
|
459
|
+
}
|
|
460
|
+
/** A country option for UI select elements. */
|
|
461
|
+
interface CountryOption {
|
|
462
|
+
code: string;
|
|
463
|
+
name: string;
|
|
464
|
+
flag: string;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/** FloPay environment — determines which billing API URL is used. */
|
|
468
|
+
type FloPayEnvironment = 'staging' | 'production';
|
|
469
|
+
/**
|
|
470
|
+
* Configure the FloPay SDK globally. Call once at app startup.
|
|
471
|
+
*
|
|
472
|
+
* The environment determines which billing API URL is used for all
|
|
473
|
+
* FloPay operations (session creation, payment processing, etc.).
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```ts
|
|
477
|
+
* import { configureFlopay } from '@flopay/shared';
|
|
478
|
+
*
|
|
479
|
+
* // In production
|
|
480
|
+
* configureFlopay({ environment: 'production' });
|
|
481
|
+
*
|
|
482
|
+
* // In staging/development
|
|
483
|
+
* configureFlopay({ environment: 'staging' });
|
|
484
|
+
* ```
|
|
485
|
+
*
|
|
486
|
+
* Alternatively, set the `NEXT_PUBLIC_FLOPAY_ENV` environment variable
|
|
487
|
+
* to `'staging'` or `'production'` — the SDK reads it automatically.
|
|
488
|
+
*/
|
|
489
|
+
declare function configureFlopay(config: {
|
|
490
|
+
environment: FloPayEnvironment;
|
|
491
|
+
}): void;
|
|
492
|
+
/** Get the billing API URL for the currently configured environment. */
|
|
493
|
+
declare function getConfiguredBillingApiUrl(): string;
|
|
494
|
+
/** Get the current configured environment. */
|
|
495
|
+
declare function getFloPayEnvironment(): FloPayEnvironment;
|
|
496
|
+
|
|
497
|
+
/** Current SDK version. */
|
|
498
|
+
declare const SDK_VERSION = "0.1.0";
|
|
499
|
+
/** Billing API URL for staging environment. */
|
|
500
|
+
declare const BILLING_API_URL_STAGING = "https://api.stage.flopay.com";
|
|
501
|
+
/** Billing API URL for production environment. */
|
|
502
|
+
declare const BILLING_API_URL_PRODUCTION = "https://api.flopay.com";
|
|
503
|
+
/** Default FloPay API base URL (used by @flopay/node). Alias for staging. */
|
|
504
|
+
declare const DEFAULT_API_BASE_URL = "https://api.stage.flopay.com";
|
|
505
|
+
/** Default billing API base URL. Alias for staging — prefer `resolveBillingApiUrl()`. */
|
|
506
|
+
declare const BILLING_API_URL = "https://api.stage.flopay.com";
|
|
507
|
+
/**
|
|
508
|
+
* Resolve the billing API URL from available configuration.
|
|
509
|
+
*
|
|
510
|
+
* Priority:
|
|
511
|
+
* 1. Explicit `billingApiUrl` (prop/param override)
|
|
512
|
+
* 2. `NEXT_PUBLIC_FLOPAY_ENV` environment variable (`'staging'` | `'production'`)
|
|
513
|
+
* 3. `configureFlopay()` global environment setting
|
|
514
|
+
* 4. Fallback: staging URL
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```ts
|
|
518
|
+
* import { resolveBillingApiUrl } from '@flopay/shared';
|
|
519
|
+
*
|
|
520
|
+
* // Reads from env var or configureFlopay() — no args needed
|
|
521
|
+
* const url = resolveBillingApiUrl();
|
|
522
|
+
*
|
|
523
|
+
* // Explicit override takes priority
|
|
524
|
+
* const url = resolveBillingApiUrl('https://custom.example.com');
|
|
525
|
+
* ```
|
|
526
|
+
*/
|
|
527
|
+
declare function resolveBillingApiUrl(billingApiUrl?: string): string;
|
|
528
|
+
/** Default API version header value. */
|
|
529
|
+
declare const DEFAULT_API_VERSION = "2024-01-01";
|
|
530
|
+
/** The default appearance applied when no custom appearance is provided. */
|
|
531
|
+
declare const DEFAULT_APPEARANCE: FloPayAppearance;
|
|
532
|
+
/** Flat theme — minimal borders and shadows. */
|
|
533
|
+
declare const FLAT_APPEARANCE: FloPayAppearance;
|
|
534
|
+
/** Night theme — dark background. */
|
|
535
|
+
declare const NIGHT_APPEARANCE: FloPayAppearance;
|
|
536
|
+
/** All supported element type identifiers. */
|
|
537
|
+
declare const ELEMENT_TYPES: readonly ["payment", "card", "cardNumber", "cardExpiry", "cardCvc", "address"];
|
|
538
|
+
declare const SUPPORTED_CARD_BRANDS: readonly ["visa", "mastercard", "mastercard_debit", "amex", "discover"];
|
|
539
|
+
/** Country code to currency information mapping. */
|
|
540
|
+
declare const CURRENCY_MAP: Record<string, CurrencyInfo>;
|
|
541
|
+
/** Default currency info when country is unknown. */
|
|
542
|
+
declare const DEFAULT_CURRENCY: CurrencyInfo;
|
|
543
|
+
|
|
544
|
+
/** A single line item formatted for display in the checkout UI. */
|
|
545
|
+
interface DisplayLineItem {
|
|
546
|
+
name: string;
|
|
547
|
+
quantity: number;
|
|
548
|
+
/** Price per unit in the session's currency (major units, e.g. 24.95). */
|
|
549
|
+
price: number;
|
|
550
|
+
/** Original price per unit before any discount (major units). */
|
|
551
|
+
originalPrice: number;
|
|
552
|
+
}
|
|
553
|
+
/** Computed display data for rendering an order summary. */
|
|
554
|
+
interface CheckoutDisplayData {
|
|
555
|
+
/** Individual items/subscriptions with names, prices, and quantities. */
|
|
556
|
+
items: DisplayLineItem[];
|
|
557
|
+
/** ISO 4217 currency code (uppercase). */
|
|
558
|
+
currency: string;
|
|
559
|
+
/** Total amount due after discounts (major units, e.g. 24.95). */
|
|
560
|
+
total: number;
|
|
561
|
+
/** Sum of original prices before discounts (major units). */
|
|
562
|
+
originalTotal: number;
|
|
563
|
+
/** Total savings (originalTotal - total), clamped to >= 0. */
|
|
564
|
+
totalSave: number;
|
|
565
|
+
/** Discount percentage (0–100). */
|
|
566
|
+
discountPercent: number;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Builds display data from a `CheckoutSession` for rendering an order summary.
|
|
570
|
+
*
|
|
571
|
+
* Matches the display logic in checkout/CheckoutModal exactly:
|
|
572
|
+
* - Subscriptions are always shown
|
|
573
|
+
* - Items are hidden when the session has both subscriptions AND items
|
|
574
|
+
* - `overrideAmount` (when not null/undefined) is the discounted price
|
|
575
|
+
* - Plan name "4-WEEK PLAN" with price <= 1 is renamed to "7-DAY TRIAL: FULL ACCESS"
|
|
576
|
+
* - Discount percentage and savings are computed from the difference
|
|
577
|
+
*
|
|
578
|
+
* All amounts are in **major currency units** (dollars, not cents).
|
|
579
|
+
*
|
|
580
|
+
* @example
|
|
581
|
+
* ```ts
|
|
582
|
+
* import { buildCheckoutDisplayData } from '@flopay/shared';
|
|
583
|
+
*
|
|
584
|
+
* const display = buildCheckoutDisplayData(session);
|
|
585
|
+
* // display.items → [{ name: 'Starter', price: 24.95, originalPrice: 24.95, quantity: 1 }]
|
|
586
|
+
* // display.total → 24.95
|
|
587
|
+
* // display.currency → 'EUR'
|
|
588
|
+
* ```
|
|
589
|
+
*/
|
|
590
|
+
declare function buildCheckoutDisplayData(session: CheckoutSession): CheckoutDisplayData;
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Look up currency information by ISO 3166-1 alpha-2 country code.
|
|
594
|
+
* Falls back to USD when the country is not in the map.
|
|
595
|
+
*/
|
|
596
|
+
declare function getCurrencyByCountry(countryCode: string): CurrencyInfo;
|
|
597
|
+
/** Returns `true` if the string looks like a Stripe publishable key. */
|
|
598
|
+
declare function isValidPublishableKey(key: string): boolean;
|
|
599
|
+
/** Returns `true` if the string looks like a Stripe secret key. */
|
|
600
|
+
declare function isValidSecretKey(key: string): boolean;
|
|
601
|
+
|
|
602
|
+
export { BILLING_API_URL, BILLING_API_URL_PRODUCTION, BILLING_API_URL_STAGING, type BillingProvider, CURRENCY_MAP, type CheckoutAccount, type CheckoutDisplayData, type CheckoutItem, type CheckoutMode, type CheckoutModeKind, type CheckoutSession, type CheckoutSessionItem, type CheckoutSessionResult, type CheckoutSessionSubscription, type CheckoutSubscription, type ConfirmCardPaymentParams, type ConfirmCardPaymentResult, type ConfirmPaymentParams, type CountryOption, type CreateCustomerParams, type CreatePaymentMethodResult, type CreateSessionParams, type CurrencyInfo, type Customer, DEFAULT_API_BASE_URL, DEFAULT_API_VERSION, DEFAULT_APPEARANCE, DEFAULT_CURRENCY, type DisplayLineItem, ELEMENT_TYPES, type ElementChangeEvent, type ElementOptions, type ElementType, FLAT_APPEARANCE, type FloPayAppearance, type FloPayConfig, type FloPayEnvironment, FloPayError, type FloPayErrorType, type FloPayThemeVariables, type LineItem, type MountedElement, NIGHT_APPEARANCE, type NormalizedCheckoutSession, type PaymentProviderAdapter, type PaymentResult, type PriceData, type ProcessPaymentParams, type RecurringInterval, SDK_VERSION, SUPPORTED_CARD_BRANDS, type TagsData, type TokenizedBody, type UpdateCustomerParams, type WebhookEvent, apiError, authenticationError, buildCheckoutDisplayData, configureFlopay, getConfiguredBillingApiUrl, getCurrencyByCountry, getFloPayEnvironment, isValidPublishableKey, isValidSecretKey, networkError, rateLimitError, resolveBillingApiUrl, validationError };
|