@umituz/react-native-subscription 2.35.13 → 2.35.14
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.35.
|
|
3
|
+
"version": "2.35.14",
|
|
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",
|
|
@@ -7,6 +7,8 @@ import type { PurchasesPackage } from "react-native-purchases";
|
|
|
7
7
|
import { usePurchaseLoadingStore } from "../../subscription/presentation/stores";
|
|
8
8
|
import type { PurchaseSource } from "../../subscription/core/SubscriptionConstants";
|
|
9
9
|
|
|
10
|
+
declare const __DEV__: boolean;
|
|
11
|
+
|
|
10
12
|
export interface UsePaywallActionsParams {
|
|
11
13
|
packages?: PurchasesPackage[];
|
|
12
14
|
onPurchase?: (pkg: PurchasesPackage) => Promise<void | boolean>;
|
|
@@ -52,49 +54,163 @@ export function usePaywallActions({
|
|
|
52
54
|
});
|
|
53
55
|
|
|
54
56
|
const handlePurchase = useCallback(async () => {
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
58
|
+
console.log("[usePaywallActions] handlePurchase called", {
|
|
59
|
+
selectedPlanId,
|
|
60
|
+
hasOnPurchase: !!onPurchaseRef.current,
|
|
61
|
+
isProcessing,
|
|
62
|
+
packagesCount: packages.length,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!selectedPlanId) {
|
|
67
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
68
|
+
console.warn("[usePaywallActions] ❌ No plan selected");
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!onPurchaseRef.current) {
|
|
74
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
75
|
+
console.error("[usePaywallActions] ❌ No onPurchase callback provided");
|
|
76
|
+
}
|
|
77
|
+
const err = new Error("Purchase handler not configured");
|
|
78
|
+
onPurchaseErrorRef.current?.(err);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (isProcessing) {
|
|
83
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
84
|
+
console.warn("[usePaywallActions] ⚠️ Already processing, ignoring duplicate request");
|
|
58
85
|
}
|
|
59
86
|
return;
|
|
60
87
|
}
|
|
61
88
|
|
|
89
|
+
const pkg = packages.find((p) => p.product.identifier === selectedPlanId);
|
|
90
|
+
|
|
91
|
+
if (!pkg) {
|
|
92
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
93
|
+
console.error("[usePaywallActions] ❌ Package not found", {
|
|
94
|
+
selectedPlanId,
|
|
95
|
+
availablePackages: packages.map(p => p.product.identifier),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const err = new Error(`Package not found: ${selectedPlanId}`);
|
|
99
|
+
onPurchaseErrorRef.current?.(err);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
104
|
+
console.log("[usePaywallActions] ✅ Starting purchase", {
|
|
105
|
+
productId: pkg.product.identifier,
|
|
106
|
+
title: pkg.product.title,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
62
110
|
setIsLocalProcessing(true);
|
|
63
111
|
startPurchase(selectedPlanId, "manual");
|
|
64
112
|
|
|
65
113
|
try {
|
|
66
|
-
|
|
114
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
115
|
+
console.log("[usePaywallActions] 🚀 Calling onPurchase callback");
|
|
116
|
+
}
|
|
67
117
|
|
|
68
|
-
|
|
69
|
-
const success = await onPurchaseRef.current(pkg);
|
|
118
|
+
const success = await onPurchaseRef.current(pkg);
|
|
70
119
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
120
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
121
|
+
console.log("[usePaywallActions] 📦 Purchase result:", { success, type: typeof success });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (success === true) {
|
|
125
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
126
|
+
console.log("[usePaywallActions] ✅ Purchase successful, calling success callbacks");
|
|
127
|
+
}
|
|
128
|
+
onPurchaseSuccessRef.current?.();
|
|
129
|
+
onCloseRef.current?.();
|
|
130
|
+
} else if (success === false) {
|
|
131
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
132
|
+
console.warn("[usePaywallActions] ⚠️ Purchase returned false (user cancelled or failed)");
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
136
|
+
console.error("[usePaywallActions] ❌ Purchase returned unexpected value:", success);
|
|
74
137
|
}
|
|
75
138
|
}
|
|
76
139
|
} catch (error) {
|
|
140
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
141
|
+
console.error("[usePaywallActions] ❌ Purchase error:", error);
|
|
142
|
+
}
|
|
77
143
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
78
144
|
onPurchaseErrorRef.current?.(err);
|
|
79
145
|
} finally {
|
|
146
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
147
|
+
console.log("[usePaywallActions] 🏁 Purchase completed, cleaning up");
|
|
148
|
+
}
|
|
80
149
|
setIsLocalProcessing(false);
|
|
81
150
|
endPurchase(selectedPlanId);
|
|
82
151
|
}
|
|
83
152
|
}, [selectedPlanId, packages, isProcessing, startPurchase, endPurchase]);
|
|
84
153
|
|
|
85
154
|
const handleRestore = useCallback(async () => {
|
|
86
|
-
if (
|
|
155
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
156
|
+
console.log("[usePaywallActions] handleRestore called", {
|
|
157
|
+
hasOnRestore: !!onRestoreRef.current,
|
|
158
|
+
isProcessing,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (!onRestoreRef.current) {
|
|
163
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
164
|
+
console.error("[usePaywallActions] ❌ No onRestore callback provided");
|
|
165
|
+
}
|
|
166
|
+
const err = new Error("Restore handler not configured");
|
|
167
|
+
onPurchaseErrorRef.current?.(err);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (isProcessing) {
|
|
172
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
173
|
+
console.warn("[usePaywallActions] ⚠️ Already processing, ignoring restore request");
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
87
177
|
|
|
88
178
|
setIsLocalProcessing(true);
|
|
89
179
|
try {
|
|
180
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
181
|
+
console.log("[usePaywallActions] 🚀 Calling onRestore callback");
|
|
182
|
+
}
|
|
183
|
+
|
|
90
184
|
const success = await onRestoreRef.current();
|
|
91
|
-
|
|
185
|
+
|
|
186
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
187
|
+
console.log("[usePaywallActions] 📦 Restore result:", { success, type: typeof success });
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (success === true) {
|
|
191
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
192
|
+
console.log("[usePaywallActions] ✅ Restore successful");
|
|
193
|
+
}
|
|
92
194
|
onPurchaseSuccessRef.current?.();
|
|
195
|
+
} else if (success === false) {
|
|
196
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
197
|
+
console.warn("[usePaywallActions] ⚠️ Restore returned false");
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
201
|
+
console.error("[usePaywallActions] ❌ Restore returned unexpected value:", success);
|
|
202
|
+
}
|
|
93
203
|
}
|
|
94
204
|
} catch (error) {
|
|
205
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
206
|
+
console.error("[usePaywallActions] ❌ Restore error:", error);
|
|
207
|
+
}
|
|
95
208
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
96
209
|
onPurchaseErrorRef.current?.(err);
|
|
97
210
|
} finally {
|
|
211
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
212
|
+
console.log("[usePaywallActions] 🏁 Restore completed");
|
|
213
|
+
}
|
|
98
214
|
setIsLocalProcessing(false);
|
|
99
215
|
}
|
|
100
216
|
}, [isProcessing]);
|
|
@@ -9,6 +9,8 @@ import { usePremium } from "./usePremium";
|
|
|
9
9
|
import type { PurchaseSource } from "../core/SubscriptionConstants";
|
|
10
10
|
import { authPurchaseStateManager } from "../infrastructure/utils/authPurchaseState";
|
|
11
11
|
|
|
12
|
+
declare const __DEV__: boolean;
|
|
13
|
+
|
|
12
14
|
export type { PurchaseAuthProvider } from "../infrastructure/utils/authPurchaseState";
|
|
13
15
|
|
|
14
16
|
export const configureAuthProvider = (provider: import("../infrastructure/utils/authPurchaseState").PurchaseAuthProvider): void => {
|
|
@@ -44,38 +46,85 @@ export const useAuthAwarePurchase = (
|
|
|
44
46
|
|
|
45
47
|
const handlePurchase = useCallback(
|
|
46
48
|
async (pkg: PurchasesPackage, source?: PurchaseSource): Promise<boolean> => {
|
|
49
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
50
|
+
console.log("[useAuthAwarePurchase] handlePurchase called", {
|
|
51
|
+
productId: pkg.product.identifier,
|
|
52
|
+
source: source || params?.source,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
47
56
|
const authProvider = authPurchaseStateManager.getProvider();
|
|
48
57
|
|
|
49
58
|
if (!authProvider) {
|
|
59
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
60
|
+
console.error("[useAuthAwarePurchase] ❌ No auth provider configured");
|
|
61
|
+
}
|
|
50
62
|
return false;
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
const isAuth = authProvider.isAuthenticated();
|
|
54
66
|
|
|
67
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
68
|
+
console.log("[useAuthAwarePurchase] Auth status:", { isAuth });
|
|
69
|
+
}
|
|
70
|
+
|
|
55
71
|
if (!isAuth) {
|
|
72
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
73
|
+
console.log("[useAuthAwarePurchase] 🔐 User not authenticated, saving purchase and showing auth modal");
|
|
74
|
+
}
|
|
56
75
|
authPurchaseStateManager.savePurchase(pkg, source || params?.source || "settings");
|
|
57
76
|
authProvider.showAuthModal();
|
|
58
77
|
return false;
|
|
59
78
|
}
|
|
60
79
|
|
|
61
|
-
|
|
80
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
81
|
+
console.log("[useAuthAwarePurchase] ✅ User authenticated, proceeding with purchase");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const result = await purchasePackage(pkg);
|
|
85
|
+
|
|
86
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
87
|
+
console.log("[useAuthAwarePurchase] Purchase result:", result);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return result;
|
|
62
91
|
},
|
|
63
92
|
[purchasePackage, params?.source]
|
|
64
93
|
);
|
|
65
94
|
|
|
66
95
|
const handleRestore = useCallback(async (): Promise<boolean> => {
|
|
96
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
97
|
+
console.log("[useAuthAwarePurchase] handleRestore called");
|
|
98
|
+
}
|
|
99
|
+
|
|
67
100
|
const authProvider = authPurchaseStateManager.getProvider();
|
|
68
101
|
|
|
69
102
|
if (!authProvider) {
|
|
103
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
104
|
+
console.error("[useAuthAwarePurchase] ❌ No auth provider configured");
|
|
105
|
+
}
|
|
70
106
|
return false;
|
|
71
107
|
}
|
|
72
108
|
|
|
73
109
|
if (!authProvider.isAuthenticated()) {
|
|
110
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
111
|
+
console.log("[useAuthAwarePurchase] 🔐 User not authenticated, showing auth modal");
|
|
112
|
+
}
|
|
74
113
|
authProvider.showAuthModal();
|
|
75
114
|
return false;
|
|
76
115
|
}
|
|
77
116
|
|
|
78
|
-
|
|
117
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
118
|
+
console.log("[useAuthAwarePurchase] ✅ User authenticated, proceeding with restore");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const result = await restorePurchase();
|
|
122
|
+
|
|
123
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
124
|
+
console.log("[useAuthAwarePurchase] Restore result:", result);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return result;
|
|
79
128
|
}, [restorePurchase]);
|
|
80
129
|
|
|
81
130
|
const executeSavedPurchase = useCallback(async (): Promise<boolean> => {
|