@umituz/react-native-subscription 2.11.6 → 2.11.8
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/package.json +1 -1
- package/src/presentation/components/details/CreditRow.tsx +83 -0
- package/src/presentation/components/details/DetailRow.tsx +53 -0
- package/src/presentation/components/details/PremiumDetailsCard.tsx +5 -155
- package/src/presentation/components/details/PremiumDetailsCardTypes.ts +41 -0
- package/src/presentation/components/paywall/BestValueBadge.tsx +0 -1
- package/src/presentation/components/paywall/PaywallFeaturesList.tsx +0 -3
- package/src/presentation/components/paywall/PaywallLegalFooter.tsx +5 -62
- package/src/presentation/components/paywall/PaywallLegalFooterStyles.ts +53 -0
- package/src/presentation/components/paywall/PaywallLegalFooterTypes.ts +19 -0
- package/src/presentation/components/paywall/PaywallModal.tsx +1 -1
- package/src/presentation/components/paywall/SubscriptionFooter.tsx +2 -6
- package/src/presentation/components/paywall/SubscriptionModal.tsx +0 -10
- package/src/presentation/components/paywall/SubscriptionPlanCard.tsx +5 -68
- package/src/presentation/components/paywall/SubscriptionPlanCardStyles.ts +61 -0
- package/src/presentation/components/paywall/SubscriptionPlanCardTypes.ts +15 -0
- package/src/presentation/hooks/useDeductCredit.ts +5 -4
- package/src/presentation/hooks/usePremiumWithConfig.ts +2 -1
- package/src/presentation/hooks/useSubscriptionModal.ts +2 -2
- package/src/revenuecat/presentation/hooks/subscriptionQueryKeys.ts +16 -0
- package/src/revenuecat/presentation/hooks/useInitializeSubscription.ts +56 -0
- package/src/revenuecat/presentation/hooks/usePurchasePackage.ts +79 -0
- package/src/revenuecat/presentation/hooks/useRestorePurchase.ts +68 -0
- package/src/revenuecat/presentation/hooks/useSubscriptionPackages.ts +44 -0
- package/src/revenuecat/presentation/hooks/useSubscriptionQueries.ts +9 -216
|
@@ -4,219 +4,12 @@
|
|
|
4
4
|
* Generic hooks for 100+ apps
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* Query keys for TanStack Query
|
|
17
|
-
*/
|
|
18
|
-
export const SUBSCRIPTION_QUERY_KEYS = {
|
|
19
|
-
packages: ["subscription", "packages"] as const,
|
|
20
|
-
initialized: (userId: string) =>
|
|
21
|
-
["subscription", "initialized", userId] as const,
|
|
22
|
-
} as const;
|
|
23
|
-
|
|
24
|
-
const STALE_TIME = 5 * 60 * 1000; // 5 minutes
|
|
25
|
-
const GC_TIME = 30 * 60 * 1000; // 30 minutes
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Initialize subscription with RevenueCat
|
|
29
|
-
*/
|
|
30
|
-
export const useInitializeSubscription = (userId: string | undefined) => {
|
|
31
|
-
const queryClient = useQueryClient();
|
|
32
|
-
|
|
33
|
-
return useMutation({
|
|
34
|
-
mutationFn: async () => {
|
|
35
|
-
if (!userId) {
|
|
36
|
-
throw new Error("User not authenticated");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
addPackageBreadcrumb("subscription", "Initialize mutation started", {
|
|
40
|
-
userId,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return SubscriptionManager.initialize(userId);
|
|
44
|
-
},
|
|
45
|
-
onSuccess: () => {
|
|
46
|
-
if (userId) {
|
|
47
|
-
queryClient.invalidateQueries({
|
|
48
|
-
queryKey: SUBSCRIPTION_QUERY_KEYS.packages,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
addPackageBreadcrumb(
|
|
52
|
-
"subscription",
|
|
53
|
-
"Initialize mutation success - packages invalidated",
|
|
54
|
-
{ userId }
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
onError: (error) => {
|
|
59
|
-
trackPackageError(
|
|
60
|
-
error instanceof Error ? error : new Error(String(error)),
|
|
61
|
-
{
|
|
62
|
-
packageName: "subscription",
|
|
63
|
-
operation: "initialize_mutation",
|
|
64
|
-
userId: userId ?? "NO_USER",
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Fetch available subscription packages
|
|
73
|
-
*/
|
|
74
|
-
export const useSubscriptionPackages = (userId: string | undefined) => {
|
|
75
|
-
return useQuery({
|
|
76
|
-
queryKey: [...SUBSCRIPTION_QUERY_KEYS.packages, userId] as const,
|
|
77
|
-
queryFn: async () => {
|
|
78
|
-
addPackageBreadcrumb("subscription", "Fetch packages query started", {
|
|
79
|
-
userId: userId ?? "NO_USER",
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Skip if already initialized for this specific user
|
|
83
|
-
if (!userId || !SubscriptionManager.isInitializedForUser(userId)) {
|
|
84
|
-
await SubscriptionManager.initialize(userId);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const packages = await SubscriptionManager.getPackages();
|
|
88
|
-
|
|
89
|
-
addPackageBreadcrumb("subscription", "Fetch packages query success", {
|
|
90
|
-
userId: userId ?? "NO_USER",
|
|
91
|
-
count: packages.length,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return packages;
|
|
95
|
-
},
|
|
96
|
-
staleTime: STALE_TIME,
|
|
97
|
-
gcTime: GC_TIME,
|
|
98
|
-
enabled: !!userId, // Only run when userId is available
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Purchase a subscription package
|
|
104
|
-
*/
|
|
105
|
-
export const usePurchasePackage = (userId: string | undefined) => {
|
|
106
|
-
const queryClient = useQueryClient();
|
|
107
|
-
|
|
108
|
-
return useMutation({
|
|
109
|
-
mutationFn: async (pkg: PurchasesPackage) => {
|
|
110
|
-
if (!userId) {
|
|
111
|
-
throw new Error("User not authenticated");
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
addPackageBreadcrumb("subscription", "Purchase started", {
|
|
115
|
-
packageId: pkg.identifier,
|
|
116
|
-
userId,
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
addPackageBreadcrumb("subscription", "Purchase mutation started", {
|
|
120
|
-
packageId: pkg.identifier,
|
|
121
|
-
userId,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
const success = await SubscriptionManager.purchasePackage(pkg);
|
|
125
|
-
|
|
126
|
-
if (success) {
|
|
127
|
-
addPackageBreadcrumb("subscription", "Purchase success", {
|
|
128
|
-
packageId: pkg.identifier,
|
|
129
|
-
userId,
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
addPackageBreadcrumb("subscription", "Purchase mutation success", {
|
|
133
|
-
packageId: pkg.identifier,
|
|
134
|
-
userId,
|
|
135
|
-
});
|
|
136
|
-
} else {
|
|
137
|
-
addPackageBreadcrumb("subscription", "Purchase cancelled", {
|
|
138
|
-
packageId: pkg.identifier,
|
|
139
|
-
userId,
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
addPackageBreadcrumb("subscription", "Purchase mutation failed", {
|
|
143
|
-
packageId: pkg.identifier,
|
|
144
|
-
userId,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return success;
|
|
149
|
-
},
|
|
150
|
-
onSuccess: () => {
|
|
151
|
-
queryClient.invalidateQueries({
|
|
152
|
-
queryKey: SUBSCRIPTION_QUERY_KEYS.packages,
|
|
153
|
-
});
|
|
154
|
-
},
|
|
155
|
-
onError: (error) => {
|
|
156
|
-
trackPackageError(
|
|
157
|
-
error instanceof Error ? error : new Error(String(error)),
|
|
158
|
-
{
|
|
159
|
-
packageName: "subscription",
|
|
160
|
-
operation: "purchase_mutation",
|
|
161
|
-
userId: userId ?? "NO_USER",
|
|
162
|
-
}
|
|
163
|
-
);
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Restore previous purchases
|
|
170
|
-
*/
|
|
171
|
-
export const useRestorePurchase = (userId: string | undefined) => {
|
|
172
|
-
const queryClient = useQueryClient();
|
|
173
|
-
|
|
174
|
-
return useMutation({
|
|
175
|
-
mutationFn: async () => {
|
|
176
|
-
if (!userId) {
|
|
177
|
-
throw new Error("User not authenticated");
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
addPackageBreadcrumb("subscription", "Restore started", {
|
|
181
|
-
userId,
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
addPackageBreadcrumb("subscription", "Restore mutation started", {
|
|
185
|
-
userId,
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
const success = await SubscriptionManager.restore();
|
|
189
|
-
|
|
190
|
-
if (success) {
|
|
191
|
-
addPackageBreadcrumb("subscription", "Restore success", {
|
|
192
|
-
userId,
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
addPackageBreadcrumb("subscription", "Restore mutation success", {
|
|
196
|
-
userId,
|
|
197
|
-
});
|
|
198
|
-
} else {
|
|
199
|
-
addPackageBreadcrumb("subscription", "Restore mutation failed", {
|
|
200
|
-
userId,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return success;
|
|
205
|
-
},
|
|
206
|
-
onSuccess: () => {
|
|
207
|
-
queryClient.invalidateQueries({
|
|
208
|
-
queryKey: SUBSCRIPTION_QUERY_KEYS.packages,
|
|
209
|
-
});
|
|
210
|
-
},
|
|
211
|
-
onError: (error) => {
|
|
212
|
-
trackPackageError(
|
|
213
|
-
error instanceof Error ? error : new Error(String(error)),
|
|
214
|
-
{
|
|
215
|
-
packageName: "subscription",
|
|
216
|
-
operation: "restore_mutation",
|
|
217
|
-
userId: userId ?? "NO_USER",
|
|
218
|
-
}
|
|
219
|
-
);
|
|
220
|
-
},
|
|
221
|
-
});
|
|
222
|
-
};
|
|
7
|
+
export {
|
|
8
|
+
SUBSCRIPTION_QUERY_KEYS,
|
|
9
|
+
STALE_TIME,
|
|
10
|
+
GC_TIME,
|
|
11
|
+
} from "./subscriptionQueryKeys";
|
|
12
|
+
export { useInitializeSubscription } from "./useInitializeSubscription";
|
|
13
|
+
export { useSubscriptionPackages } from "./useSubscriptionPackages";
|
|
14
|
+
export { usePurchasePackage } from "./usePurchasePackage";
|
|
15
|
+
export { useRestorePurchase } from "./useRestorePurchase";
|