@umituz/react-native-subscription 2.40.6 → 2.40.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.40.
|
|
3
|
+
"version": "2.40.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",
|
|
@@ -2,6 +2,8 @@ import { useState, useCallback, useRef, useMemo } from "react";
|
|
|
2
2
|
import type { PurchasesPackage } from "react-native-purchases";
|
|
3
3
|
import { usePurchaseLoadingStore, selectIsPurchasing } from "../../subscription/presentation/stores/purchaseLoadingStore";
|
|
4
4
|
import type { PurchaseSource } from "../../subscription/core/SubscriptionConstants";
|
|
5
|
+
import { useSubscriptionStatus } from "../../subscription/presentation/useSubscriptionStatus";
|
|
6
|
+
import { useCredits } from "../../credits/presentation/useCredits";
|
|
5
7
|
|
|
6
8
|
interface UsePaywallActionsParams {
|
|
7
9
|
packages?: PurchasesPackage[];
|
|
@@ -29,6 +31,10 @@ export function usePaywallActions({
|
|
|
29
31
|
// Use optimized selector for global purchasing state
|
|
30
32
|
const isGlobalPurchasing = usePurchaseLoadingStore(selectIsPurchasing);
|
|
31
33
|
|
|
34
|
+
// Get premium and credits status for fallback success checks
|
|
35
|
+
const { refetch: refetchStatus } = useSubscriptionStatus();
|
|
36
|
+
const { refetch: refetchCredits } = useCredits();
|
|
37
|
+
|
|
32
38
|
// Combine processing states
|
|
33
39
|
const isProcessing = isLocalProcessing || isGlobalPurchasing;
|
|
34
40
|
|
|
@@ -90,7 +96,39 @@ export function usePaywallActions({
|
|
|
90
96
|
if (__DEV__) {
|
|
91
97
|
console.log('[usePaywallActions] Purchase completed', { success });
|
|
92
98
|
}
|
|
93
|
-
|
|
99
|
+
|
|
100
|
+
// Check if purchase was successful
|
|
101
|
+
// We consider it success if:
|
|
102
|
+
// 1. Handler returns true
|
|
103
|
+
// 2. Handler returns void (undefined) but user is now premium (fallback for misconfigured handlers)
|
|
104
|
+
let isActuallySuccessful = success === true;
|
|
105
|
+
|
|
106
|
+
if (success === undefined) {
|
|
107
|
+
if (__DEV__) {
|
|
108
|
+
console.log('[usePaywallActions] Handler returned undefined, checking premium status as fallback...');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Use Promise.all to fetch both in parallel
|
|
112
|
+
const [statusResult, creditsResult] = await Promise.all([
|
|
113
|
+
refetchStatus(),
|
|
114
|
+
refetchCredits()
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
const isSubscriptionPremium = statusResult.data?.isPremium ?? false;
|
|
118
|
+
const isCreditsPremium = creditsResult.data?.isPremium ?? false;
|
|
119
|
+
|
|
120
|
+
isActuallySuccessful = isSubscriptionPremium || isCreditsPremium;
|
|
121
|
+
|
|
122
|
+
if (__DEV__) {
|
|
123
|
+
console.log('[usePaywallActions] Fallback check result:', {
|
|
124
|
+
isSubscriptionPremium,
|
|
125
|
+
isCreditsPremium,
|
|
126
|
+
isActuallySuccessful
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (isActuallySuccessful) {
|
|
94
132
|
if (__DEV__) {
|
|
95
133
|
console.log('[usePaywallActions] Purchase successful, calling onPurchaseSuccess and onClose');
|
|
96
134
|
}
|
|
@@ -99,7 +137,7 @@ export function usePaywallActions({
|
|
|
99
137
|
onCloseRef.current?.();
|
|
100
138
|
} else {
|
|
101
139
|
if (__DEV__) {
|
|
102
|
-
console.warn('[usePaywallActions] Purchase
|
|
140
|
+
console.warn('[usePaywallActions] Purchase did not indicate success, not closing');
|
|
103
141
|
}
|
|
104
142
|
}
|
|
105
143
|
} catch (error) {
|
|
@@ -108,7 +146,7 @@ export function usePaywallActions({
|
|
|
108
146
|
setIsLocalProcessing(false);
|
|
109
147
|
endPurchase(currentSelectedId);
|
|
110
148
|
}
|
|
111
|
-
}, [selectedPlanId, startPurchase, endPurchase]); // Only depend on state that must trigger re-creation if changed
|
|
149
|
+
}, [selectedPlanId, startPurchase, endPurchase, refetchStatus, refetchCredits]); // Only depend on state that must trigger re-creation if changed
|
|
112
150
|
|
|
113
151
|
const handleRestore = useCallback(async () => {
|
|
114
152
|
if (!onRestoreRef.current) {
|
|
@@ -131,7 +169,19 @@ export function usePaywallActions({
|
|
|
131
169
|
if (__DEV__) {
|
|
132
170
|
console.log('[usePaywallActions] Restore completed', { success });
|
|
133
171
|
}
|
|
134
|
-
|
|
172
|
+
|
|
173
|
+
// Check success with same fallback as purchase
|
|
174
|
+
let isActuallySuccessful = success === true;
|
|
175
|
+
|
|
176
|
+
if (success === undefined) {
|
|
177
|
+
const [statusResult, creditsResult] = await Promise.all([
|
|
178
|
+
refetchStatus(),
|
|
179
|
+
refetchCredits()
|
|
180
|
+
]);
|
|
181
|
+
isActuallySuccessful = (statusResult.data?.isPremium ?? false) || (creditsResult.data?.isPremium ?? false);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (isActuallySuccessful) {
|
|
135
185
|
if (__DEV__) {
|
|
136
186
|
console.log('[usePaywallActions] Restore successful, calling onPurchaseSuccess and onClose');
|
|
137
187
|
}
|
|
@@ -139,7 +189,7 @@ export function usePaywallActions({
|
|
|
139
189
|
onCloseRef.current?.();
|
|
140
190
|
} else {
|
|
141
191
|
if (__DEV__) {
|
|
142
|
-
console.warn('[usePaywallActions] Restore
|
|
192
|
+
console.warn('[usePaywallActions] Restore did not indicate success, not closing');
|
|
143
193
|
}
|
|
144
194
|
}
|
|
145
195
|
} catch (error) {
|
|
@@ -147,7 +197,7 @@ export function usePaywallActions({
|
|
|
147
197
|
} finally {
|
|
148
198
|
setIsLocalProcessing(false);
|
|
149
199
|
}
|
|
150
|
-
}, []); // Truly stable callback
|
|
200
|
+
}, [refetchStatus, refetchCredits]); // Truly stable callback
|
|
151
201
|
|
|
152
202
|
const resetState = useCallback(() => {
|
|
153
203
|
setSelectedPlanId(null);
|