@umituz/react-native-subscription 2.33.6 → 2.33.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.33.
|
|
3
|
+
"version": "2.33.8",
|
|
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",
|
|
@@ -19,6 +19,8 @@ import { subscriptionStatusQueryKeys } from "../../presentation/useSubscriptionS
|
|
|
19
19
|
import { creditsQueryKeys } from "../../../credits/presentation/creditsQueryKeys";
|
|
20
20
|
import { getErrorMessage } from "../../../revenuecat/core/errors";
|
|
21
21
|
|
|
22
|
+
declare const __DEV__: boolean;
|
|
23
|
+
|
|
22
24
|
/** Purchase mutation result - simplified for presentation layer */
|
|
23
25
|
export interface PurchaseMutationResult {
|
|
24
26
|
success: boolean;
|
|
@@ -39,21 +41,51 @@ export const usePurchasePackage = () => {
|
|
|
39
41
|
|
|
40
42
|
return useMutation({
|
|
41
43
|
mutationFn: async (pkg: PurchasesPackage): Promise<PurchaseMutationResult> => {
|
|
44
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
45
|
+
console.log("[Purchase] ========================================");
|
|
46
|
+
console.log("[Purchase] mutationFn called:", {
|
|
47
|
+
productId: pkg.product.identifier,
|
|
48
|
+
userId,
|
|
49
|
+
isAnonymous,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
if (!userId) {
|
|
54
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
55
|
+
console.log("[Purchase] ERROR: User not authenticated");
|
|
56
|
+
}
|
|
43
57
|
throw new Error("User not authenticated");
|
|
44
58
|
}
|
|
45
59
|
|
|
46
60
|
if (isAnonymous) {
|
|
61
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
62
|
+
console.log("[Purchase] ERROR: Anonymous users cannot purchase");
|
|
63
|
+
}
|
|
47
64
|
throw new Error("Anonymous users cannot purchase subscriptions");
|
|
48
65
|
}
|
|
49
66
|
|
|
50
67
|
const productId = pkg.product.identifier;
|
|
68
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
69
|
+
console.log("[Purchase] Calling SubscriptionManager.purchasePackage()");
|
|
70
|
+
}
|
|
71
|
+
|
|
51
72
|
const success = await SubscriptionManager.purchasePackage(pkg);
|
|
52
73
|
|
|
74
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
75
|
+
console.log("[Purchase] Purchase completed:", { success, productId });
|
|
76
|
+
}
|
|
77
|
+
|
|
53
78
|
return { success, productId };
|
|
54
79
|
},
|
|
55
80
|
onSuccess: (result) => {
|
|
81
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
82
|
+
console.log("[Purchase] onSuccess called:", result);
|
|
83
|
+
}
|
|
84
|
+
|
|
56
85
|
if (result.success) {
|
|
86
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
87
|
+
console.log("[Purchase] ✅ Purchase successful! Invalidating queries...");
|
|
88
|
+
}
|
|
57
89
|
showSuccess("Purchase Successful", "Your subscription is now active!");
|
|
58
90
|
queryClient.invalidateQueries({
|
|
59
91
|
queryKey: SUBSCRIPTION_QUERY_KEYS.packages,
|
|
@@ -65,17 +97,34 @@ export const usePurchasePackage = () => {
|
|
|
65
97
|
queryClient.invalidateQueries({
|
|
66
98
|
queryKey: creditsQueryKeys.user(userId),
|
|
67
99
|
});
|
|
100
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
101
|
+
console.log("[Purchase] Queries invalidated - credits should reload now");
|
|
102
|
+
}
|
|
68
103
|
}
|
|
69
104
|
} else {
|
|
105
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
106
|
+
console.log("[Purchase] ❌ Purchase failed");
|
|
107
|
+
}
|
|
70
108
|
showError("Purchase Failed", "Unable to complete purchase. Please try again.");
|
|
71
109
|
}
|
|
72
110
|
},
|
|
73
111
|
onError: (error) => {
|
|
112
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
113
|
+
console.log("[Purchase] onError called:", error);
|
|
114
|
+
}
|
|
115
|
+
|
|
74
116
|
// Use map-based lookup - O(1) complexity
|
|
75
117
|
const errorInfo = getErrorMessage(error);
|
|
76
118
|
|
|
119
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
120
|
+
console.log("[Purchase] Error info:", errorInfo);
|
|
121
|
+
}
|
|
122
|
+
|
|
77
123
|
// Don't show alert for user cancellation
|
|
78
124
|
if (!errorInfo.shouldShowAlert) {
|
|
125
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
126
|
+
console.log("[Purchase] User cancelled - not showing alert");
|
|
127
|
+
}
|
|
79
128
|
return;
|
|
80
129
|
}
|
|
81
130
|
|
|
@@ -6,6 +6,8 @@ import { executeFeatureAction } from "./featureGateActions";
|
|
|
6
6
|
|
|
7
7
|
export type { UseFeatureGateParams, UseFeatureGateResult } from "./useFeatureGate.types";
|
|
8
8
|
|
|
9
|
+
declare const __DEV__: boolean;
|
|
10
|
+
|
|
9
11
|
export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResult {
|
|
10
12
|
const {
|
|
11
13
|
isAuthenticated,
|
|
@@ -25,14 +27,34 @@ export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResu
|
|
|
25
27
|
const { creditBalanceRef, hasSubscriptionRef, onShowPaywallRef, requiredCreditsRef, isCreditsLoadedRef } = useSyncedRefs(creditBalance, hasSubscription, onShowPaywall, requiredCredits, isCreditsLoaded);
|
|
26
28
|
|
|
27
29
|
useEffect(() => {
|
|
28
|
-
if (
|
|
30
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
31
|
+
console.log("[FeatureGate] Auth completion useEffect triggered:", {
|
|
32
|
+
isWaitingForAuthCredits: isWaitingForAuthCreditsRef.current,
|
|
33
|
+
isCreditsLoaded,
|
|
34
|
+
hasPendingAction: !!pendingActionRef.current,
|
|
35
|
+
hasSubscription,
|
|
36
|
+
creditBalance,
|
|
37
|
+
requiredCredits,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const shouldExecute = shouldExecuteAuthAction(
|
|
29
42
|
isWaitingForAuthCreditsRef.current,
|
|
30
43
|
isCreditsLoaded,
|
|
31
44
|
!!pendingActionRef.current,
|
|
32
45
|
hasSubscription,
|
|
33
46
|
creditBalance,
|
|
34
47
|
requiredCredits
|
|
35
|
-
)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
51
|
+
console.log("[FeatureGate] shouldExecuteAuthAction:", shouldExecute);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (shouldExecute) {
|
|
55
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
56
|
+
console.log("[FeatureGate] ✅ EXECUTING PENDING ACTION after auth!");
|
|
57
|
+
}
|
|
36
58
|
isWaitingForAuthCreditsRef.current = false;
|
|
37
59
|
const action = pendingActionRef.current!;
|
|
38
60
|
pendingActionRef.current = null;
|
|
@@ -41,6 +63,9 @@ export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResu
|
|
|
41
63
|
}
|
|
42
64
|
|
|
43
65
|
if (isWaitingForAuthCreditsRef.current && isCreditsLoaded && pendingActionRef.current) {
|
|
66
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
67
|
+
console.log("[FeatureGate] Auth credits loaded but insufficient, showing paywall");
|
|
68
|
+
}
|
|
44
69
|
isWaitingForAuthCreditsRef.current = false;
|
|
45
70
|
isWaitingForPurchaseRef.current = true;
|
|
46
71
|
onShowPaywall(requiredCredits);
|
|
@@ -48,14 +73,34 @@ export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResu
|
|
|
48
73
|
}, [isCreditsLoaded, creditBalance, hasSubscription, requiredCredits, onShowPaywall]);
|
|
49
74
|
|
|
50
75
|
useEffect(() => {
|
|
51
|
-
if (
|
|
76
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
77
|
+
console.log("[FeatureGate] Purchase completion useEffect triggered:", {
|
|
78
|
+
creditBalance,
|
|
79
|
+
prevCreditBalance: prevCreditBalanceRef.current,
|
|
80
|
+
hasSubscription,
|
|
81
|
+
prevHasSubscription: hasSubscriptionRef.current,
|
|
82
|
+
isWaitingForPurchase: isWaitingForPurchaseRef.current,
|
|
83
|
+
hasPendingAction: !!pendingActionRef.current,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const shouldExecute = shouldExecutePurchaseAction(
|
|
52
88
|
isWaitingForPurchaseRef.current,
|
|
53
89
|
creditBalance,
|
|
54
90
|
prevCreditBalanceRef.current ?? 0,
|
|
55
91
|
hasSubscription,
|
|
56
92
|
hasSubscriptionRef.current,
|
|
57
93
|
!!pendingActionRef.current
|
|
58
|
-
)
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
97
|
+
console.log("[FeatureGate] shouldExecutePurchaseAction:", shouldExecute);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (shouldExecute) {
|
|
101
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
102
|
+
console.log("[FeatureGate] ✅ EXECUTING PENDING ACTION after purchase!");
|
|
103
|
+
}
|
|
59
104
|
const action = pendingActionRef.current!;
|
|
60
105
|
pendingActionRef.current = null;
|
|
61
106
|
isWaitingForPurchaseRef.current = false;
|