@umituz/react-native-subscription 2.14.15 → 2.14.16
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.16",
|
|
4
4
|
"description": "Complete subscription management with RevenueCat, paywall UI, and credits system for React Native apps",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -51,7 +51,8 @@
|
|
|
51
51
|
"@types/react": "~19.1.10",
|
|
52
52
|
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
53
53
|
"@typescript-eslint/parser": "^8.50.1",
|
|
54
|
-
"@umituz/react-native-auth": "
|
|
54
|
+
"@umituz/react-native-auth": "*",
|
|
55
|
+
"@umituz/react-native-storage": "*",
|
|
55
56
|
"@umituz/react-native-design-system": "*",
|
|
56
57
|
"@umituz/react-native-firebase": "*",
|
|
57
58
|
"@umituz/react-native-legal": "*",
|
package/src/index.ts
CHANGED
|
@@ -317,6 +317,13 @@ export {
|
|
|
317
317
|
type UsePremiumResult,
|
|
318
318
|
} from "./presentation/hooks/usePremium";
|
|
319
319
|
|
|
320
|
+
export {
|
|
321
|
+
useSubscriptionStatus,
|
|
322
|
+
subscriptionStatusQueryKeys,
|
|
323
|
+
type SubscriptionStatusResult,
|
|
324
|
+
type UseSubscriptionStatusParams,
|
|
325
|
+
} from "./presentation/hooks/useSubscriptionStatus";
|
|
326
|
+
|
|
320
327
|
export {
|
|
321
328
|
usePaywallOperations,
|
|
322
329
|
type UsePaywallOperationsProps,
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
* usePremium Hook
|
|
3
3
|
* Complete subscription management for 100+ apps
|
|
4
4
|
* Works for both authenticated and anonymous users
|
|
5
|
+
*
|
|
6
|
+
* IMPORTANT: isPremium is based on actual RevenueCat subscription status,
|
|
7
|
+
* NOT on whether credits document exists.
|
|
5
8
|
*/
|
|
6
9
|
|
|
7
10
|
import { useCallback } from 'react';
|
|
8
11
|
import type { PurchasesPackage } from 'react-native-purchases';
|
|
9
12
|
import type { UserCredits } from '../../domain/entities/Credits';
|
|
10
13
|
import { useCredits } from './useCredits';
|
|
14
|
+
import { useSubscriptionStatus } from './useSubscriptionStatus';
|
|
11
15
|
import {
|
|
12
16
|
useSubscriptionPackages,
|
|
13
17
|
usePurchasePackage,
|
|
@@ -54,6 +58,13 @@ export const usePremium = (userId?: string): UsePremiumResult => {
|
|
|
54
58
|
console.log('[DEBUG usePremium] Hook called', { userId: userId || 'ANONYMOUS' });
|
|
55
59
|
}
|
|
56
60
|
|
|
61
|
+
// Fetch real subscription status from RevenueCat
|
|
62
|
+
const { isPremium: subscriptionActive, isLoading: statusLoading } =
|
|
63
|
+
useSubscriptionStatus({
|
|
64
|
+
userId,
|
|
65
|
+
enabled: !!userId,
|
|
66
|
+
});
|
|
67
|
+
|
|
57
68
|
// Fetch user credits (server state)
|
|
58
69
|
const { credits, isLoading: creditsLoading } = useCredits({
|
|
59
70
|
userId,
|
|
@@ -70,7 +81,8 @@ export const usePremium = (userId?: string): UsePremiumResult => {
|
|
|
70
81
|
packagesCount: packages?.length || 0,
|
|
71
82
|
packagesLoading,
|
|
72
83
|
creditsLoading,
|
|
73
|
-
|
|
84
|
+
statusLoading,
|
|
85
|
+
isPremium: subscriptionActive,
|
|
74
86
|
});
|
|
75
87
|
}
|
|
76
88
|
|
|
@@ -82,8 +94,8 @@ export const usePremium = (userId?: string): UsePremiumResult => {
|
|
|
82
94
|
const { showPaywall, setShowPaywall, closePaywall, openPaywall } =
|
|
83
95
|
usePaywallVisibility();
|
|
84
96
|
|
|
85
|
-
// Premium status =
|
|
86
|
-
const isPremium =
|
|
97
|
+
// Premium status = actual subscription status from RevenueCat
|
|
98
|
+
const isPremium = subscriptionActive;
|
|
87
99
|
|
|
88
100
|
// Purchase handler with proper error handling
|
|
89
101
|
const handlePurchase = useCallback(
|
|
@@ -117,6 +129,7 @@ export const usePremium = (userId?: string): UsePremiumResult => {
|
|
|
117
129
|
return {
|
|
118
130
|
isPremium,
|
|
119
131
|
isLoading:
|
|
132
|
+
statusLoading ||
|
|
120
133
|
creditsLoading ||
|
|
121
134
|
packagesLoading ||
|
|
122
135
|
purchaseMutation.isPending ||
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSubscriptionStatus Hook
|
|
3
|
+
*
|
|
4
|
+
* TanStack Query hook for checking real subscription status from RevenueCat.
|
|
5
|
+
* This provides the actual premium status based on entitlements, not credits.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useQuery } from "@tanstack/react-query";
|
|
9
|
+
import { SubscriptionManager } from "../../revenuecat/infrastructure/managers/SubscriptionManager";
|
|
10
|
+
|
|
11
|
+
declare const __DEV__: boolean;
|
|
12
|
+
|
|
13
|
+
export const subscriptionStatusQueryKeys = {
|
|
14
|
+
all: ["subscriptionStatus"] as const,
|
|
15
|
+
user: (userId: string) => ["subscriptionStatus", userId] as const,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export interface SubscriptionStatusResult {
|
|
19
|
+
isPremium: boolean;
|
|
20
|
+
expirationDate: Date | null;
|
|
21
|
+
isLoading: boolean;
|
|
22
|
+
error: Error | null;
|
|
23
|
+
refetch: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface UseSubscriptionStatusParams {
|
|
27
|
+
userId: string | undefined;
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Check real subscription status from RevenueCat
|
|
33
|
+
*
|
|
34
|
+
* @param userId - User ID
|
|
35
|
+
* @param enabled - Whether to enable the query
|
|
36
|
+
* @returns Subscription status with isPremium flag
|
|
37
|
+
*/
|
|
38
|
+
export const useSubscriptionStatus = ({
|
|
39
|
+
userId,
|
|
40
|
+
enabled = true,
|
|
41
|
+
}: UseSubscriptionStatusParams): SubscriptionStatusResult => {
|
|
42
|
+
const { data, isLoading, error, refetch } = useQuery({
|
|
43
|
+
queryKey: subscriptionStatusQueryKeys.user(userId ?? ""),
|
|
44
|
+
queryFn: async () => {
|
|
45
|
+
if (!userId) {
|
|
46
|
+
return { isPremium: false, expirationDate: null };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const status = await SubscriptionManager.checkPremiumStatus();
|
|
50
|
+
|
|
51
|
+
if (__DEV__) {
|
|
52
|
+
console.log("[useSubscriptionStatus] Status from RevenueCat", {
|
|
53
|
+
userId,
|
|
54
|
+
isPremium: status.isPremium,
|
|
55
|
+
expirationDate: status.expirationDate,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return status;
|
|
60
|
+
},
|
|
61
|
+
enabled: enabled && !!userId && SubscriptionManager.isInitialized(),
|
|
62
|
+
staleTime: 30 * 1000,
|
|
63
|
+
gcTime: 5 * 60 * 1000,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
isPremium: data?.isPremium ?? false,
|
|
68
|
+
expirationDate: data?.expirationDate ?? null,
|
|
69
|
+
isLoading,
|
|
70
|
+
error: error as Error | null,
|
|
71
|
+
refetch,
|
|
72
|
+
};
|
|
73
|
+
};
|