@solvapay/react 1.0.8-preview.5 → 1.0.8-preview.7
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 +12 -95
- package/dist/CancelPlanButton-Bb7cvym9.d.cts +1105 -0
- package/dist/CancelPlanButton-CieT9swn.d.cts +1102 -0
- package/dist/CancelPlanButton-Cq117t7h.d.ts +1105 -0
- package/dist/CancelPlanButton-f56UlQN-.d.ts +1102 -0
- package/dist/PaymentForm-B5dw0i1X.d.ts +934 -0
- package/dist/PaymentForm-CesoRQWu.d.cts +934 -0
- package/dist/chunk-5FZBOPIW.js +4763 -0
- package/dist/chunk-C7SKOENW.js +1889 -0
- package/dist/chunk-ISYAH4ZL.js +1889 -0
- package/dist/chunk-MOP3ZBGC.js +4749 -0
- package/dist/chunk-TP4JPKE2.js +3126 -0
- package/dist/chunk-VTGIXJQU.js +4755 -0
- package/dist/chunk-XMQ4GBWQ.js +4752 -0
- package/dist/index-DLl3UwO3.d.ts +798 -0
- package/dist/index-Sj2lHLl8.d.cts +798 -0
- package/dist/index.cjs +11 -10
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/primitives/index.cjs +4 -6
- package/dist/primitives/index.d.cts +2 -2
- package/dist/primitives/index.d.ts +2 -2
- package/dist/primitives/index.js +1 -1
- package/dist/src/PaymentForm.d.ts +56 -0
- package/dist/src/PaymentForm.d.ts.map +1 -0
- package/dist/src/PaymentForm.js +212 -0
- package/dist/src/PaymentForm.js.map +1 -0
- package/dist/src/SolvaPayProvider.d.ts +84 -0
- package/dist/src/SolvaPayProvider.d.ts.map +1 -0
- package/dist/src/SolvaPayProvider.js +537 -0
- package/dist/src/SolvaPayProvider.js.map +1 -0
- package/dist/src/adapters/auth.d.ts +43 -0
- package/dist/src/adapters/auth.d.ts.map +1 -0
- package/dist/src/adapters/auth.js +38 -0
- package/dist/src/adapters/auth.js.map +1 -0
- package/dist/src/components/PlanBadge.d.ts +31 -0
- package/dist/src/components/PlanBadge.d.ts.map +1 -0
- package/dist/src/components/PlanBadge.js +119 -0
- package/dist/src/components/PlanBadge.js.map +1 -0
- package/dist/src/components/PlanSelector.d.ts +49 -0
- package/dist/src/components/PlanSelector.d.ts.map +1 -0
- package/dist/src/components/PlanSelector.js +82 -0
- package/dist/src/components/PlanSelector.js.map +1 -0
- package/dist/src/components/Spinner.d.ts +10 -0
- package/dist/src/components/Spinner.d.ts.map +1 -0
- package/dist/src/components/Spinner.js +14 -0
- package/dist/src/components/Spinner.js.map +1 -0
- package/dist/src/components/StripePaymentFormWrapper.d.ts +17 -0
- package/dist/src/components/StripePaymentFormWrapper.d.ts.map +1 -0
- package/dist/src/components/StripePaymentFormWrapper.js +158 -0
- package/dist/src/components/StripePaymentFormWrapper.js.map +1 -0
- package/dist/src/components/SubscriptionGate.d.ts +21 -0
- package/dist/src/components/SubscriptionGate.d.ts.map +1 -0
- package/dist/src/components/SubscriptionGate.js +32 -0
- package/dist/src/components/SubscriptionGate.js.map +1 -0
- package/dist/src/hooks/__tests__/useSubscription.test.d.ts +2 -0
- package/dist/src/hooks/__tests__/useSubscription.test.d.ts.map +1 -0
- package/dist/src/hooks/__tests__/useSubscription.test.js +554 -0
- package/dist/src/hooks/__tests__/useSubscription.test.js.map +1 -0
- package/dist/src/hooks/__tests__/useSubscriptionStatus.test.d.ts +2 -0
- package/dist/src/hooks/__tests__/useSubscriptionStatus.test.d.ts.map +1 -0
- package/dist/src/hooks/__tests__/useSubscriptionStatus.test.js +719 -0
- package/dist/src/hooks/__tests__/useSubscriptionStatus.test.js.map +1 -0
- package/dist/src/hooks/useCheckout.d.ts +59 -0
- package/dist/src/hooks/useCheckout.d.ts.map +1 -0
- package/dist/src/hooks/useCheckout.js +138 -0
- package/dist/src/hooks/useCheckout.js.map +1 -0
- package/dist/src/hooks/useCustomer.d.ts +43 -0
- package/dist/src/hooks/useCustomer.d.ts.map +1 -0
- package/dist/src/hooks/useCustomer.js +31 -0
- package/dist/src/hooks/useCustomer.js.map +1 -0
- package/dist/src/hooks/usePlans.d.ts +28 -0
- package/dist/src/hooks/usePlans.d.ts.map +1 -0
- package/dist/src/hooks/usePlans.js +181 -0
- package/dist/src/hooks/usePlans.js.map +1 -0
- package/dist/src/hooks/useSolvaPay.d.ts +44 -0
- package/dist/src/hooks/useSolvaPay.d.ts.map +1 -0
- package/dist/src/hooks/useSolvaPay.js +52 -0
- package/dist/src/hooks/useSolvaPay.js.map +1 -0
- package/dist/src/hooks/useSubscription.d.ts +46 -0
- package/dist/src/hooks/useSubscription.d.ts.map +1 -0
- package/dist/src/hooks/useSubscription.js +50 -0
- package/dist/src/hooks/useSubscription.js.map +1 -0
- package/dist/src/hooks/useSubscriptionStatus.d.ts +19 -0
- package/dist/src/hooks/useSubscriptionStatus.d.ts.map +1 -0
- package/dist/src/hooks/useSubscriptionStatus.js +68 -0
- package/dist/src/hooks/useSubscriptionStatus.js.map +1 -0
- package/dist/src/index.d.ts +24 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +26 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/types/index.d.ts +339 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +5 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/utils/__tests__/subscriptions.test.d.ts +2 -0
- package/dist/src/utils/__tests__/subscriptions.test.d.ts.map +1 -0
- package/dist/src/utils/__tests__/subscriptions.test.js +121 -0
- package/dist/src/utils/__tests__/subscriptions.test.js.map +1 -0
- package/dist/src/utils/subscriptions.d.ts +57 -0
- package/dist/src/utils/subscriptions.d.ts.map +1 -0
- package/dist/src/utils/subscriptions.js +85 -0
- package/dist/src/utils/subscriptions.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { SolvaPayContext } from '../SolvaPayProvider';
|
|
3
|
+
/**
|
|
4
|
+
* Hook to access SolvaPay context and provider methods.
|
|
5
|
+
*
|
|
6
|
+
* This is the base hook that provides access to all SolvaPay functionality
|
|
7
|
+
* including subscription data, payment methods, and customer information.
|
|
8
|
+
* Other hooks like `useSubscription` and `useCheckout` use this internally.
|
|
9
|
+
*
|
|
10
|
+
* Must be used within a `SolvaPayProvider` component.
|
|
11
|
+
*
|
|
12
|
+
* @returns SolvaPay context value with all provider methods and state
|
|
13
|
+
* @returns subscription - Subscription status and data
|
|
14
|
+
* @returns createPayment - Function to create payment intents
|
|
15
|
+
* @returns processPayment - Function to process payments
|
|
16
|
+
* @returns customerRef - Current customer reference
|
|
17
|
+
* @returns refetchSubscription - Function to refetch subscription data
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* import { useSolvaPay } from '@solvapay/react';
|
|
22
|
+
*
|
|
23
|
+
* function CustomComponent() {
|
|
24
|
+
* const { subscription, createPayment, processPayment } = useSolvaPay();
|
|
25
|
+
*
|
|
26
|
+
* const handlePayment = async () => {
|
|
27
|
+
* const intent = await createPayment({
|
|
28
|
+
* planRef: 'pln_premium',
|
|
29
|
+
* agentRef: 'agt_myapi'
|
|
30
|
+
* });
|
|
31
|
+
* // Process payment...
|
|
32
|
+
* };
|
|
33
|
+
*
|
|
34
|
+
* return <div>Subscription status: {subscription.hasPaidSubscription ? 'Active' : 'None'}</div>;
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @throws {Error} If used outside of SolvaPayProvider
|
|
39
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
40
|
+
* @see {@link useSubscription} for subscription-specific hook
|
|
41
|
+
* @see {@link useCheckout} for checkout-specific hook
|
|
42
|
+
* @since 1.0.0
|
|
43
|
+
*/
|
|
44
|
+
export function useSolvaPay() {
|
|
45
|
+
const context = useContext(SolvaPayContext);
|
|
46
|
+
if (!context) {
|
|
47
|
+
throw new Error('useSolvaPay must be used within a SolvaPayProvider. ' +
|
|
48
|
+
'Wrap your component tree with <SolvaPayProvider> to use this hook.');
|
|
49
|
+
}
|
|
50
|
+
return context;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=useSolvaPay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSolvaPay.js","sourceRoot":"","sources":["../../../src/hooks/useSolvaPay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC,CAAA;IAE3C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,sDAAsD;YACpD,oEAAoE,CACvE,CAAA;IACH,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { SubscriptionStatus } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to get current subscription status and information.
|
|
4
|
+
*
|
|
5
|
+
* Returns the current user's subscription status, including active
|
|
6
|
+
* subscriptions, plan details, and payment information. Automatically
|
|
7
|
+
* syncs with the SolvaPay backend and handles loading and error states.
|
|
8
|
+
*
|
|
9
|
+
* @returns Subscription data and status
|
|
10
|
+
* @returns subscriptions - Array of active subscriptions
|
|
11
|
+
* @returns hasPaidSubscription - Whether user has any paid subscription
|
|
12
|
+
* @returns isLoading - Loading state
|
|
13
|
+
* @returns error - Error state if subscription check fails
|
|
14
|
+
* @returns refetch - Function to manually refetch subscription data
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import { useSubscription } from '@solvapay/react';
|
|
19
|
+
*
|
|
20
|
+
* function Dashboard() {
|
|
21
|
+
* const { subscriptions, hasPaidSubscription, isLoading, refetch } = useSubscription();
|
|
22
|
+
*
|
|
23
|
+
* if (isLoading) return <Spinner />;
|
|
24
|
+
*
|
|
25
|
+
* if (!hasPaidSubscription) {
|
|
26
|
+
* return <UpgradePrompt />;
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* return (
|
|
30
|
+
* <div>
|
|
31
|
+
* <h2>Welcome, Premium User!</h2>
|
|
32
|
+
* <p>Active subscriptions: {subscriptions.length}</p>
|
|
33
|
+
* <button onClick={() => refetch()}>Refresh</button>
|
|
34
|
+
* </div>
|
|
35
|
+
* );
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
40
|
+
* @see {@link useSubscriptionStatus} for detailed status information
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
*/
|
|
43
|
+
export declare function useSubscription(): SubscriptionStatus & {
|
|
44
|
+
refetch: () => Promise<void>;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=useSubscription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSubscription.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSubscription.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,eAAe,IAAI,kBAAkB,GAAG;IAAE,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAOvF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useSolvaPay } from './useSolvaPay';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to get current subscription status and information.
|
|
4
|
+
*
|
|
5
|
+
* Returns the current user's subscription status, including active
|
|
6
|
+
* subscriptions, plan details, and payment information. Automatically
|
|
7
|
+
* syncs with the SolvaPay backend and handles loading and error states.
|
|
8
|
+
*
|
|
9
|
+
* @returns Subscription data and status
|
|
10
|
+
* @returns subscriptions - Array of active subscriptions
|
|
11
|
+
* @returns hasPaidSubscription - Whether user has any paid subscription
|
|
12
|
+
* @returns isLoading - Loading state
|
|
13
|
+
* @returns error - Error state if subscription check fails
|
|
14
|
+
* @returns refetch - Function to manually refetch subscription data
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import { useSubscription } from '@solvapay/react';
|
|
19
|
+
*
|
|
20
|
+
* function Dashboard() {
|
|
21
|
+
* const { subscriptions, hasPaidSubscription, isLoading, refetch } = useSubscription();
|
|
22
|
+
*
|
|
23
|
+
* if (isLoading) return <Spinner />;
|
|
24
|
+
*
|
|
25
|
+
* if (!hasPaidSubscription) {
|
|
26
|
+
* return <UpgradePrompt />;
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* return (
|
|
30
|
+
* <div>
|
|
31
|
+
* <h2>Welcome, Premium User!</h2>
|
|
32
|
+
* <p>Active subscriptions: {subscriptions.length}</p>
|
|
33
|
+
* <button onClick={() => refetch()}>Refresh</button>
|
|
34
|
+
* </div>
|
|
35
|
+
* );
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
40
|
+
* @see {@link useSubscriptionStatus} for detailed status information
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
*/
|
|
43
|
+
export function useSubscription() {
|
|
44
|
+
const { subscription, refetchSubscription } = useSolvaPay();
|
|
45
|
+
return {
|
|
46
|
+
...subscription,
|
|
47
|
+
refetch: refetchSubscription,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=useSubscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSubscription.js","sourceRoot":"","sources":["../../../src/hooks/useSubscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,EAAE,YAAY,EAAE,mBAAmB,EAAE,GAAG,WAAW,EAAE,CAAA;IAE3D,OAAO;QACL,GAAG,YAAY;QACf,OAAO,EAAE,mBAAmB;KAC7B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SubscriptionStatusReturn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook providing advanced status and helper functions for subscription management
|
|
4
|
+
*
|
|
5
|
+
* Focuses on cancelled subscription logic and date formatting utilities.
|
|
6
|
+
* For basic subscription data and paid status checks, use useSubscription() instead.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const { cancelledSubscription, shouldShowCancelledNotice, formatDate, getDaysUntilExpiration } = useSubscriptionStatus();
|
|
11
|
+
*
|
|
12
|
+
* if (shouldShowCancelledNotice && cancelledSubscription) {
|
|
13
|
+
* const formattedDate = formatDate(cancelledSubscription.endDate);
|
|
14
|
+
* const daysLeft = getDaysUntilExpiration(cancelledSubscription.endDate);
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function useSubscriptionStatus(): SubscriptionStatusReturn;
|
|
19
|
+
//# sourceMappingURL=useSubscriptionStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSubscriptionStatus.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSubscriptionStatus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,wBAAwB,EAAE,MAAM,UAAU,CAAA;AAG1E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,IAAI,wBAAwB,CAyDhE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useMemo, useCallback } from 'react';
|
|
2
|
+
import { useSubscription } from './useSubscription';
|
|
3
|
+
/**
|
|
4
|
+
* Hook providing advanced status and helper functions for subscription management
|
|
5
|
+
*
|
|
6
|
+
* Focuses on cancelled subscription logic and date formatting utilities.
|
|
7
|
+
* For basic subscription data and paid status checks, use useSubscription() instead.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const { cancelledSubscription, shouldShowCancelledNotice, formatDate, getDaysUntilExpiration } = useSubscriptionStatus();
|
|
12
|
+
*
|
|
13
|
+
* if (shouldShowCancelledNotice && cancelledSubscription) {
|
|
14
|
+
* const formattedDate = formatDate(cancelledSubscription.endDate);
|
|
15
|
+
* const daysLeft = getDaysUntilExpiration(cancelledSubscription.endDate);
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function useSubscriptionStatus() {
|
|
20
|
+
const { subscriptions } = useSubscription();
|
|
21
|
+
// Helper to check if a subscription is paid
|
|
22
|
+
// Only uses amount field: amount > 0 = paid, amount === 0 or undefined = free
|
|
23
|
+
const isPaidSubscription = useCallback((sub) => {
|
|
24
|
+
return (sub.amount ?? 0) > 0;
|
|
25
|
+
}, []);
|
|
26
|
+
// Memoize subscription calculations for cancelled subscriptions
|
|
27
|
+
// Backend keeps cancelled subscriptions as 'active' until expiration, tracked via cancelledAt
|
|
28
|
+
const subscriptionData = useMemo(() => {
|
|
29
|
+
const cancelledPaidSubscriptions = subscriptions.filter(sub => {
|
|
30
|
+
const subAny = sub; // Type assertion to access optional properties
|
|
31
|
+
// Look for subscriptions with cancelledAt set and status === 'active'
|
|
32
|
+
return sub.status === 'active' && subAny.cancelledAt && isPaidSubscription(sub);
|
|
33
|
+
});
|
|
34
|
+
const cancelledSubscription = cancelledPaidSubscriptions.sort((a, b) => new Date(b.startDate).getTime() - new Date(a.startDate).getTime())[0] || null;
|
|
35
|
+
const shouldShowCancelledNotice = !!cancelledSubscription;
|
|
36
|
+
return {
|
|
37
|
+
cancelledSubscription,
|
|
38
|
+
shouldShowCancelledNotice,
|
|
39
|
+
};
|
|
40
|
+
}, [subscriptions, isPaidSubscription]);
|
|
41
|
+
// Format date helper
|
|
42
|
+
const formatDate = useCallback((dateString) => {
|
|
43
|
+
if (!dateString)
|
|
44
|
+
return null;
|
|
45
|
+
return new Date(dateString).toLocaleDateString('en-US', {
|
|
46
|
+
year: 'numeric',
|
|
47
|
+
month: 'long',
|
|
48
|
+
day: 'numeric',
|
|
49
|
+
});
|
|
50
|
+
}, []);
|
|
51
|
+
// Calculate days until expiration
|
|
52
|
+
const getDaysUntilExpiration = useCallback((endDate) => {
|
|
53
|
+
if (!endDate)
|
|
54
|
+
return null;
|
|
55
|
+
const now = new Date();
|
|
56
|
+
const expiration = new Date(endDate);
|
|
57
|
+
const diffTime = expiration.getTime() - now.getTime();
|
|
58
|
+
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
|
59
|
+
return diffDays > 0 ? diffDays : 0;
|
|
60
|
+
}, []);
|
|
61
|
+
return {
|
|
62
|
+
cancelledSubscription: subscriptionData.cancelledSubscription,
|
|
63
|
+
shouldShowCancelledNotice: subscriptionData.shouldShowCancelledNotice,
|
|
64
|
+
formatDate,
|
|
65
|
+
getDaysUntilExpiration,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=useSubscriptionStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSubscriptionStatus.js","sourceRoot":"","sources":["../../../src/hooks/useSubscriptionStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,qBAAqB;IACnC,MAAM,EAAE,aAAa,EAAE,GAAG,eAAe,EAAE,CAAA;IAE3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b,GAAG,EAAE,SAAS;SACf,CAAC,CAAA;IACJ,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,kCAAkC;IAClC,MAAM,sBAAsB,GAAG,WAAW,CAAC,CAAC,OAAgB,EAAiB,EAAE;QAC7E,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAA;QACzB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;QACtB,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAA;QACpC,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC,OAAO,EAAE,CAAA;QACrD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;QAC5D,OAAO,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;IACpC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACL,qBAAqB,EAAE,gBAAgB,CAAC,qBAAqB;QAC7D,yBAAyB,EAAE,gBAAgB,CAAC,yBAAyB;QACrE,UAAU;QACV,sBAAsB;KACvB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @solvapay/react - Payment components for SolvaPay
|
|
3
|
+
*
|
|
4
|
+
* Provides headless React components and hooks for handling payment flows.
|
|
5
|
+
*/
|
|
6
|
+
export { SolvaPayProvider } from './SolvaPayProvider';
|
|
7
|
+
export { PaymentForm } from './PaymentForm';
|
|
8
|
+
export { PlanBadge } from './components/PlanBadge';
|
|
9
|
+
export { SubscriptionGate } from './components/SubscriptionGate';
|
|
10
|
+
export { PlanSelector } from './components/PlanSelector';
|
|
11
|
+
export { Spinner } from './components/Spinner';
|
|
12
|
+
export { StripePaymentFormWrapper } from './components/StripePaymentFormWrapper';
|
|
13
|
+
export { useSubscription } from './hooks/useSubscription';
|
|
14
|
+
export { useCustomer } from './hooks/useCustomer';
|
|
15
|
+
export { useCheckout } from './hooks/useCheckout';
|
|
16
|
+
export { useSolvaPay } from './hooks/useSolvaPay';
|
|
17
|
+
export { usePlans } from './hooks/usePlans';
|
|
18
|
+
export { useSubscriptionStatus } from './hooks/useSubscriptionStatus';
|
|
19
|
+
export type { SolvaPayConfig, SolvaPayProviderProps, SolvaPayContextValue, SubscriptionStatus, SubscriptionInfo, CustomerSubscriptionData, PaymentIntentResult, PlanBadgeProps, SubscriptionGateProps, PlanSelectorProps, PaymentFormProps, PaymentError, Plan, UsePlansOptions, UsePlansReturn, SubscriptionStatusReturn, } from './types';
|
|
20
|
+
export type { CustomerInfo } from './hooks/useCustomer';
|
|
21
|
+
export type { AuthAdapter } from './adapters/auth';
|
|
22
|
+
export { defaultAuthAdapter } from './adapters/auth';
|
|
23
|
+
export { filterSubscriptions, getActiveSubscriptions, getCancelledSubscriptionsWithEndDate, getMostRecentSubscription, getPrimarySubscription, isPaidSubscription, } from './utils/subscriptions';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAGrD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAA;AAGhF,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAGrE,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,EACnB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,IAAI,EACJ,eAAe,EACf,cAAc,EACd,wBAAwB,GACzB,MAAM,SAAS,CAAA;AAChB,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAGvD,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAGpD,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,oCAAoC,EACpC,yBAAyB,EACzB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @solvapay/react - Payment components for SolvaPay
|
|
3
|
+
*
|
|
4
|
+
* Provides headless React components and hooks for handling payment flows.
|
|
5
|
+
*/
|
|
6
|
+
// Core Provider
|
|
7
|
+
export { SolvaPayProvider } from './SolvaPayProvider';
|
|
8
|
+
// Payment Form
|
|
9
|
+
export { PaymentForm } from './PaymentForm';
|
|
10
|
+
// Headless Components
|
|
11
|
+
export { PlanBadge } from './components/PlanBadge';
|
|
12
|
+
export { SubscriptionGate } from './components/SubscriptionGate';
|
|
13
|
+
export { PlanSelector } from './components/PlanSelector';
|
|
14
|
+
export { Spinner } from './components/Spinner';
|
|
15
|
+
export { StripePaymentFormWrapper } from './components/StripePaymentFormWrapper';
|
|
16
|
+
// Hooks
|
|
17
|
+
export { useSubscription } from './hooks/useSubscription';
|
|
18
|
+
export { useCustomer } from './hooks/useCustomer';
|
|
19
|
+
export { useCheckout } from './hooks/useCheckout';
|
|
20
|
+
export { useSolvaPay } from './hooks/useSolvaPay';
|
|
21
|
+
export { usePlans } from './hooks/usePlans';
|
|
22
|
+
export { useSubscriptionStatus } from './hooks/useSubscriptionStatus';
|
|
23
|
+
export { defaultAuthAdapter } from './adapters/auth';
|
|
24
|
+
// Utilities
|
|
25
|
+
export { filterSubscriptions, getActiveSubscriptions, getCancelledSubscriptionsWithEndDate, getMostRecentSubscription, getPrimarySubscription, isPaidSubscription, } from './utils/subscriptions';
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gBAAgB;AAChB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,sBAAsB;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAA;AAEhF,QAAQ;AACR,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAyBrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,YAAY;AACZ,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,oCAAoC,EACpC,yBAAyB,EACzB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type definitions for @solvapay/react
|
|
3
|
+
*/
|
|
4
|
+
import type { PaymentIntent } from '@stripe/stripe-js';
|
|
5
|
+
import type { ProcessPaymentResult } from '@solvapay/server';
|
|
6
|
+
import type { AuthAdapter } from '../adapters/auth';
|
|
7
|
+
export interface SubscriptionInfo {
|
|
8
|
+
reference: string;
|
|
9
|
+
planName: string;
|
|
10
|
+
agentName: string;
|
|
11
|
+
status: string;
|
|
12
|
+
startDate: string;
|
|
13
|
+
endDate?: string;
|
|
14
|
+
cancelledAt?: string;
|
|
15
|
+
cancellationReason?: string;
|
|
16
|
+
amount?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface CustomerSubscriptionData {
|
|
19
|
+
customerRef?: string;
|
|
20
|
+
email?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
subscriptions: SubscriptionInfo[];
|
|
23
|
+
}
|
|
24
|
+
export interface PaymentIntentResult {
|
|
25
|
+
clientSecret: string;
|
|
26
|
+
publishableKey: string;
|
|
27
|
+
accountId?: string;
|
|
28
|
+
customerRef?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface SubscriptionStatus {
|
|
31
|
+
loading: boolean;
|
|
32
|
+
customerRef?: string;
|
|
33
|
+
email?: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
subscriptions: SubscriptionInfo[];
|
|
36
|
+
hasPlan: (planName: string) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Primary active subscription (paid or free) - most recent subscription with status === 'active'
|
|
39
|
+
* Backend keeps subscriptions as 'active' until expiration, even when cancelled.
|
|
40
|
+
* null if no active subscription exists
|
|
41
|
+
*/
|
|
42
|
+
activeSubscription: SubscriptionInfo | null;
|
|
43
|
+
/**
|
|
44
|
+
* Check if user has any active paid subscription (amount > 0)
|
|
45
|
+
* Checks subscriptions with status === 'active'.
|
|
46
|
+
* Backend keeps subscriptions as 'active' until expiration, even when cancelled.
|
|
47
|
+
*/
|
|
48
|
+
hasPaidSubscription: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Most recent active paid subscription (sorted by startDate)
|
|
51
|
+
* Returns subscription with status === 'active' and amount > 0.
|
|
52
|
+
* null if no active paid subscription exists
|
|
53
|
+
*/
|
|
54
|
+
activePaidSubscription: SubscriptionInfo | null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* SolvaPay Provider Configuration
|
|
58
|
+
* Sensible defaults for minimal code, but fully customizable
|
|
59
|
+
*/
|
|
60
|
+
export interface SolvaPayConfig {
|
|
61
|
+
/**
|
|
62
|
+
* API route configuration
|
|
63
|
+
* Defaults to standard Next.js API routes
|
|
64
|
+
*/
|
|
65
|
+
api?: {
|
|
66
|
+
checkSubscription?: string;
|
|
67
|
+
createPayment?: string;
|
|
68
|
+
processPayment?: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Authentication configuration
|
|
72
|
+
* Uses adapter pattern for flexible auth provider support
|
|
73
|
+
*/
|
|
74
|
+
auth?: {
|
|
75
|
+
/**
|
|
76
|
+
* Auth adapter instance
|
|
77
|
+
* Default: checks localStorage for 'auth_token' key
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```tsx
|
|
81
|
+
* import { createSupabaseAuthAdapter } from '@solvapay/react-supabase';
|
|
82
|
+
*
|
|
83
|
+
* <SolvaPayProvider
|
|
84
|
+
* config={{
|
|
85
|
+
* auth: {
|
|
86
|
+
* adapter: createSupabaseAuthAdapter({
|
|
87
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
88
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
89
|
+
* })
|
|
90
|
+
* }
|
|
91
|
+
* }}
|
|
92
|
+
* >
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
adapter?: AuthAdapter;
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated Use `adapter` instead. Will be removed in a future version.
|
|
98
|
+
* Function to get auth token
|
|
99
|
+
*/
|
|
100
|
+
getToken?: () => Promise<string | null>;
|
|
101
|
+
/**
|
|
102
|
+
* @deprecated Use `adapter` instead. Will be removed in a future version.
|
|
103
|
+
* Function to get user ID (for cache key)
|
|
104
|
+
*/
|
|
105
|
+
getUserId?: () => Promise<string | null>;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Custom fetch implementation
|
|
109
|
+
* Default: uses global fetch
|
|
110
|
+
*/
|
|
111
|
+
fetch?: typeof fetch;
|
|
112
|
+
/**
|
|
113
|
+
* Request headers to include in all API calls
|
|
114
|
+
* Default: empty
|
|
115
|
+
*/
|
|
116
|
+
headers?: HeadersInit | (() => Promise<HeadersInit>);
|
|
117
|
+
/**
|
|
118
|
+
* Custom error handler
|
|
119
|
+
* Default: logs to console
|
|
120
|
+
*/
|
|
121
|
+
onError?: (error: Error, context: string) => void;
|
|
122
|
+
}
|
|
123
|
+
export interface SolvaPayContextValue {
|
|
124
|
+
subscription: SubscriptionStatus;
|
|
125
|
+
refetchSubscription: () => Promise<void>;
|
|
126
|
+
createPayment: (params: {
|
|
127
|
+
planRef: string;
|
|
128
|
+
agentRef?: string;
|
|
129
|
+
}) => Promise<PaymentIntentResult>;
|
|
130
|
+
processPayment?: (params: {
|
|
131
|
+
paymentIntentId: string;
|
|
132
|
+
agentRef: string;
|
|
133
|
+
planRef?: string;
|
|
134
|
+
}) => Promise<ProcessPaymentResult>;
|
|
135
|
+
customerRef?: string;
|
|
136
|
+
updateCustomerRef?: (newCustomerRef: string) => void;
|
|
137
|
+
}
|
|
138
|
+
export interface SolvaPayProviderProps {
|
|
139
|
+
/**
|
|
140
|
+
* Configuration object with sensible defaults
|
|
141
|
+
* If not provided, uses standard Next.js API routes
|
|
142
|
+
*/
|
|
143
|
+
config?: SolvaPayConfig;
|
|
144
|
+
/**
|
|
145
|
+
* Custom API functions (override config defaults)
|
|
146
|
+
* Use only if you need custom logic beyond standard API routes
|
|
147
|
+
*/
|
|
148
|
+
createPayment?: (params: {
|
|
149
|
+
planRef: string;
|
|
150
|
+
agentRef?: string;
|
|
151
|
+
}) => Promise<PaymentIntentResult>;
|
|
152
|
+
checkSubscription?: () => Promise<CustomerSubscriptionData>;
|
|
153
|
+
processPayment?: (params: {
|
|
154
|
+
paymentIntentId: string;
|
|
155
|
+
agentRef: string;
|
|
156
|
+
planRef?: string;
|
|
157
|
+
}) => Promise<ProcessPaymentResult>;
|
|
158
|
+
children: React.ReactNode;
|
|
159
|
+
}
|
|
160
|
+
export interface PlanBadgeProps {
|
|
161
|
+
children?: (props: {
|
|
162
|
+
subscriptions: SubscriptionInfo[];
|
|
163
|
+
loading: boolean;
|
|
164
|
+
displayPlan: string | null;
|
|
165
|
+
shouldShow: boolean;
|
|
166
|
+
}) => React.ReactNode;
|
|
167
|
+
as?: React.ElementType;
|
|
168
|
+
className?: string | ((props: {
|
|
169
|
+
subscriptions: SubscriptionInfo[];
|
|
170
|
+
}) => string);
|
|
171
|
+
}
|
|
172
|
+
export interface SubscriptionGateProps {
|
|
173
|
+
requirePlan?: string;
|
|
174
|
+
children: (props: {
|
|
175
|
+
hasAccess: boolean;
|
|
176
|
+
subscriptions: SubscriptionInfo[];
|
|
177
|
+
loading: boolean;
|
|
178
|
+
}) => React.ReactNode;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Error type for payment operations
|
|
182
|
+
*/
|
|
183
|
+
export interface PaymentError extends Error {
|
|
184
|
+
code?: string;
|
|
185
|
+
type?: string;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Plan interface for subscription plans
|
|
189
|
+
*/
|
|
190
|
+
export interface Plan {
|
|
191
|
+
reference: string;
|
|
192
|
+
name: string;
|
|
193
|
+
description?: string;
|
|
194
|
+
price?: number;
|
|
195
|
+
currency?: string;
|
|
196
|
+
interval?: string;
|
|
197
|
+
features?: string[];
|
|
198
|
+
isFreeTier?: boolean;
|
|
199
|
+
metadata?: Record<string, any>;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Options for usePlans hook
|
|
203
|
+
*/
|
|
204
|
+
export interface UsePlansOptions {
|
|
205
|
+
/**
|
|
206
|
+
* Fetcher function to retrieve plans
|
|
207
|
+
*/
|
|
208
|
+
fetcher: (agentRef: string) => Promise<Plan[]>;
|
|
209
|
+
/**
|
|
210
|
+
* Agent reference to fetch plans for
|
|
211
|
+
*/
|
|
212
|
+
agentRef?: string;
|
|
213
|
+
/**
|
|
214
|
+
* Optional filter function to filter plans
|
|
215
|
+
*/
|
|
216
|
+
filter?: (plan: Plan) => boolean;
|
|
217
|
+
/**
|
|
218
|
+
* Optional sort function to sort plans
|
|
219
|
+
*/
|
|
220
|
+
sortBy?: (a: Plan, b: Plan) => number;
|
|
221
|
+
/**
|
|
222
|
+
* Auto-select first paid plan on load
|
|
223
|
+
*/
|
|
224
|
+
autoSelectFirstPaid?: boolean;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Return type for usePlans hook
|
|
228
|
+
*/
|
|
229
|
+
export interface UsePlansReturn {
|
|
230
|
+
plans: Plan[];
|
|
231
|
+
loading: boolean;
|
|
232
|
+
error: Error | null;
|
|
233
|
+
selectedPlanIndex: number;
|
|
234
|
+
selectedPlan: Plan | null;
|
|
235
|
+
setSelectedPlanIndex: (index: number) => void;
|
|
236
|
+
selectPlan: (planRef: string) => void;
|
|
237
|
+
refetch: () => Promise<void>;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Props for headless PlanSelector component
|
|
241
|
+
*/
|
|
242
|
+
export interface PlanSelectorProps {
|
|
243
|
+
/**
|
|
244
|
+
* Agent reference to fetch plans for
|
|
245
|
+
*/
|
|
246
|
+
agentRef?: string;
|
|
247
|
+
/**
|
|
248
|
+
* Fetcher function to retrieve plans
|
|
249
|
+
*/
|
|
250
|
+
fetcher: (agentRef: string) => Promise<Plan[]>;
|
|
251
|
+
/**
|
|
252
|
+
* Optional filter function
|
|
253
|
+
*/
|
|
254
|
+
filter?: (plan: Plan) => boolean;
|
|
255
|
+
/**
|
|
256
|
+
* Optional sort function
|
|
257
|
+
*/
|
|
258
|
+
sortBy?: (a: Plan, b: Plan) => number;
|
|
259
|
+
/**
|
|
260
|
+
* Auto-select first paid plan on load
|
|
261
|
+
*/
|
|
262
|
+
autoSelectFirstPaid?: boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Render prop function
|
|
265
|
+
*/
|
|
266
|
+
children: (props: UsePlansReturn & {
|
|
267
|
+
subscriptions: SubscriptionInfo[];
|
|
268
|
+
isPaidPlan: (planName: string) => boolean;
|
|
269
|
+
isCurrentPlan: (planName: string) => boolean;
|
|
270
|
+
}) => React.ReactNode;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Return type for useSubscriptionStatus hook
|
|
274
|
+
*
|
|
275
|
+
* Provides advanced subscription status helpers and utilities.
|
|
276
|
+
* Focuses on cancelled subscription logic and date formatting.
|
|
277
|
+
* For basic subscription data and paid status, use useSubscription() instead.
|
|
278
|
+
*/
|
|
279
|
+
export interface SubscriptionStatusReturn {
|
|
280
|
+
/**
|
|
281
|
+
* Most recent cancelled paid subscription (sorted by startDate)
|
|
282
|
+
* null if no cancelled paid subscription exists
|
|
283
|
+
*/
|
|
284
|
+
cancelledSubscription: SubscriptionInfo | null;
|
|
285
|
+
/**
|
|
286
|
+
* Whether to show cancelled subscription notice
|
|
287
|
+
* true if cancelledSubscription exists
|
|
288
|
+
*/
|
|
289
|
+
shouldShowCancelledNotice: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* Format a date string to locale format (e.g., "January 15, 2024")
|
|
292
|
+
* Returns null if dateString is not provided
|
|
293
|
+
*/
|
|
294
|
+
formatDate: (dateString?: string) => string | null;
|
|
295
|
+
/**
|
|
296
|
+
* Calculate days until expiration date
|
|
297
|
+
* Returns null if endDate is not provided, otherwise returns days (0 or positive)
|
|
298
|
+
*/
|
|
299
|
+
getDaysUntilExpiration: (endDate?: string) => number | null;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Payment form props - simplified and minimal
|
|
303
|
+
*/
|
|
304
|
+
export interface PaymentFormProps {
|
|
305
|
+
/**
|
|
306
|
+
* Plan reference to checkout. PaymentForm handles the entire checkout flow internally
|
|
307
|
+
* including Stripe initialization and payment intent creation.
|
|
308
|
+
*/
|
|
309
|
+
planRef: string;
|
|
310
|
+
/**
|
|
311
|
+
* Agent reference. Required for processing payment after confirmation.
|
|
312
|
+
*/
|
|
313
|
+
agentRef?: string;
|
|
314
|
+
/**
|
|
315
|
+
* Callback when payment succeeds
|
|
316
|
+
*/
|
|
317
|
+
onSuccess?: (paymentIntent: PaymentIntent) => void;
|
|
318
|
+
/**
|
|
319
|
+
* Callback when payment fails
|
|
320
|
+
*/
|
|
321
|
+
onError?: (error: Error) => void;
|
|
322
|
+
/**
|
|
323
|
+
* Return URL after payment completion. Defaults to current page URL if not provided.
|
|
324
|
+
*/
|
|
325
|
+
returnUrl?: string;
|
|
326
|
+
/**
|
|
327
|
+
* Text for the submit button. Defaults to "Pay Now"
|
|
328
|
+
*/
|
|
329
|
+
submitButtonText?: string;
|
|
330
|
+
/**
|
|
331
|
+
* Optional className for the form container
|
|
332
|
+
*/
|
|
333
|
+
className?: string;
|
|
334
|
+
/**
|
|
335
|
+
* Optional className for the submit button
|
|
336
|
+
*/
|
|
337
|
+
buttonClassName?: string;
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=index.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