@umituz/react-native-subscription 2.12.15 โ 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
|
@@ -120,6 +120,8 @@ export {
|
|
|
120
120
|
type SubscriptionDetailTranslations,
|
|
121
121
|
} from "./presentation/screens/SubscriptionDetailScreen";
|
|
122
122
|
|
|
123
|
+
export { type DevTestActions } from "./presentation/screens/components/DevTestSection";
|
|
124
|
+
|
|
123
125
|
|
|
124
126
|
// =============================================================================
|
|
125
127
|
// UTILS - Date & Price
|
|
@@ -247,6 +249,8 @@ export {
|
|
|
247
249
|
type AuthSubscriptionSyncConfig,
|
|
248
250
|
} from "./presentation/hooks/useAuthSubscriptionSync";
|
|
249
251
|
|
|
252
|
+
export { useDevTestCallbacks } from "./presentation/hooks/useDevTestCallbacks";
|
|
253
|
+
|
|
250
254
|
// =============================================================================
|
|
251
255
|
// CREDITS SYSTEM - Utilities
|
|
252
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
|
+
};
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import React from "react";
|
|
8
|
-
import { ScrollView, StyleSheet } from "react-native";
|
|
8
|
+
import { View, ScrollView, StyleSheet } from "react-native";
|
|
9
9
|
import { useAppDesignTokens } from "@umituz/react-native-design-system";
|
|
10
10
|
import { SubscriptionHeader } from "./components/SubscriptionHeader";
|
|
11
11
|
import { CreditsList } from "./components/CreditsList";
|
|
12
12
|
import { SubscriptionActions } from "./components/SubscriptionActions";
|
|
13
|
+
import { DevTestSection, type DevTestActions } from "./components/DevTestSection";
|
|
13
14
|
import type { SubscriptionStatusType } from "../components/details/PremiumStatusBadge";
|
|
14
15
|
import type { CreditInfo } from "../components/details/PremiumDetailsCard";
|
|
15
16
|
|
|
@@ -41,6 +42,10 @@ export interface SubscriptionDetailConfig {
|
|
|
41
42
|
translations: SubscriptionDetailTranslations;
|
|
42
43
|
onManageSubscription?: () => void;
|
|
43
44
|
onUpgrade?: () => void;
|
|
45
|
+
devTools?: {
|
|
46
|
+
actions: DevTestActions;
|
|
47
|
+
title?: string;
|
|
48
|
+
};
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
export interface SubscriptionDetailScreenProps {
|
|
@@ -54,39 +59,48 @@ export const SubscriptionDetailScreen: React.FC<
|
|
|
54
59
|
const showCredits = config.credits && config.credits.length > 0;
|
|
55
60
|
|
|
56
61
|
return (
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
<View style={{ flex: 1 }}>
|
|
63
|
+
<ScrollView
|
|
64
|
+
style={[styles.container, { backgroundColor: tokens.colors.backgroundPrimary }]}
|
|
65
|
+
contentContainerStyle={styles.content}
|
|
66
|
+
>
|
|
67
|
+
<SubscriptionHeader
|
|
68
|
+
statusType={config.statusType}
|
|
69
|
+
isPremium={config.isPremium}
|
|
70
|
+
isLifetime={config.isLifetime}
|
|
71
|
+
expirationDate={config.expirationDate}
|
|
72
|
+
purchaseDate={config.purchaseDate}
|
|
73
|
+
daysRemaining={config.daysRemaining}
|
|
74
|
+
translations={config.translations}
|
|
75
|
+
/>
|
|
76
|
+
|
|
77
|
+
{showCredits && (
|
|
78
|
+
<CreditsList
|
|
79
|
+
credits={config.credits!}
|
|
80
|
+
title={
|
|
81
|
+
config.translations.usageTitle || config.translations.creditsTitle
|
|
82
|
+
}
|
|
83
|
+
description={config.translations.creditsResetInfo}
|
|
84
|
+
remainingLabel={config.translations.remainingLabel}
|
|
85
|
+
/>
|
|
86
|
+
)}
|
|
70
87
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
description={config.translations.creditsResetInfo}
|
|
78
|
-
remainingLabel={config.translations.remainingLabel}
|
|
88
|
+
<SubscriptionActions
|
|
89
|
+
isPremium={config.isPremium}
|
|
90
|
+
manageButtonLabel={config.translations.manageButton}
|
|
91
|
+
upgradeButtonLabel={config.translations.upgradeButton}
|
|
92
|
+
onManage={config.onManageSubscription}
|
|
93
|
+
onUpgrade={config.onUpgrade}
|
|
79
94
|
/>
|
|
80
|
-
|
|
95
|
+
</ScrollView>
|
|
81
96
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
</ScrollView>
|
|
97
|
+
{config.devTools && (
|
|
98
|
+
<DevTestSection
|
|
99
|
+
actions={config.devTools.actions}
|
|
100
|
+
title={config.devTools.title}
|
|
101
|
+
/>
|
|
102
|
+
)}
|
|
103
|
+
</View>
|
|
90
104
|
);
|
|
91
105
|
};
|
|
92
106
|
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev Test Section
|
|
3
|
+
* Developer testing tools for subscription renewals
|
|
4
|
+
* Only visible in __DEV__ mode
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { View, TouchableOpacity, StyleSheet } from "react-native";
|
|
9
|
+
import { AtomicText, useAppDesignTokens } from "@umituz/react-native-design-system";
|
|
10
|
+
|
|
11
|
+
export interface DevTestActions {
|
|
12
|
+
onTestRenewal: () => Promise<void>;
|
|
13
|
+
onCheckCredits: () => void;
|
|
14
|
+
onTestDuplicate: () => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface DevTestSectionProps {
|
|
18
|
+
actions: DevTestActions;
|
|
19
|
+
title?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const DevTestSection: React.FC<DevTestSectionProps> = ({
|
|
23
|
+
actions,
|
|
24
|
+
title = "๐งช Developer Testing",
|
|
25
|
+
}) => {
|
|
26
|
+
const tokens = useAppDesignTokens();
|
|
27
|
+
|
|
28
|
+
if (!__DEV__) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<View
|
|
34
|
+
style={[
|
|
35
|
+
styles.container,
|
|
36
|
+
{
|
|
37
|
+
backgroundColor: tokens.colors.surfaceSecondary,
|
|
38
|
+
borderTopColor: tokens.colors.border,
|
|
39
|
+
},
|
|
40
|
+
]}
|
|
41
|
+
>
|
|
42
|
+
<AtomicText
|
|
43
|
+
type="titleMedium"
|
|
44
|
+
style={[styles.title, { color: tokens.colors.textPrimary }]}
|
|
45
|
+
>
|
|
46
|
+
{title}
|
|
47
|
+
</AtomicText>
|
|
48
|
+
|
|
49
|
+
<TouchableOpacity
|
|
50
|
+
style={[styles.button, { backgroundColor: tokens.colors.primary }]}
|
|
51
|
+
onPress={actions.onTestRenewal}
|
|
52
|
+
>
|
|
53
|
+
<AtomicText
|
|
54
|
+
type="bodyMedium"
|
|
55
|
+
style={[styles.buttonText, { color: tokens.colors.onPrimary }]}
|
|
56
|
+
>
|
|
57
|
+
โก Test Auto-Renewal (Add Credits)
|
|
58
|
+
</AtomicText>
|
|
59
|
+
</TouchableOpacity>
|
|
60
|
+
|
|
61
|
+
<TouchableOpacity
|
|
62
|
+
style={[
|
|
63
|
+
styles.button,
|
|
64
|
+
{
|
|
65
|
+
backgroundColor: tokens.colors.surfaceSecondary,
|
|
66
|
+
borderWidth: 1,
|
|
67
|
+
borderColor: tokens.colors.border,
|
|
68
|
+
},
|
|
69
|
+
]}
|
|
70
|
+
onPress={actions.onCheckCredits}
|
|
71
|
+
>
|
|
72
|
+
<AtomicText
|
|
73
|
+
type="bodyMedium"
|
|
74
|
+
style={[styles.buttonText, { color: tokens.colors.textPrimary }]}
|
|
75
|
+
>
|
|
76
|
+
๐ Check Current Credits
|
|
77
|
+
</AtomicText>
|
|
78
|
+
</TouchableOpacity>
|
|
79
|
+
|
|
80
|
+
<TouchableOpacity
|
|
81
|
+
style={[
|
|
82
|
+
styles.button,
|
|
83
|
+
{
|
|
84
|
+
backgroundColor: tokens.colors.surfaceSecondary,
|
|
85
|
+
borderWidth: 1,
|
|
86
|
+
borderColor: tokens.colors.border,
|
|
87
|
+
},
|
|
88
|
+
]}
|
|
89
|
+
onPress={actions.onTestDuplicate}
|
|
90
|
+
>
|
|
91
|
+
<AtomicText
|
|
92
|
+
type="bodyMedium"
|
|
93
|
+
style={[styles.buttonText, { color: tokens.colors.textPrimary }]}
|
|
94
|
+
>
|
|
95
|
+
๐ Test Duplicate Protection
|
|
96
|
+
</AtomicText>
|
|
97
|
+
</TouchableOpacity>
|
|
98
|
+
</View>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const styles = StyleSheet.create({
|
|
103
|
+
container: {
|
|
104
|
+
padding: 16,
|
|
105
|
+
gap: 12,
|
|
106
|
+
borderTopWidth: 1,
|
|
107
|
+
},
|
|
108
|
+
title: {
|
|
109
|
+
fontWeight: "600",
|
|
110
|
+
marginBottom: 4,
|
|
111
|
+
},
|
|
112
|
+
button: {
|
|
113
|
+
paddingVertical: 12,
|
|
114
|
+
paddingHorizontal: 16,
|
|
115
|
+
borderRadius: 8,
|
|
116
|
+
alignItems: "center",
|
|
117
|
+
},
|
|
118
|
+
buttonText: {
|
|
119
|
+
fontWeight: "500",
|
|
120
|
+
},
|
|
121
|
+
});
|