@solvapay/react 1.0.8-preview.9 → 1.0.9
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/CHANGELOG.md +209 -0
- package/README.md +194 -25
- package/dist/adapters/auth.d.cts +13 -0
- package/dist/adapters/auth.d.ts +13 -0
- package/dist/adapters/auth.js +1 -0
- package/dist/{chunk-MOP3ZBGC.js → chunk-37R5NZGF.js} +1116 -1041
- package/dist/chunk-HWVJL5X6.js +429 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-R2ZPZ7VM.js +597 -0
- package/dist/chunk-ZAV7CQ4G.js +361 -0
- package/dist/index-WBjulQHf.d.cts +3656 -0
- package/dist/index-onWNU7iT.d.ts +3656 -0
- package/dist/index.cjs +1422 -366
- package/dist/index.d.cts +251 -64
- package/dist/index.d.ts +251 -64
- package/dist/index.js +54 -26
- package/dist/mcp/index.cjs +8096 -0
- package/dist/mcp/index.d.cts +1013 -0
- package/dist/mcp/index.d.ts +1013 -0
- package/dist/mcp/index.js +2724 -0
- package/dist/mcp/styles.css +1020 -0
- package/dist/primitives/index.cjs +1177 -115
- package/dist/primitives/index.d.cts +208 -20
- package/dist/primitives/index.d.ts +208 -20
- package/dist/primitives/index.js +66 -21
- package/dist/styles.css +246 -0
- package/dist/useUsage-BmOYXxgG.d.cts +413 -0
- package/dist/useUsage-nD7zwSbG.d.ts +413 -0
- package/dist/webapi-K5XBCEO6.js +3775 -0
- package/package.json +20 -4
- package/dist/CancelPlanButton-CieT9swn.d.cts +0 -1102
- package/dist/CancelPlanButton-f56UlQN-.d.ts +0 -1102
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { S as SolvaPayProviderProps, P as PaymentFormProps, a as PrefillCustomer,
|
|
3
|
-
export {
|
|
2
|
+
import { S as SolvaPayProviderProps, P as PaymentFormProps, a as PrefillCustomer, T as TopupFormProps, C as CheckoutResult, b as Plan, A as ActivationResult, c as PurchaseStatus, d as SolvaPayContextValue, U as UsePlansOptions, e as UsePlansReturn, f as UsePlanOptions, g as UsePlanReturn, h as UseProductReturn, i as UseMerchantReturn, j as SolvaPayCopy, k as PurchaseStatusReturn, l as CancelResult, R as ReactivateResult, m as ActivatePlanResult, n as UseTopupOptions, o as UseTopupReturn, B as BalanceStatus, p as UseTopupAmountSelectorOptions, q as UseTopupAmountSelectorReturn, r as UsePaymentMethodReturn, s as SolvaPayTransport, t as PaywallStructuredContent, u as PartialSolvaPayCopy, v as PurchaseInfo, w as Product, x as SolvaPayConfig } from './index-onWNU7iT.js';
|
|
3
|
+
export { y as CustomerPurchaseData, M as MandateContext, z as MandateTemplate, D as Merchant, E as PaymentError, F as PaymentIntentResult, G as PaymentMethodInfo, H as PaymentResult, I as PurchaseStatusValue, J as TopupPaymentResult, K as TransportBalanceResult, L as TransportCheckoutSessionResult, N as TransportCustomerSessionResult, O as UnsupportedTransportMethodError } from './index-onWNU7iT.js';
|
|
4
|
+
import { P as PaymentFormSummary, a as PaymentFormCustomerFields, b as PaymentFormPaymentElement, c as PaymentFormCardElement, d as PaymentFormMandateText, e as PaymentFormTermsCheckbox, f as PaymentFormSubmitButton, g as PaymentFormLoading, h as PaymentFormError, C as CheckoutVariant } from './useUsage-nD7zwSbG.js';
|
|
5
|
+
export { A as ActivationFlowStep, B as BalanceBadge, i as CancelPlanButton, j as CheckoutSummary, k as CheckoutSummaryProps, M as MandateText, l as MandateTextProps, m as PlanBadge, n as ProductBadge, o as PurchaseGate, U as UsageSnapshot, p as UseUsageReturn, q as deriveVariant, u as useUsage } from './useUsage-nD7zwSbG.js';
|
|
4
6
|
import { PaymentIntent, Stripe, StripeElements } from '@stripe/stripe-js';
|
|
5
|
-
import { ActivatePlanResult } from '@solvapay/server';
|
|
6
|
-
export { ActivatePlanResult } from '@solvapay/server';
|
|
7
7
|
export { AuthAdapter, defaultAuthAdapter } from './adapters/auth.js';
|
|
8
8
|
import '@stripe/react-stripe-js';
|
|
9
9
|
|
|
@@ -14,77 +14,39 @@ import '@stripe/react-stripe-js';
|
|
|
14
14
|
* via React Context. This is the root component that must wrap your app to use
|
|
15
15
|
* SolvaPay React hooks and components.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* - Authentication adapter support (Supabase, custom, etc.)
|
|
22
|
-
* - Zero-config with sensible defaults, or full customization
|
|
23
|
-
*
|
|
24
|
-
* @param props - Provider configuration
|
|
25
|
-
* @param props.config - Configuration object for API routes and authentication
|
|
26
|
-
* @param props.config.api - API route configuration (optional, uses defaults if not provided)
|
|
27
|
-
* @param props.config.api.checkPurchase - Endpoint for checking purchase status (default: '/api/check-purchase')
|
|
28
|
-
* @param props.config.api.createPayment - Endpoint for creating payment intents (default: '/api/create-payment-intent')
|
|
29
|
-
* @param props.config.api.processPayment - Endpoint for processing payments (default: '/api/process-payment')
|
|
30
|
-
* @param props.config.auth - Authentication configuration (optional)
|
|
31
|
-
* @param props.config.auth.adapter - Auth adapter for extracting user ID and token
|
|
32
|
-
* @param props.children - React children components
|
|
17
|
+
* All data access flows through `config.transport`. When omitted, a default
|
|
18
|
+
* HTTP transport is built from `config.api` + `config.fetch`. Integrators who
|
|
19
|
+
* need to route calls somewhere else (e.g. MCP hosts) pass a custom transport
|
|
20
|
+
* — see `@solvapay/react/mcp` and `createHttpTransport` for building blocks.
|
|
33
21
|
*
|
|
34
22
|
* @example
|
|
35
23
|
* ```tsx
|
|
36
|
-
* import { SolvaPayProvider } from '@solvapay/react'
|
|
24
|
+
* import { SolvaPayProvider } from '@solvapay/react'
|
|
37
25
|
*
|
|
38
|
-
* // Zero config (uses defaults)
|
|
39
26
|
* function App() {
|
|
40
27
|
* return (
|
|
41
28
|
* <SolvaPayProvider>
|
|
42
29
|
* <YourApp />
|
|
43
30
|
* </SolvaPayProvider>
|
|
44
|
-
* )
|
|
31
|
+
* )
|
|
45
32
|
* }
|
|
33
|
+
* ```
|
|
46
34
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* config={{
|
|
52
|
-
* api: {
|
|
53
|
-
* checkPurchase: '/custom/api/purchase',
|
|
54
|
-
* createPayment: '/custom/api/payment'
|
|
55
|
-
* }
|
|
56
|
-
* }}
|
|
57
|
-
* >
|
|
58
|
-
* <YourApp />
|
|
59
|
-
* </SolvaPayProvider>
|
|
60
|
-
* );
|
|
61
|
-
* }
|
|
35
|
+
* @example MCP App
|
|
36
|
+
* ```tsx
|
|
37
|
+
* import { SolvaPayProvider } from '@solvapay/react'
|
|
38
|
+
* import { createMcpAppAdapter } from '@solvapay/react/mcp'
|
|
62
39
|
*
|
|
63
|
-
*
|
|
64
|
-
* import { createSupabaseAuthAdapter } from '@solvapay/react-supabase';
|
|
40
|
+
* const transport = createMcpAppAdapter(app)
|
|
65
41
|
*
|
|
66
42
|
* function App() {
|
|
67
|
-
* const adapter = createSupabaseAuthAdapter({
|
|
68
|
-
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
69
|
-
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
70
|
-
* });
|
|
71
|
-
*
|
|
72
43
|
* return (
|
|
73
|
-
* <SolvaPayProvider
|
|
74
|
-
* config={{
|
|
75
|
-
* auth: { adapter }
|
|
76
|
-
* }}
|
|
77
|
-
* >
|
|
44
|
+
* <SolvaPayProvider config={{ transport }}>
|
|
78
45
|
* <YourApp />
|
|
79
46
|
* </SolvaPayProvider>
|
|
80
|
-
* )
|
|
47
|
+
* )
|
|
81
48
|
* }
|
|
82
49
|
* ```
|
|
83
|
-
*
|
|
84
|
-
* @see {@link usePurchase} for accessing purchase data
|
|
85
|
-
* @see {@link useCheckout} for payment checkout flow
|
|
86
|
-
* @see {@link useSolvaPay} for accessing provider methods
|
|
87
|
-
* @since 1.0.0
|
|
88
50
|
*/
|
|
89
51
|
declare const SolvaPayProvider: React.FC<SolvaPayProviderProps>;
|
|
90
52
|
|
|
@@ -132,12 +94,20 @@ declare const PaymentForm: React.FC<PaymentFormRootProps> & {
|
|
|
132
94
|
declare const TopupForm: React.FC<TopupFormProps>;
|
|
133
95
|
|
|
134
96
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
97
|
+
* SDK-scoped SVG spinner. Self-contained: SVG `width`/`height` and inline
|
|
98
|
+
* stroke/fill opacity guarantee the visual regardless of consumer CSS.
|
|
99
|
+
* Rotation is driven by the `[data-solvapay-spinner]` rule in `styles.css`,
|
|
100
|
+
* so it only animates when consumers import `@solvapay/react/styles.css`
|
|
101
|
+
* (or target the attribute themselves).
|
|
137
102
|
*/
|
|
103
|
+
declare const SIZE_PX: {
|
|
104
|
+
readonly sm: 16;
|
|
105
|
+
readonly md: 20;
|
|
106
|
+
readonly lg: 24;
|
|
107
|
+
};
|
|
138
108
|
declare const Spinner: React.FC<{
|
|
139
109
|
className?: string;
|
|
140
|
-
size?:
|
|
110
|
+
size?: keyof typeof SIZE_PX;
|
|
141
111
|
}>;
|
|
142
112
|
|
|
143
113
|
interface StripePaymentFormWrapperProps {
|
|
@@ -308,6 +278,119 @@ interface CreditGateProps {
|
|
|
308
278
|
}
|
|
309
279
|
declare const CreditGate: React.FC<CreditGateProps>;
|
|
310
280
|
|
|
281
|
+
/**
|
|
282
|
+
* `<CurrentPlanCard>` — summary card for the customer's active purchase.
|
|
283
|
+
*
|
|
284
|
+
* Pure projection of existing provider state (`usePurchase`,
|
|
285
|
+
* `usePurchaseStatus`, `useBalance`, `usePaymentMethod`) plus Phase 1
|
|
286
|
+
* action components (`<CancelPlanButton>`, Phase 2's
|
|
287
|
+
* `<UpdatePaymentMethodButton>`). No Stripe Elements dependency, so the
|
|
288
|
+
* default tree renders identically inside an MCP host sandbox and a
|
|
289
|
+
* standalone HTTP app.
|
|
290
|
+
*
|
|
291
|
+
* Returns `null` when `usePurchase()` reports no active purchase, so
|
|
292
|
+
* integrators can drop it into account pages without wrapping in
|
|
293
|
+
* `{hasPaidPurchase && ...}`.
|
|
294
|
+
*
|
|
295
|
+
* Plan-type-aware lines:
|
|
296
|
+
* - `recurring` — "Next billing: {date}"
|
|
297
|
+
* - `one-time` — "Expires {date}" or "Valid indefinitely"
|
|
298
|
+
* - `usage-based` — `<BalanceBadge>` line; no date
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
interface CurrentPlanCardClassNames {
|
|
302
|
+
root?: string;
|
|
303
|
+
heading?: string;
|
|
304
|
+
planName?: string;
|
|
305
|
+
productContext?: string;
|
|
306
|
+
price?: string;
|
|
307
|
+
dateLine?: string;
|
|
308
|
+
balanceLine?: string;
|
|
309
|
+
usageMeter?: string;
|
|
310
|
+
paymentMethod?: string;
|
|
311
|
+
actions?: string;
|
|
312
|
+
}
|
|
313
|
+
interface CurrentPlanCardProps {
|
|
314
|
+
/** Hide the payment-method line even when the endpoint returns a card. Default: `false`. */
|
|
315
|
+
hidePaymentMethod?: boolean;
|
|
316
|
+
/** Hide the "Cancel plan" action. Default: `false`. */
|
|
317
|
+
hideCancelButton?: boolean;
|
|
318
|
+
/** Hide the "Update card" action. Default: `false`. */
|
|
319
|
+
hideUpdatePaymentButton?: boolean;
|
|
320
|
+
/**
|
|
321
|
+
* Hide the `<UsageMeter>` that automatically renders for usage-based
|
|
322
|
+
* plans. Default: `false` (meter renders whenever the active plan has
|
|
323
|
+
* a quota).
|
|
324
|
+
*/
|
|
325
|
+
hideUsageMeter?: boolean;
|
|
326
|
+
/** Per-element classNames. */
|
|
327
|
+
classNames?: CurrentPlanCardClassNames;
|
|
328
|
+
/**
|
|
329
|
+
* Custom className on the root. Appended after `solvapay-current-plan-card`
|
|
330
|
+
* so integrators can tweak without losing the SDK baseline.
|
|
331
|
+
*/
|
|
332
|
+
className?: string;
|
|
333
|
+
}
|
|
334
|
+
declare const CurrentPlanCard: React.FC<CurrentPlanCardProps>;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* `<LaunchCustomerPortalButton>` — opens the SolvaPay hosted customer
|
|
338
|
+
* portal in a new browser tab.
|
|
339
|
+
*
|
|
340
|
+
* Works identically in HTTP and MCP contexts because it routes through
|
|
341
|
+
* `transport.createCustomerSession()` (either HTTP `/api/create-customer-session`
|
|
342
|
+
* or MCP `create_customer_session` tool). The portal URL is pre-fetched on
|
|
343
|
+
* mount so the click handler can navigate via a real `<a target="_blank">`,
|
|
344
|
+
* which MCP host sandboxes permit (scripted `window.open` after an async
|
|
345
|
+
* round-trip is blocked — see `mcp-checkout-app` for prior art).
|
|
346
|
+
*/
|
|
347
|
+
|
|
348
|
+
interface LaunchCustomerPortalButtonProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href' | 'target' | 'rel' | 'onError'> {
|
|
349
|
+
/** Override the default "Manage billing" label. */
|
|
350
|
+
children?: React.ReactNode;
|
|
351
|
+
/** Called immediately before the user navigates to `href`. */
|
|
352
|
+
onLaunch?: (href: string) => void;
|
|
353
|
+
/** Called when the portal session fetch fails. */
|
|
354
|
+
onError?: (error: Error) => void;
|
|
355
|
+
/** Optional className applied to the disabled <button> shown while loading. */
|
|
356
|
+
loadingClassName?: string;
|
|
357
|
+
/** Optional className applied to the disabled <button> shown on error. */
|
|
358
|
+
errorClassName?: string;
|
|
359
|
+
/**
|
|
360
|
+
* Render the ready-state anchor via `Slot` so consumers can substitute
|
|
361
|
+
* their own element (typically a real `<button>`) while preserving the
|
|
362
|
+
* `href`, `target`, `rel`, and click chain. The loading/error fallback
|
|
363
|
+
* buttons are untouched — `asChild` only swaps the ready-state shell.
|
|
364
|
+
*/
|
|
365
|
+
asChild?: boolean;
|
|
366
|
+
}
|
|
367
|
+
declare const LaunchCustomerPortalButton: React.ForwardRefExoticComponent<LaunchCustomerPortalButtonProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* `<UpdatePaymentMethodButton>` — trigger that opens the SolvaPay hosted
|
|
371
|
+
* customer portal so the customer can update their card on file.
|
|
372
|
+
*
|
|
373
|
+
* This MCP-first slice ships `mode="portal"` only (thin wrapper around
|
|
374
|
+
* `<LaunchCustomerPortalButton>`). A future Lovable-focused PR will add
|
|
375
|
+
* `mode="inline"` — a drawer containing `<PaymentMethodForm>` (Stripe
|
|
376
|
+
* Elements + SetupIntent). The `mode` prop is defined now so the API
|
|
377
|
+
* stays stable across both PRs.
|
|
378
|
+
*/
|
|
379
|
+
|
|
380
|
+
type UpdatePaymentMethodButtonMode = 'portal';
|
|
381
|
+
interface UpdatePaymentMethodButtonProps extends Omit<LaunchCustomerPortalButtonProps, 'children'> {
|
|
382
|
+
/**
|
|
383
|
+
* How card updates are collected. `"portal"` (default, only value shipped
|
|
384
|
+
* today) opens the SolvaPay hosted customer portal in a new tab. A
|
|
385
|
+
* future PR adds `"inline"` for Stripe Elements; keep the prop stable so
|
|
386
|
+
* callers don't need to migrate when that lands.
|
|
387
|
+
*/
|
|
388
|
+
mode?: UpdatePaymentMethodButtonMode;
|
|
389
|
+
/** Override the default "Update card" label. */
|
|
390
|
+
children?: React.ReactNode;
|
|
391
|
+
}
|
|
392
|
+
declare const UpdatePaymentMethodButton: React.ForwardRefExoticComponent<UpdatePaymentMethodButtonProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
393
|
+
|
|
311
394
|
type PaymentElementKind = 'payment-element' | 'card-element' | null;
|
|
312
395
|
interface PaymentFormContextValue {
|
|
313
396
|
planRef?: string;
|
|
@@ -529,8 +612,8 @@ declare function usePlan(options: UsePlanOptions): UsePlanReturn;
|
|
|
529
612
|
|
|
530
613
|
/**
|
|
531
614
|
* Hook to load a single product by reference. Uses a module-level
|
|
532
|
-
* single-flight cache keyed by `productRef`
|
|
533
|
-
* same in-flight request.
|
|
615
|
+
* single-flight cache keyed by `productRef` (and transport identity) so
|
|
616
|
+
* concurrent consumers share the same in-flight request.
|
|
534
617
|
*/
|
|
535
618
|
declare function useProduct(productRef: string | undefined): UseProductReturn;
|
|
536
619
|
|
|
@@ -538,8 +621,9 @@ declare function useProduct(productRef: string | undefined): UseProductReturn;
|
|
|
538
621
|
* Hook to load merchant identity (legal name, support email, terms/privacy
|
|
539
622
|
* URLs, ...) for rendering mandate copy and trust signals.
|
|
540
623
|
*
|
|
541
|
-
* Uses a module-level single-flight cache keyed by the configured
|
|
542
|
-
*
|
|
624
|
+
* Uses a module-level single-flight cache keyed by the configured transport
|
|
625
|
+
* (or HTTP route when no transport is provided) so concurrent consumers
|
|
626
|
+
* share one in-flight request and response.
|
|
543
627
|
*/
|
|
544
628
|
declare function useMerchant(): UseMerchantReturn;
|
|
545
629
|
|
|
@@ -681,6 +765,52 @@ declare function useBalance(): BalanceStatus;
|
|
|
681
765
|
*/
|
|
682
766
|
declare function useTopupAmountSelector(options: UseTopupAmountSelectorOptions): UseTopupAmountSelectorReturn;
|
|
683
767
|
|
|
768
|
+
/**
|
|
769
|
+
* Hook that loads the customer's default payment method for rendering
|
|
770
|
+
* under `<CurrentPlanCard>`. Mirrors `useMerchant`'s caching semantics:
|
|
771
|
+
* module-level single-flight cache keyed by transport identity (or HTTP
|
|
772
|
+
* route when no custom transport is provided).
|
|
773
|
+
*
|
|
774
|
+
* The hook **does not throw** on transport errors — it sets `error` and
|
|
775
|
+
* keeps `paymentMethod: null` so the consuming component can hide the
|
|
776
|
+
* payment-method line. This lets `<CurrentPlanCard>` degrade gracefully
|
|
777
|
+
* when the backend endpoint isn't deployed yet or the MCP server doesn't
|
|
778
|
+
* expose the `get_payment_method` tool.
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* ```tsx
|
|
782
|
+
* const { paymentMethod, loading } = usePaymentMethod()
|
|
783
|
+
*
|
|
784
|
+
* if (loading) return null
|
|
785
|
+
* if (!paymentMethod || paymentMethod.kind === 'none') return null
|
|
786
|
+
*
|
|
787
|
+
* return <span>{paymentMethod.brand} •••• {paymentMethod.last4}</span>
|
|
788
|
+
* ```
|
|
789
|
+
*/
|
|
790
|
+
declare function usePaymentMethod(): UsePaymentMethodReturn;
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* Returns the effective data-access transport for the current provider.
|
|
794
|
+
*
|
|
795
|
+
* If the consumer passed a custom `transport` on `SolvaPayConfig`, that
|
|
796
|
+
* instance is returned. Otherwise a fresh HTTP transport is built from
|
|
797
|
+
* `config.api` + `config.fetch`. Memoised on the config identity so
|
|
798
|
+
* HTTP-default consumers don't re-create a transport on every render.
|
|
799
|
+
*
|
|
800
|
+
* Use this from components that need a transport method the provider
|
|
801
|
+
* doesn't already expose on its context (e.g. `createCustomerSession`,
|
|
802
|
+
* `getPaymentMethod`, `listPlans`).
|
|
803
|
+
*/
|
|
804
|
+
declare function useTransport(): SolvaPayTransport;
|
|
805
|
+
|
|
806
|
+
interface UsePaywallResolverReturn {
|
|
807
|
+
/** `true` once the paywall requirement is met. */
|
|
808
|
+
resolved: boolean;
|
|
809
|
+
/** Refetch the underlying purchase + balance state. */
|
|
810
|
+
refetch: () => Promise<void>;
|
|
811
|
+
}
|
|
812
|
+
declare function usePaywallResolver(content: PaywallStructuredContent): UsePaywallResolverReturn;
|
|
813
|
+
|
|
684
814
|
type CopyContextValue = {
|
|
685
815
|
locale?: string;
|
|
686
816
|
copy: SolvaPayCopy;
|
|
@@ -768,6 +898,24 @@ declare function getPrimaryPurchase(purchases: PurchaseInfo[]): PurchaseInfo | n
|
|
|
768
898
|
* @returns true if purchase is paid (amount > 0)
|
|
769
899
|
*/
|
|
770
900
|
declare function isPaidPurchase(purchase: PurchaseInfo): boolean;
|
|
901
|
+
/**
|
|
902
|
+
* Classify a purchase as a plan (subscription / one-time / usage-based) vs a
|
|
903
|
+
* balance transaction (credit top-up, and any future non-plan purposes).
|
|
904
|
+
*
|
|
905
|
+
* Primary signal is structural: a purchase with no `planSnapshot` was never a
|
|
906
|
+
* plan. The `metadata.purpose` check is defense in depth — it keeps obvious
|
|
907
|
+
* top-ups out of plan selectors even if a future backend regression
|
|
908
|
+
* accidentally attaches a snapshot to one.
|
|
909
|
+
*
|
|
910
|
+
* @param purchase - Purchase to classify
|
|
911
|
+
* @returns true when the purchase represents a plan
|
|
912
|
+
*/
|
|
913
|
+
declare function isPlanPurchase(purchase: PurchaseInfo): boolean;
|
|
914
|
+
/**
|
|
915
|
+
* Inverse of `isPlanPurchase` — balance transactions (credit top-ups today,
|
|
916
|
+
* gift credits / refunds / bonuses tomorrow).
|
|
917
|
+
*/
|
|
918
|
+
declare function isTopupPurchase(purchase: PurchaseInfo): boolean;
|
|
771
919
|
|
|
772
920
|
/**
|
|
773
921
|
* Currency + interval price formatting utilities.
|
|
@@ -789,6 +937,19 @@ type FormatPriceOptions = {
|
|
|
789
937
|
*/
|
|
790
938
|
free?: string;
|
|
791
939
|
};
|
|
940
|
+
/**
|
|
941
|
+
* Number of minor units per one major unit of `currency`. 1 for zero-decimal
|
|
942
|
+
* currencies (JPY, KRW, …), 100 for everything else. Use this to convert
|
|
943
|
+
* between the units a user types (major, e.g. dollars) and the units Stripe
|
|
944
|
+
* and the SolvaPay API consume (minor, e.g. cents).
|
|
945
|
+
*/
|
|
946
|
+
declare function getMinorUnitsPerMajor(currency: string): number;
|
|
947
|
+
/**
|
|
948
|
+
* Convert a minor-unit amount to its major-unit equivalent. Zero-decimal
|
|
949
|
+
* currencies pass through unchanged (1000 JPY minor = 1000 JPY major);
|
|
950
|
+
* two-decimal currencies divide by 100 (1999 USD minor = 19.99 USD).
|
|
951
|
+
*/
|
|
952
|
+
declare function toMajorUnits(amountMinor: number, currency: string): number;
|
|
792
953
|
declare function formatPrice(amountMinor: number, currency: string, opts?: FormatPriceOptions): string;
|
|
793
954
|
|
|
794
955
|
type ResolveCtaInput = {
|
|
@@ -847,4 +1008,30 @@ type ConfirmPaymentResult = {
|
|
|
847
1008
|
*/
|
|
848
1009
|
declare function confirmPayment(input: ConfirmPaymentInput): Promise<ConfirmPaymentResult>;
|
|
849
1010
|
|
|
850
|
-
|
|
1011
|
+
/**
|
|
1012
|
+
* Default HTTP transport — wraps `config.api` + `config.fetch` so every SDK
|
|
1013
|
+
* hook and component routes through a single place. Extracted from the
|
|
1014
|
+
* inline `buildDefault*` callbacks that used to live inside
|
|
1015
|
+
* `SolvaPayProvider`.
|
|
1016
|
+
*/
|
|
1017
|
+
|
|
1018
|
+
declare const DEFAULT_ROUTES: {
|
|
1019
|
+
readonly checkPurchase: "/api/check-purchase";
|
|
1020
|
+
readonly createPayment: "/api/create-payment-intent";
|
|
1021
|
+
readonly processPayment: "/api/process-payment";
|
|
1022
|
+
readonly createTopupPayment: "/api/create-topup-payment-intent";
|
|
1023
|
+
readonly customerBalance: "/api/customer-balance";
|
|
1024
|
+
readonly cancelRenewal: "/api/cancel-renewal";
|
|
1025
|
+
readonly reactivateRenewal: "/api/reactivate-renewal";
|
|
1026
|
+
readonly activatePlan: "/api/activate-plan";
|
|
1027
|
+
readonly createCheckoutSession: "/api/create-checkout-session";
|
|
1028
|
+
readonly createCustomerSession: "/api/create-customer-session";
|
|
1029
|
+
readonly getMerchant: "/api/merchant";
|
|
1030
|
+
readonly getProduct: "/api/get-product";
|
|
1031
|
+
readonly listPlans: "/api/list-plans";
|
|
1032
|
+
readonly getPaymentMethod: "/api/payment-method";
|
|
1033
|
+
readonly getUsage: "/api/usage";
|
|
1034
|
+
};
|
|
1035
|
+
declare function createHttpTransport(config: SolvaPayConfig | undefined): SolvaPayTransport;
|
|
1036
|
+
|
|
1037
|
+
export { ActivatePlanResult, ActivationFlow, type ActivationFlowProps, ActivationResult, type ActivationState, AmountPicker, type AmountPickerProps, BalanceStatus, CancelResult, CancelledPlanNotice, type CancelledPlanNoticeProps, CheckoutLayout, type CheckoutLayoutPlanSelectorOptions, type CheckoutLayoutProps, type CheckoutLayoutSize, CheckoutResult, CheckoutVariant, type ConfirmPaymentInput, type ConfirmPaymentMode, type ConfirmPaymentResult, CopyContext, CopyProvider, CreditGate, type CreditGateProps, CurrentPlanCard, type CurrentPlanCardClassNames, type CurrentPlanCardProps, type CustomerInfo, DEFAULT_ROUTES, type FormatPriceOptions, LaunchCustomerPortalButton, type LaunchCustomerPortalButtonProps, PartialSolvaPayCopy, type PaymentElementKind, PaymentForm, PaymentFormContext, type PaymentFormContextValue, PaymentFormProps, PaymentFormProvider, Plan, PlanSelector, type PlanSelectorProps, PrefillCustomer, Product, type PurchaseActions, PurchaseInfo, PurchaseStatus, PurchaseStatusReturn, ReactivateResult, SolvaPayConfig, SolvaPayContextValue, SolvaPayCopy, SolvaPayProvider, SolvaPayProviderProps, SolvaPayTransport, Spinner, StripePaymentFormWrapper, TopupForm, TopupFormProps, UpdatePaymentMethodButton, type UpdatePaymentMethodButtonMode, type UpdatePaymentMethodButtonProps, type UseActivationReturn, UseMerchantReturn, UsePaymentMethodReturn, type UsePaywallResolverReturn, UsePlanOptions, UsePlanReturn, UsePlansOptions, UsePlansReturn, UseProductReturn, UseTopupAmountSelectorOptions, UseTopupAmountSelectorReturn, UseTopupOptions, UseTopupReturn, confirmPayment, createHttpTransport, enCopy, filterPurchases, formatPrice, getActivePurchases, getCancelledPurchasesWithEndDate, getMinorUnitsPerMajor, getMostRecentPurchase, getPrimaryPurchase, interpolate, isPaidPurchase, isPlanPurchase, isTopupPurchase, mergeCopy, resolveCta, toMajorUnits, useActivation, useBalance, useCheckout, useCopy, useCustomer, useLocale, useMerchant, usePaymentForm, usePaymentMethod, usePaywallResolver, usePlan, usePlans, useProduct, usePurchase, usePurchaseActions, usePurchaseStatus, useSolvaPay, useTopup, useTopupAmountSelector, useTransport };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CurrentPlanCard,
|
|
3
|
+
LaunchCustomerPortalButton,
|
|
4
|
+
UpdatePaymentMethodButton,
|
|
5
|
+
usePaymentMethod
|
|
6
|
+
} from "./chunk-HWVJL5X6.js";
|
|
1
7
|
import {
|
|
2
8
|
ActivationFlow,
|
|
9
|
+
CreditGate,
|
|
10
|
+
PlanBadge,
|
|
11
|
+
ProductBadge,
|
|
12
|
+
PurchaseGate,
|
|
13
|
+
TopupForm,
|
|
14
|
+
useActivationFlow,
|
|
15
|
+
useCreditGate
|
|
16
|
+
} from "./chunk-R2ZPZ7VM.js";
|
|
17
|
+
import {
|
|
3
18
|
AmountPicker,
|
|
4
19
|
BalanceBadge,
|
|
5
20
|
CancelPlanButton,
|
|
@@ -7,7 +22,7 @@ import {
|
|
|
7
22
|
CheckoutSummary2 as CheckoutSummary,
|
|
8
23
|
CopyContext,
|
|
9
24
|
CopyProvider,
|
|
10
|
-
|
|
25
|
+
DEFAULT_ROUTES,
|
|
11
26
|
MandateText,
|
|
12
27
|
PaymentForm,
|
|
13
28
|
PaymentFormCardElement,
|
|
@@ -21,40 +36,40 @@ import {
|
|
|
21
36
|
PaymentFormSubmitButton,
|
|
22
37
|
PaymentFormSummary,
|
|
23
38
|
PaymentFormTermsCheckbox,
|
|
24
|
-
PlanBadge,
|
|
25
39
|
PlanSelector,
|
|
26
|
-
ProductBadge,
|
|
27
|
-
PurchaseGate,
|
|
28
40
|
SolvaPayContext,
|
|
29
41
|
SolvaPayProvider,
|
|
30
42
|
Spinner,
|
|
31
|
-
TopupForm2 as TopupForm,
|
|
32
|
-
buildRequestHeaders,
|
|
33
43
|
confirmPayment,
|
|
44
|
+
createHttpTransport,
|
|
45
|
+
defaultListPlans,
|
|
34
46
|
deriveVariant,
|
|
35
47
|
enCopy,
|
|
36
48
|
filterPurchases,
|
|
37
49
|
formatPrice,
|
|
38
50
|
getActivePurchases,
|
|
39
51
|
getCancelledPurchasesWithEndDate,
|
|
52
|
+
getMinorUnitsPerMajor,
|
|
40
53
|
getMostRecentPurchase,
|
|
41
54
|
getPrimaryPurchase,
|
|
42
55
|
interpolate,
|
|
43
56
|
isPaidPurchase,
|
|
57
|
+
isPlanPurchase,
|
|
58
|
+
isTopupPurchase,
|
|
44
59
|
mergeCopy,
|
|
45
60
|
resolveCta,
|
|
61
|
+
toMajorUnits,
|
|
46
62
|
useActivation,
|
|
47
|
-
useActivationFlow,
|
|
48
63
|
useAmountPicker,
|
|
49
64
|
useAmountPickerCopy,
|
|
50
65
|
useBalance,
|
|
51
66
|
useCheckout,
|
|
52
67
|
useCopy,
|
|
53
|
-
useCreditGate,
|
|
54
68
|
useCustomer,
|
|
55
69
|
useLocale,
|
|
56
70
|
useMerchant,
|
|
57
71
|
usePaymentForm,
|
|
72
|
+
usePaywallResolver,
|
|
58
73
|
usePlan,
|
|
59
74
|
usePlans,
|
|
60
75
|
useProduct,
|
|
@@ -63,11 +78,14 @@ import {
|
|
|
63
78
|
usePurchaseStatus,
|
|
64
79
|
useSolvaPay,
|
|
65
80
|
useTopup,
|
|
66
|
-
useTopupAmountSelector
|
|
67
|
-
|
|
81
|
+
useTopupAmountSelector,
|
|
82
|
+
useTransport,
|
|
83
|
+
useUsage
|
|
84
|
+
} from "./chunk-37R5NZGF.js";
|
|
68
85
|
import {
|
|
69
86
|
defaultAuthAdapter
|
|
70
87
|
} from "./chunk-OUSEQRCT.js";
|
|
88
|
+
import "./chunk-MLKGABMK.js";
|
|
71
89
|
|
|
72
90
|
// src/PaymentForm.tsx
|
|
73
91
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -348,7 +366,7 @@ var TopupPaymentStep = () => {
|
|
|
348
366
|
/* @__PURE__ */ jsx4(
|
|
349
367
|
TopupForm,
|
|
350
368
|
{
|
|
351
|
-
amount: ctx.
|
|
369
|
+
amount: ctx.amountMinor,
|
|
352
370
|
currency: ctx.currency,
|
|
353
371
|
onSuccess: ctx.onTopupSuccess,
|
|
354
372
|
onError: (err) => ctx.onError?.(err instanceof Error ? err : new Error(String(err)))
|
|
@@ -529,20 +547,6 @@ var CheckoutLayout = ({
|
|
|
529
547
|
}
|
|
530
548
|
);
|
|
531
549
|
};
|
|
532
|
-
async function defaultListPlans(productRef, config) {
|
|
533
|
-
const base = config?.api?.listPlans || "/api/list-plans";
|
|
534
|
-
const url = `${base}?productRef=${encodeURIComponent(productRef)}`;
|
|
535
|
-
const fetchFn = config?.fetch || fetch;
|
|
536
|
-
const { headers } = await buildRequestHeaders(config);
|
|
537
|
-
const res = await fetchFn(url, { method: "GET", headers });
|
|
538
|
-
if (!res.ok) {
|
|
539
|
-
const error = new Error(`Failed to fetch plans: ${res.statusText || res.status}`);
|
|
540
|
-
config?.onError?.(error, "listPlans");
|
|
541
|
-
throw error;
|
|
542
|
-
}
|
|
543
|
-
const data = await res.json();
|
|
544
|
-
return data.plans ?? [];
|
|
545
|
-
}
|
|
546
550
|
var SelectStep = ({ productRef, initialPlanRef, filter, sortBy, popularPlanRef, onContinue }) => {
|
|
547
551
|
const copy = useCopy();
|
|
548
552
|
const solva = useContext(SolvaPayContext);
|
|
@@ -725,6 +729,16 @@ var CreditGate2 = ({
|
|
|
725
729
|
}
|
|
726
730
|
);
|
|
727
731
|
};
|
|
732
|
+
|
|
733
|
+
// src/transport/types.ts
|
|
734
|
+
var UnsupportedTransportMethodError = class extends Error {
|
|
735
|
+
method;
|
|
736
|
+
constructor(method) {
|
|
737
|
+
super(`SolvaPay transport does not implement "${method}"`);
|
|
738
|
+
this.name = "UnsupportedTransportMethodError";
|
|
739
|
+
this.method = method;
|
|
740
|
+
}
|
|
741
|
+
};
|
|
728
742
|
export {
|
|
729
743
|
ActivationFlow2 as ActivationFlow,
|
|
730
744
|
AmountPicker2 as AmountPicker,
|
|
@@ -736,6 +750,9 @@ export {
|
|
|
736
750
|
CopyContext,
|
|
737
751
|
CopyProvider,
|
|
738
752
|
CreditGate2 as CreditGate,
|
|
753
|
+
CurrentPlanCard,
|
|
754
|
+
DEFAULT_ROUTES,
|
|
755
|
+
LaunchCustomerPortalButton,
|
|
739
756
|
MandateText,
|
|
740
757
|
PaymentForm2 as PaymentForm,
|
|
741
758
|
PaymentFormContext,
|
|
@@ -748,7 +765,10 @@ export {
|
|
|
748
765
|
Spinner,
|
|
749
766
|
StripePaymentFormWrapper,
|
|
750
767
|
TopupForm,
|
|
768
|
+
UnsupportedTransportMethodError,
|
|
769
|
+
UpdatePaymentMethodButton,
|
|
751
770
|
confirmPayment,
|
|
771
|
+
createHttpTransport,
|
|
752
772
|
defaultAuthAdapter,
|
|
753
773
|
deriveVariant,
|
|
754
774
|
enCopy,
|
|
@@ -756,12 +776,16 @@ export {
|
|
|
756
776
|
formatPrice,
|
|
757
777
|
getActivePurchases,
|
|
758
778
|
getCancelledPurchasesWithEndDate,
|
|
779
|
+
getMinorUnitsPerMajor,
|
|
759
780
|
getMostRecentPurchase,
|
|
760
781
|
getPrimaryPurchase,
|
|
761
782
|
interpolate,
|
|
762
783
|
isPaidPurchase,
|
|
784
|
+
isPlanPurchase,
|
|
785
|
+
isTopupPurchase,
|
|
763
786
|
mergeCopy,
|
|
764
787
|
resolveCta,
|
|
788
|
+
toMajorUnits,
|
|
765
789
|
useActivation,
|
|
766
790
|
useBalance,
|
|
767
791
|
useCheckout,
|
|
@@ -770,6 +794,8 @@ export {
|
|
|
770
794
|
useLocale,
|
|
771
795
|
useMerchant,
|
|
772
796
|
usePaymentForm,
|
|
797
|
+
usePaymentMethod,
|
|
798
|
+
usePaywallResolver,
|
|
773
799
|
usePlan,
|
|
774
800
|
usePlans,
|
|
775
801
|
useProduct,
|
|
@@ -778,5 +804,7 @@ export {
|
|
|
778
804
|
usePurchaseStatus,
|
|
779
805
|
useSolvaPay,
|
|
780
806
|
useTopup,
|
|
781
|
-
useTopupAmountSelector
|
|
807
|
+
useTopupAmountSelector,
|
|
808
|
+
useTransport,
|
|
809
|
+
useUsage
|
|
782
810
|
};
|