@umituz/react-native-subscription 2.12.16 โ 2.12.17
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.12.
|
|
3
|
+
"version": "2.12.17",
|
|
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",
|
package/src/index.ts
CHANGED
|
@@ -249,6 +249,8 @@ export {
|
|
|
249
249
|
type AuthSubscriptionSyncConfig,
|
|
250
250
|
} from "./presentation/hooks/useAuthSubscriptionSync";
|
|
251
251
|
|
|
252
|
+
export { useDevTestCallbacks } from "./presentation/hooks/useDevTestCallbacks";
|
|
253
|
+
|
|
252
254
|
// =============================================================================
|
|
253
255
|
// CREDITS SYSTEM - Utilities
|
|
254
256
|
// =============================================================================
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev Test Callbacks Hook
|
|
3
|
+
* Provides test functions for subscription renewal testing
|
|
4
|
+
* Only used in __DEV__ mode
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { useCallback } from "react";
|
|
8
|
+
import { Alert } from "react-native";
|
|
9
|
+
import { useAuth } from "@umituz/react-native-auth";
|
|
10
|
+
import { getCreditsRepository } from "../../infrastructure/repositories/CreditsRepositoryProvider";
|
|
11
|
+
import { useCredits } from "./useCredits";
|
|
12
|
+
import type { DevTestActions } from "../screens/components/DevTestSection";
|
|
13
|
+
|
|
14
|
+
export const useDevTestCallbacks = (): DevTestActions | undefined => {
|
|
15
|
+
const { user } = useAuth();
|
|
16
|
+
const { credits, refetch } = useCredits({ userId: user?.uid });
|
|
17
|
+
|
|
18
|
+
const onTestRenewal = useCallback(async () => {
|
|
19
|
+
if (!user?.uid) {
|
|
20
|
+
Alert.alert("Error", "No user logged in");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const repository = getCreditsRepository();
|
|
26
|
+
const renewalId = `dev_renewal_${Date.now()}`;
|
|
27
|
+
const productId = "test_yearly_subscription";
|
|
28
|
+
|
|
29
|
+
if (__DEV__) {
|
|
30
|
+
console.log("๐งช [Dev Test] Simulating auto-renewal...", {
|
|
31
|
+
userId: user.uid,
|
|
32
|
+
renewalId,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const result = await repository.initializeCredits(
|
|
37
|
+
user.uid,
|
|
38
|
+
renewalId,
|
|
39
|
+
productId,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (__DEV__) {
|
|
43
|
+
console.log("โ
[Dev Test] Renewal completed:", {
|
|
44
|
+
success: result.success,
|
|
45
|
+
textCredits: result.data?.textCredits,
|
|
46
|
+
imageCredits: result.data?.imageCredits,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
await refetch();
|
|
51
|
+
|
|
52
|
+
Alert.alert(
|
|
53
|
+
"โ
Test Renewal Success",
|
|
54
|
+
`Credits Updated!\n\nText: ${result.data?.textCredits || 0}\nImage: ${result.data?.imageCredits || 0}\n\n(ACCUMULATE mode - credits added to existing)`,
|
|
55
|
+
[{ text: "OK" }],
|
|
56
|
+
);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (__DEV__) {
|
|
59
|
+
console.error("โ [Dev Test] Renewal failed:", error);
|
|
60
|
+
}
|
|
61
|
+
Alert.alert(
|
|
62
|
+
"Test Failed",
|
|
63
|
+
error instanceof Error ? error.message : "Unknown error",
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}, [user?.uid, refetch]);
|
|
67
|
+
|
|
68
|
+
const onCheckCredits = useCallback(() => {
|
|
69
|
+
if (!credits) {
|
|
70
|
+
Alert.alert("Credits", "No credits data available");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
Alert.alert(
|
|
75
|
+
"๐ Current Credits",
|
|
76
|
+
`Text Generation: ${credits.textCredits}\nImage Generation: ${credits.imageCredits}\n\nPurchased: ${credits.purchasedAt?.toLocaleDateString() || "N/A"}`,
|
|
77
|
+
[{ text: "OK" }],
|
|
78
|
+
);
|
|
79
|
+
}, [credits]);
|
|
80
|
+
|
|
81
|
+
const onTestDuplicate = useCallback(async () => {
|
|
82
|
+
if (!user?.uid) {
|
|
83
|
+
Alert.alert("Error", "No user logged in");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const repository = getCreditsRepository();
|
|
89
|
+
const sameRenewalId = "dev_duplicate_test_12345";
|
|
90
|
+
|
|
91
|
+
if (__DEV__) {
|
|
92
|
+
console.log("๐งช [Dev Test] Testing duplicate protection...");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const result1 = await repository.initializeCredits(
|
|
96
|
+
user.uid,
|
|
97
|
+
sameRenewalId,
|
|
98
|
+
"test_product",
|
|
99
|
+
);
|
|
100
|
+
if (__DEV__) {
|
|
101
|
+
console.log("First call:", result1.data);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const result2 = await repository.initializeCredits(
|
|
105
|
+
user.uid,
|
|
106
|
+
sameRenewalId,
|
|
107
|
+
"test_product",
|
|
108
|
+
);
|
|
109
|
+
if (__DEV__) {
|
|
110
|
+
console.log("Second call:", result2.data);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
await refetch();
|
|
114
|
+
|
|
115
|
+
const duplicateProtectionWorks =
|
|
116
|
+
result2.data?.textCredits === result1.data?.textCredits;
|
|
117
|
+
|
|
118
|
+
Alert.alert(
|
|
119
|
+
"Duplicate Test",
|
|
120
|
+
`First call: ${result1.success ? "โ
Added credits" : "โ Failed"}\n\nSecond call: ${duplicateProtectionWorks ? "โ
Skipped (protection works!)" : "โ Added again (protection failed!)"}`,
|
|
121
|
+
[{ text: "OK" }],
|
|
122
|
+
);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (__DEV__) {
|
|
125
|
+
console.error("โ [Dev Test] Duplicate test failed:", error);
|
|
126
|
+
}
|
|
127
|
+
Alert.alert(
|
|
128
|
+
"Test Failed",
|
|
129
|
+
error instanceof Error ? error.message : "Unknown error",
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}, [user?.uid, refetch]);
|
|
133
|
+
|
|
134
|
+
if (!__DEV__) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
onTestRenewal,
|
|
140
|
+
onCheckCredits,
|
|
141
|
+
onTestDuplicate,
|
|
142
|
+
};
|
|
143
|
+
};
|