@umituz/react-native-subscription 2.19.3 → 2.19.5
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.19.
|
|
3
|
+
"version": "2.19.5",
|
|
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,7 @@ import { useCallback } from "react";
|
|
|
2
2
|
import type { PurchasesPackage } from "react-native-purchases";
|
|
3
3
|
import { useRestorePurchase } from "../../../revenuecat/presentation/hooks/useRestorePurchase";
|
|
4
4
|
import { useAuthAwarePurchase } from "../../../presentation/hooks/useAuthAwarePurchase";
|
|
5
|
+
import { usePendingPurchaseStore } from "../../../infrastructure/stores/PendingPurchaseStore";
|
|
5
6
|
import type { PurchaseSource } from "../../../domain/entities/Credits";
|
|
6
7
|
|
|
7
8
|
declare const __DEV__: boolean;
|
|
@@ -25,8 +26,15 @@ export const usePaywallActions = ({
|
|
|
25
26
|
}: UsePaywallActionsProps) => {
|
|
26
27
|
const { handlePurchase: authAwarePurchase } = useAuthAwarePurchase({ source, userId });
|
|
27
28
|
const { mutateAsync: restorePurchases } = useRestorePurchase(userId);
|
|
29
|
+
const { isExecuting } = usePendingPurchaseStore();
|
|
28
30
|
|
|
29
31
|
const handlePurchase = useCallback(async (pkg: PurchasesPackage) => {
|
|
32
|
+
// Block if a pending purchase is already being executed
|
|
33
|
+
if (isExecuting) {
|
|
34
|
+
if (__DEV__) console.log("[PaywallActions] Purchase blocked - pending purchase in progress");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
try {
|
|
31
39
|
if (__DEV__) console.log("[PaywallActions] Purchase started:", pkg.product.identifier);
|
|
32
40
|
const res = await authAwarePurchase(pkg, source);
|
|
@@ -38,7 +46,7 @@ export const usePaywallActions = ({
|
|
|
38
46
|
const message = err instanceof Error ? err.message : String(err);
|
|
39
47
|
onPurchaseError?.(message);
|
|
40
48
|
}
|
|
41
|
-
}, [authAwarePurchase, source, onClose, onPurchaseSuccess, onPurchaseError]);
|
|
49
|
+
}, [authAwarePurchase, source, onClose, onPurchaseSuccess, onPurchaseError, isExecuting]);
|
|
42
50
|
|
|
43
51
|
const handleRestore = useCallback(async () => {
|
|
44
52
|
try {
|
|
@@ -113,22 +113,35 @@ export async function initializeCreditsTransaction(
|
|
|
113
113
|
? [...(existing?.purchaseHistory || []), purchaseMetadata].slice(-10)
|
|
114
114
|
: existing?.purchaseHistory;
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
// Build credits data, excluding undefined values (Firestore doesn't accept undefined)
|
|
117
|
+
const creditsData: Record<string, unknown> = {
|
|
117
118
|
credits: newCredits,
|
|
118
|
-
packageType: packageType !== "unknown" ? packageType : undefined,
|
|
119
119
|
creditLimit,
|
|
120
|
-
productId: productId || undefined,
|
|
121
|
-
purchaseSource: metadata?.source,
|
|
122
|
-
purchaseType: metadata?.type ? purchaseType : undefined,
|
|
123
|
-
platform: productId ? platform : undefined,
|
|
124
|
-
appVersion: productId ? appVersion : undefined,
|
|
125
120
|
purchasedAt,
|
|
126
121
|
lastUpdatedAt: now,
|
|
127
122
|
lastPurchaseAt: now,
|
|
128
123
|
processedPurchases,
|
|
129
|
-
purchaseHistory,
|
|
130
124
|
};
|
|
131
125
|
|
|
126
|
+
// Only add optional fields if they have values
|
|
127
|
+
if (packageType && packageType !== "unknown") {
|
|
128
|
+
creditsData.packageType = packageType;
|
|
129
|
+
}
|
|
130
|
+
if (productId) {
|
|
131
|
+
creditsData.productId = productId;
|
|
132
|
+
creditsData.platform = platform;
|
|
133
|
+
creditsData.appVersion = appVersion;
|
|
134
|
+
}
|
|
135
|
+
if (metadata?.source) {
|
|
136
|
+
creditsData.purchaseSource = metadata.source;
|
|
137
|
+
}
|
|
138
|
+
if (metadata?.type) {
|
|
139
|
+
creditsData.purchaseType = purchaseType;
|
|
140
|
+
}
|
|
141
|
+
if (purchaseHistory && purchaseHistory.length > 0) {
|
|
142
|
+
creditsData.purchaseHistory = purchaseHistory;
|
|
143
|
+
}
|
|
144
|
+
|
|
132
145
|
transaction.set(creditsRef, creditsData, { merge: true });
|
|
133
146
|
|
|
134
147
|
return { credits: newCredits };
|
|
@@ -16,6 +16,7 @@ export interface PendingPurchaseData {
|
|
|
16
16
|
|
|
17
17
|
interface PendingPurchaseState {
|
|
18
18
|
pending: PendingPurchaseData | null;
|
|
19
|
+
isExecuting: boolean;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
interface PendingPurchaseActions {
|
|
@@ -23,10 +24,12 @@ interface PendingPurchaseActions {
|
|
|
23
24
|
getPendingPurchase: () => PendingPurchaseData | null;
|
|
24
25
|
clearPendingPurchase: () => void;
|
|
25
26
|
hasPendingPurchase: () => boolean;
|
|
27
|
+
setExecuting: (executing: boolean) => void;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
const initialState: PendingPurchaseState = {
|
|
29
31
|
pending: null,
|
|
32
|
+
isExecuting: false,
|
|
30
33
|
};
|
|
31
34
|
|
|
32
35
|
export const usePendingPurchaseStore = createStore<
|
|
@@ -52,5 +55,9 @@ export const usePendingPurchaseStore = createStore<
|
|
|
52
55
|
hasPendingPurchase: () => {
|
|
53
56
|
return get().pending !== null;
|
|
54
57
|
},
|
|
58
|
+
|
|
59
|
+
setExecuting: (executing: boolean) => {
|
|
60
|
+
set({ isExecuting: executing });
|
|
61
|
+
},
|
|
55
62
|
}),
|
|
56
63
|
});
|
|
@@ -22,7 +22,7 @@ export const usePendingPurchaseHandler = ({
|
|
|
22
22
|
userId,
|
|
23
23
|
isAuthenticated,
|
|
24
24
|
}: UsePendingPurchaseHandlerParams): void => {
|
|
25
|
-
const { pending, clearPendingPurchase } = usePendingPurchaseStore();
|
|
25
|
+
const { pending, clearPendingPurchase, setExecuting } = usePendingPurchaseStore();
|
|
26
26
|
const { purchasePackage } = usePremium(userId);
|
|
27
27
|
const isExecutingRef = useRef(false);
|
|
28
28
|
const executedPackageIdRef = useRef<string | null>(null);
|
|
@@ -45,6 +45,7 @@ export const usePendingPurchaseHandler = ({
|
|
|
45
45
|
const executePendingPurchase = async () => {
|
|
46
46
|
isExecutingRef.current = true;
|
|
47
47
|
executedPackageIdRef.current = pending.package.identifier;
|
|
48
|
+
setExecuting(true);
|
|
48
49
|
|
|
49
50
|
if (__DEV__) {
|
|
50
51
|
console.log(
|
|
@@ -69,9 +70,10 @@ export const usePendingPurchaseHandler = ({
|
|
|
69
70
|
} finally {
|
|
70
71
|
clearPendingPurchase();
|
|
71
72
|
isExecutingRef.current = false;
|
|
73
|
+
setExecuting(false);
|
|
72
74
|
}
|
|
73
75
|
};
|
|
74
76
|
|
|
75
77
|
void executePendingPurchase();
|
|
76
|
-
}, [isAuthenticated, userId, pending, clearPendingPurchase, purchasePackage]);
|
|
78
|
+
}, [isAuthenticated, userId, pending, clearPendingPurchase, purchasePackage, setExecuting]);
|
|
77
79
|
};
|