@umituz/react-native-subscription 2.14.98 → 2.14.100
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/README.md +211 -395
- package/package.json +1 -1
- package/src/application/README.md +46 -225
- package/src/application/ports/README.md +42 -97
- package/src/domain/README.md +36 -384
- package/src/domain/constants/README.md +0 -56
- package/src/domain/entities/README.md +43 -169
- package/src/domain/errors/README.md +33 -287
- package/src/domain/value-objects/README.md +43 -179
- package/src/domains/README.md +52 -0
- package/src/domains/README.md.bak +274 -0
- package/src/domains/config/README.md +93 -383
- package/src/domains/config/domain/README.md +37 -0
- package/src/domains/config/domain/entities/README.md +41 -0
- package/src/domains/paywall/README.md +99 -369
- package/src/domains/paywall/components/README.md +34 -178
- package/src/domains/paywall/entities/README.md +34 -193
- package/src/domains/paywall/hooks/README.md +34 -122
- package/src/domains/wallet/README.md +34 -275
- package/src/domains/wallet/README.md.bak +209 -0
- package/src/domains/wallet/domain/README.md +34 -101
- package/src/domains/wallet/domain/entities/README.md +34 -115
- package/src/domains/wallet/domain/errors/README.md +34 -151
- package/src/domains/wallet/infrastructure/README.md +34 -89
- package/src/domains/wallet/presentation/components/README.md +34 -224
- package/src/domains/wallet/presentation/hooks/README.md +34 -248
- package/src/infrastructure/README.md +37 -496
- package/src/infrastructure/mappers/README.md +0 -13
- package/src/infrastructure/repositories/README.md +74 -360
- package/src/infrastructure/services/README.md +95 -370
- package/src/presentation/README.md +123 -408
- package/src/presentation/README.md.bak +172 -0
- package/src/presentation/components/README.md +151 -179
- package/src/presentation/components/README.md.bak +217 -0
- package/src/presentation/components/details/CreditRow.md +65 -310
- package/src/presentation/components/details/DetailRow.md +63 -255
- package/src/presentation/components/details/PremiumDetailsCard.md +65 -238
- package/src/presentation/components/details/PremiumStatusBadge.md +64 -239
- package/src/presentation/components/details/README.md +97 -447
- package/src/presentation/components/feedback/PaywallFeedbackModal.md +63 -287
- package/src/presentation/components/feedback/README.md +97 -445
- package/src/presentation/components/paywall/PaywallModal.md +66 -416
- package/src/presentation/components/paywall/README.md +50 -186
- package/src/presentation/components/sections/README.md +97 -466
- package/src/presentation/components/sections/SubscriptionSection.md +92 -244
- package/src/presentation/hooks/README.md +154 -741
- package/src/presentation/hooks/useAuthAwarePurchase.md +58 -325
- package/src/presentation/hooks/useAuthGate.md +61 -375
- package/src/presentation/hooks/useAuthSubscriptionSync.md +66 -370
- package/src/presentation/hooks/useCreditChecker.md +73 -378
- package/src/presentation/hooks/useCredits.md +74 -313
- package/src/presentation/hooks/useCredits.md.bak +231 -0
- package/src/presentation/hooks/useCreditsGate.md +66 -318
- package/src/presentation/hooks/useDeductCredit.md +96 -156
- package/src/presentation/hooks/useDevTestCallbacks.md +63 -394
- package/src/presentation/hooks/useFeatureGate.md +105 -150
- package/src/presentation/hooks/useFeatureGate.md.bak +284 -0
- package/src/presentation/hooks/useInitializeCredits.md +64 -430
- package/src/presentation/hooks/usePaywall.md +61 -306
- package/src/presentation/hooks/usePaywallOperations.md +64 -458
- package/src/presentation/hooks/usePaywallVisibility.md +67 -316
- package/src/presentation/hooks/usePremium.md +84 -226
- package/src/presentation/hooks/usePremiumGate.md +60 -395
- package/src/presentation/hooks/usePremiumWithCredits.md +64 -401
- package/src/presentation/hooks/useSubscription.md +66 -422
- package/src/presentation/hooks/useSubscriptionDetails.md +65 -410
- package/src/presentation/hooks/useSubscriptionGate.md +80 -164
- package/src/presentation/hooks/useSubscriptionSettingsConfig.md +66 -346
- package/src/presentation/hooks/useSubscriptionStatus.md +66 -396
- package/src/presentation/hooks/useUserTier.md +63 -328
- package/src/presentation/hooks/useUserTierWithRepository.md +64 -424
- package/src/presentation/screens/README.md +48 -190
- package/src/presentation/types/README.md +0 -16
- package/src/presentation/utils/README.md +0 -21
- package/src/revenuecat/README.md +99 -518
- package/src/revenuecat/application/README.md +43 -0
- package/src/revenuecat/application/ports/README.md +41 -0
- package/src/revenuecat/domain/README.md +42 -141
- package/src/revenuecat/domain/constants/README.md +41 -0
- package/src/revenuecat/domain/entities/README.md +42 -0
- package/src/revenuecat/domain/errors/README.md +47 -191
- package/src/revenuecat/domain/types/README.md +41 -0
- package/src/revenuecat/domain/value-objects/README.md +41 -0
- package/src/revenuecat/infrastructure/README.md +41 -0
- package/src/revenuecat/infrastructure/config/README.md +32 -23
- package/src/revenuecat/infrastructure/handlers/README.md +41 -0
- package/src/revenuecat/infrastructure/managers/README.md +34 -42
- package/src/revenuecat/infrastructure/services/README.md +42 -0
- package/src/revenuecat/infrastructure/utils/README.md +41 -0
- package/src/revenuecat/presentation/README.md +42 -0
- package/src/revenuecat/presentation/hooks/README.md +29 -35
- package/src/utils/README.md +38 -525
package/README.md
CHANGED
|
@@ -2,461 +2,277 @@
|
|
|
2
2
|
|
|
3
3
|
Complete subscription management with RevenueCat, paywall UI, and credits system for React Native apps.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
- 🚀 **RevenueCat Integration** - Full RevenueCat SDK integration with auto-initialization
|
|
8
|
-
- 💳 **Subscription Management** - Handle monthly, annual, and lifetime subscriptions
|
|
9
|
-
- 💰 **Credits System** - Built-in credits system with transaction tracking
|
|
10
|
-
- 🎨 **Paywall Components** - Beautiful, customizable paywall UI components
|
|
11
|
-
- 🔐 **Gate System** - Premium, auth, and credit gates for feature access control
|
|
12
|
-
- 🌍 **Multi-language Support** - Built-in i18n support
|
|
13
|
-
- 📊 **Analytics Ready** - Track subscription events and user behavior
|
|
14
|
-
- 🏗️ **DDD Architecture** - Domain-driven design with clean architecture
|
|
15
|
-
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
npm install @umituz/react-native-subscription
|
|
20
|
-
# or
|
|
21
|
-
yarn add @umituz/react-native-subscription
|
|
22
|
-
```
|
|
5
|
+
## Package Overview
|
|
23
6
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
```json
|
|
27
|
-
{
|
|
28
|
-
"@tanstack/react-query": ">=5.0.0",
|
|
29
|
-
"expo-constants": ">=16.0.0",
|
|
30
|
-
"expo-image": ">=2.0.0",
|
|
31
|
-
"expo-linear-gradient": ">=14.0.0",
|
|
32
|
-
"firebase": ">=10.0.0",
|
|
33
|
-
"react": ">=18.2.0",
|
|
34
|
-
"react-native": ">=0.74.0",
|
|
35
|
-
"react-native-purchases": ">=7.0.0",
|
|
36
|
-
"react-native-safe-area-context": ">=5.0.0"
|
|
37
|
-
}
|
|
38
|
-
```
|
|
7
|
+
**Import Path**: `@umituz/react-native-subscription`
|
|
39
8
|
|
|
40
|
-
|
|
9
|
+
**Version**: Latest
|
|
41
10
|
|
|
42
|
-
|
|
11
|
+
**Type**: React Native Package
|
|
43
12
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
<SubscriptionProvider
|
|
51
|
-
config={{
|
|
52
|
-
revenueCatApiKey: 'your_api_key',
|
|
53
|
-
revenueCatEntitlementId: 'premium',
|
|
54
|
-
}}
|
|
55
|
-
>
|
|
56
|
-
<YourApp />
|
|
57
|
-
</SubscriptionProvider>
|
|
58
|
-
);
|
|
59
|
-
}
|
|
13
|
+
This package provides comprehensive subscription and credit management with:
|
|
14
|
+
- RevenueCat integration for subscriptions
|
|
15
|
+
- Credits system with transaction tracking
|
|
16
|
+
- Paywall UI components
|
|
17
|
+
- Feature gating (premium, auth, credits)
|
|
18
|
+
- DDD architecture with clean layers
|
|
60
19
|
|
|
61
|
-
|
|
62
|
-
await initializeSubscription({
|
|
63
|
-
revenueCatApiKey: process.env.REVENUECAT_API_KEY,
|
|
64
|
-
revenueCatEntitlementId: 'premium',
|
|
65
|
-
});
|
|
66
|
-
```
|
|
20
|
+
## Strategy
|
|
67
21
|
|
|
68
|
-
###
|
|
22
|
+
### Architecture Principles
|
|
69
23
|
|
|
70
|
-
|
|
71
|
-
|
|
24
|
+
1. **Domain-Driven Design (DDD)**
|
|
25
|
+
- Separate domains: Wallet, Paywall, Config
|
|
26
|
+
- Each domain has its own entities, rules, and boundaries
|
|
27
|
+
- Business logic stays in domain layer
|
|
72
28
|
|
|
73
|
-
|
|
74
|
-
|
|
29
|
+
2. **Clean Architecture**
|
|
30
|
+
- Presentation: React hooks and components
|
|
31
|
+
- Application: Use cases and orchestration
|
|
32
|
+
- Domain: Entities and business rules
|
|
33
|
+
- Infrastructure: External integrations
|
|
75
34
|
|
|
76
|
-
|
|
35
|
+
3. **Separation of Concerns**
|
|
36
|
+
- UI components are pure and reusable
|
|
37
|
+
- Business logic is in hooks and services
|
|
38
|
+
- Data persistence is abstracted behind repositories
|
|
77
39
|
|
|
78
|
-
|
|
79
|
-
return <UpgradePrompt />;
|
|
80
|
-
}
|
|
40
|
+
### Integration Flow
|
|
81
41
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
42
|
+
1. **Initialization**
|
|
43
|
+
- Configure RevenueCat with API key
|
|
44
|
+
- Set up Firebase for credits storage
|
|
45
|
+
- Initialize providers at app root
|
|
85
46
|
|
|
86
|
-
|
|
47
|
+
2. **Subscription Management**
|
|
48
|
+
- Check user tier and subscription status
|
|
49
|
+
- Gate premium features
|
|
50
|
+
- Handle purchase flows
|
|
87
51
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
<>
|
|
96
|
-
<Button onPress={() => setIsVisible(true)} title="Upgrade" />
|
|
97
|
-
|
|
98
|
-
<PaywallModal
|
|
99
|
-
isVisible={isVisible}
|
|
100
|
-
onClose={() => setIsVisible(false)}
|
|
101
|
-
config={{
|
|
102
|
-
title: 'Unlock Premium',
|
|
103
|
-
description: 'Get unlimited access',
|
|
104
|
-
features: [
|
|
105
|
-
{ icon: 'star', text: 'Unlimited credits' },
|
|
106
|
-
{ icon: 'zap', text: 'AI-powered tools' },
|
|
107
|
-
],
|
|
108
|
-
}}
|
|
109
|
-
/>
|
|
110
|
-
</>
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
```
|
|
52
|
+
3. **Credits System**
|
|
53
|
+
- Initialize credits on purchase
|
|
54
|
+
- Deduct credits for feature usage
|
|
55
|
+
- Track all transactions
|
|
56
|
+
- Handle credit exhaustion
|
|
114
57
|
|
|
115
|
-
|
|
58
|
+
4. **Paywall Display**
|
|
59
|
+
- Show paywall on feature gates
|
|
60
|
+
- Handle purchase operations
|
|
61
|
+
- Manage paywall visibility state
|
|
116
62
|
|
|
117
|
-
|
|
118
|
-
import { useCreditsGate } from '@umituz/react-native-subscription';
|
|
119
|
-
|
|
120
|
-
function FeatureWithCredits() {
|
|
121
|
-
const { hasCredits, consumeCredit } = useCreditsGate({
|
|
122
|
-
creditCost: 5,
|
|
123
|
-
featureId: 'ai_generation',
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
const handleAction = async () => {
|
|
127
|
-
if (!hasCredits) {
|
|
128
|
-
showPaywall();
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const result = await consumeCredit();
|
|
133
|
-
if (result.success) {
|
|
134
|
-
await performAction();
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
return <Button onPress={handleAction} title="Use Feature (5 credits)" />;
|
|
139
|
-
}
|
|
140
|
-
```
|
|
63
|
+
### Key Dependencies
|
|
141
64
|
|
|
142
|
-
|
|
65
|
+
- **RevenueCat**: `react-native-purchases` >= 7.0.0
|
|
66
|
+
- **Firebase**: `firebase` >= 10.0.0
|
|
67
|
+
- **State Management**: `@tanstack/react-query` >= 5.0.0
|
|
68
|
+
- **React Native**: `react-native` >= 0.74.0
|
|
143
69
|
|
|
144
|
-
|
|
70
|
+
## Restrictions
|
|
145
71
|
|
|
146
|
-
|
|
72
|
+
### REQUIRED
|
|
147
73
|
|
|
148
|
-
- **
|
|
149
|
-
- **
|
|
150
|
-
- **
|
|
74
|
+
- **RevenueCat Configuration**: MUST provide valid API key and entitlement ID
|
|
75
|
+
- **Firebase Setup**: MUST initialize Firebase for credits system
|
|
76
|
+
- **Provider Setup**: MUST wrap app with `SubscriptionProvider`
|
|
77
|
+
- **Authentication**: MUST have authenticated user for credits operations
|
|
78
|
+
- **Error Handling**: MUST handle all error states appropriately
|
|
151
79
|
|
|
152
|
-
###
|
|
80
|
+
### PROHIBITED
|
|
153
81
|
|
|
154
|
-
- **
|
|
155
|
-
- **
|
|
156
|
-
- **
|
|
157
|
-
- **
|
|
82
|
+
- **NEVER** use subscription hooks outside provider
|
|
83
|
+
- **NEVER** deduce credits without checking balance first
|
|
84
|
+
- **NEVER** gate features without proper user feedback
|
|
85
|
+
- **DO NOT** bypass gate hooks for premium features
|
|
86
|
+
- **DO NOT** initialize RevenueCat multiple times
|
|
158
87
|
|
|
159
|
-
###
|
|
88
|
+
### CRITICAL SAFETY
|
|
160
89
|
|
|
161
|
-
- **
|
|
162
|
-
- **
|
|
163
|
-
- **
|
|
164
|
-
- **
|
|
90
|
+
- **ALWAYS** check loading states before rendering
|
|
91
|
+
- **ALWAYS** handle edge cases (no subscription, expired, etc)
|
|
92
|
+
- **ALWAYS** validate return values from credit operations
|
|
93
|
+
- **NEVER** assume user has premium or credits
|
|
94
|
+
- **MUST** implement proper error boundaries
|
|
165
95
|
|
|
166
|
-
##
|
|
96
|
+
## Rules
|
|
167
97
|
|
|
168
|
-
###
|
|
98
|
+
### Provider Setup
|
|
169
99
|
|
|
170
100
|
```typescript
|
|
171
|
-
//
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
//
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
// Paywall
|
|
187
|
-
import {
|
|
188
|
-
usePaywall,
|
|
189
|
-
usePaywallActions,
|
|
190
|
-
usePaywallVisibility,
|
|
191
|
-
} from '@umituz/react-native-subscription';
|
|
192
|
-
|
|
193
|
-
// User Tier
|
|
194
|
-
import {
|
|
195
|
-
useUserTier,
|
|
196
|
-
useAuthGate,
|
|
197
|
-
useFeatureGate,
|
|
198
|
-
} from '@umituz/react-native-subscription';
|
|
101
|
+
// CORRECT - Wrap app with provider
|
|
102
|
+
<SubscriptionProvider config={{ revenueCatApiKey: 'xxx' }}>
|
|
103
|
+
<App />
|
|
104
|
+
</SubscriptionProvider>
|
|
105
|
+
|
|
106
|
+
// INCORRECT - No provider
|
|
107
|
+
<App /> // Hooks will fail
|
|
108
|
+
|
|
109
|
+
// INCORRECT - Multiple providers
|
|
110
|
+
<SubscriptionProvider>
|
|
111
|
+
<SubscriptionProvider> // Duplicate
|
|
112
|
+
<App />
|
|
113
|
+
</SubscriptionProvider>
|
|
114
|
+
</SubscriptionProvider>
|
|
199
115
|
```
|
|
200
116
|
|
|
201
|
-
###
|
|
117
|
+
### Feature Gating
|
|
202
118
|
|
|
203
119
|
```typescript
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
// Paywall components
|
|
212
|
-
PaywallModal,
|
|
213
|
-
PaywallScreen,
|
|
214
|
-
SubscriptionSection,
|
|
215
|
-
|
|
216
|
-
// Feedback
|
|
217
|
-
PaywallFeedbackModal,
|
|
218
|
-
} from '@umituz/react-native-subscription';
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
### Services
|
|
120
|
+
// CORRECT - Use gate hooks
|
|
121
|
+
const { canAccess, showPaywall } = usePremiumGate();
|
|
122
|
+
if (!canAccess) {
|
|
123
|
+
showPaywall();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
222
126
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
SubscriptionService,
|
|
228
|
-
|
|
229
|
-
// Credits
|
|
230
|
-
configureCreditsRepository,
|
|
231
|
-
getCreditsRepository,
|
|
232
|
-
|
|
233
|
-
// RevenueCat
|
|
234
|
-
useRevenueCat,
|
|
235
|
-
useCustomerInfo,
|
|
236
|
-
useRestorePurchase,
|
|
237
|
-
} from '@umituz/react-native-subscription';
|
|
127
|
+
// INCORRECT - Manual check
|
|
128
|
+
if (!user.isPremium) { // No feedback, no paywall
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
238
131
|
```
|
|
239
132
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
### Complete Premium Feature Example
|
|
133
|
+
### Credit Operations
|
|
243
134
|
|
|
244
135
|
```typescript
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
useCreditsGate,
|
|
250
|
-
useUserTier,
|
|
251
|
-
PaywallModal,
|
|
252
|
-
} from '@umituz/react-native-subscription';
|
|
253
|
-
|
|
254
|
-
function PremiumFeature() {
|
|
255
|
-
const { tier, isPremium } = useUserTier();
|
|
256
|
-
const { canAccess, showPaywall } = usePremiumGate({
|
|
257
|
-
featureId: 'ai_tools',
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
const { hasCredits, credits, consumeCredit } = useCreditsGate({
|
|
261
|
-
creditCost: 5,
|
|
262
|
-
featureId: 'ai_generation',
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
const handleGenerate = async () => {
|
|
266
|
-
if (!canAccess) {
|
|
267
|
-
showPaywall();
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if (isPremium) {
|
|
272
|
-
// Premium: unlimited access
|
|
273
|
-
await generateContent();
|
|
274
|
-
} else if (hasCredits) {
|
|
275
|
-
// Free: use credits
|
|
276
|
-
const result = await consumeCredit();
|
|
277
|
-
if (result.success) {
|
|
278
|
-
await generateContent();
|
|
279
|
-
}
|
|
280
|
-
} else {
|
|
281
|
-
// No access: show upgrade
|
|
282
|
-
showPaywall();
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
return (
|
|
287
|
-
<View>
|
|
288
|
-
<Text>Tier: {tier}</Text>
|
|
289
|
-
{!isPremium && <Text>Credits: {credits}</Text>}
|
|
290
|
-
|
|
291
|
-
<Button
|
|
292
|
-
onPress={handleGenerate}
|
|
293
|
-
title={
|
|
294
|
-
isPremium
|
|
295
|
-
? 'Generate (Unlimited)'
|
|
296
|
-
: 'Generate (5 credits)'
|
|
297
|
-
}
|
|
298
|
-
/>
|
|
299
|
-
</View>
|
|
300
|
-
);
|
|
136
|
+
// CORRECT - Check return value
|
|
137
|
+
const success = await deductCredit(5);
|
|
138
|
+
if (success) {
|
|
139
|
+
executeFeature();
|
|
301
140
|
}
|
|
141
|
+
|
|
142
|
+
// INCORRECT - Assume success
|
|
143
|
+
await deductCredit(5);
|
|
144
|
+
executeFeature(); // May execute if deduction failed
|
|
302
145
|
```
|
|
303
146
|
|
|
304
|
-
###
|
|
147
|
+
### Loading States
|
|
305
148
|
|
|
306
149
|
```typescript
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
function SettingsScreen() {
|
|
316
|
-
const { subscription, isLoading, refetch } = useSubscription();
|
|
317
|
-
const [refreshing, setRefreshing] = React.useState(false);
|
|
318
|
-
|
|
319
|
-
const handleRefresh = async () => {
|
|
320
|
-
setRefreshing(true);
|
|
321
|
-
await refetch();
|
|
322
|
-
setRefreshing(false);
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
return (
|
|
326
|
-
<ScrollView
|
|
327
|
-
refreshControl={
|
|
328
|
-
<RefreshControl refreshing={refreshing} onRefresh={handleRefresh} />
|
|
329
|
-
}
|
|
330
|
-
>
|
|
331
|
-
<SubscriptionSection
|
|
332
|
-
subscription={subscription}
|
|
333
|
-
onPress={() => navigation.navigate('SubscriptionDetail')}
|
|
334
|
-
/>
|
|
335
|
-
|
|
336
|
-
{subscription?.isPremium && (
|
|
337
|
-
<PremiumDetailsCard
|
|
338
|
-
status={subscription}
|
|
339
|
-
onManagePress={handleManageSubscription}
|
|
340
|
-
/>
|
|
341
|
-
)}
|
|
342
|
-
</ScrollView>
|
|
343
|
-
);
|
|
344
|
-
}
|
|
150
|
+
// CORRECT - Respect loading
|
|
151
|
+
if (isLoading) return <Spinner />;
|
|
152
|
+
if (!isPremium) return <UpgradePrompt />;
|
|
153
|
+
return <Content />;
|
|
154
|
+
|
|
155
|
+
// INCORRECT - Ignore loading
|
|
156
|
+
{!isPremium && <UpgradePrompt />} // Flickers during load
|
|
345
157
|
```
|
|
346
158
|
|
|
347
|
-
##
|
|
159
|
+
## AI Agent Guidelines
|
|
348
160
|
|
|
349
|
-
###
|
|
161
|
+
### When Implementing Features
|
|
350
162
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
plans: {
|
|
359
|
-
monthly: monthlyPlan,
|
|
360
|
-
annual: annualPlan,
|
|
361
|
-
lifetime: lifetimePlan,
|
|
362
|
-
},
|
|
363
|
-
|
|
364
|
-
defaultPlan: 'monthly',
|
|
365
|
-
|
|
366
|
-
features: {
|
|
367
|
-
requireAuth: true,
|
|
368
|
-
allowRestore: true,
|
|
369
|
-
syncWithFirebase: true,
|
|
370
|
-
},
|
|
371
|
-
|
|
372
|
-
ui: {
|
|
373
|
-
showAnnualDiscount: true,
|
|
374
|
-
highlightPopularPlan: true,
|
|
375
|
-
showPerks: true,
|
|
376
|
-
},
|
|
377
|
-
};
|
|
378
|
-
```
|
|
163
|
+
1. **Always** use appropriate gate hooks for feature access
|
|
164
|
+
2. **Always** handle loading, error, and empty states
|
|
165
|
+
3. **Always** provide user feedback for blocked features
|
|
166
|
+
4. **Always** check return values from operations
|
|
167
|
+
5. **Never** bypass gate system or checks
|
|
168
|
+
6. **Must** test with different user tiers
|
|
169
|
+
7. **Must** handle network errors gracefully
|
|
379
170
|
|
|
380
|
-
###
|
|
171
|
+
### Implementation Checklist
|
|
381
172
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
price: 0.99,
|
|
394
|
-
currency: 'USD',
|
|
395
|
-
},
|
|
396
|
-
{
|
|
397
|
-
id: 'credits_medium',
|
|
398
|
-
productId: 'com.app.credits.medium',
|
|
399
|
-
amount: 500,
|
|
400
|
-
price: 3.99,
|
|
401
|
-
currency: 'USD',
|
|
402
|
-
},
|
|
403
|
-
],
|
|
404
|
-
|
|
405
|
-
creditCosts: {
|
|
406
|
-
ai_generation: 1,
|
|
407
|
-
ai_analysis: 2,
|
|
408
|
-
premium_feature: 5,
|
|
409
|
-
},
|
|
410
|
-
};
|
|
411
|
-
```
|
|
173
|
+
- [ ] Import from correct path
|
|
174
|
+
- [ ] Wrap with necessary providers
|
|
175
|
+
- [ ] Use gate hooks for features
|
|
176
|
+
- [ ] Handle loading states
|
|
177
|
+
- [ ] Handle error states
|
|
178
|
+
- [ ] Provide user feedback
|
|
179
|
+
- [ ] Test with guest user
|
|
180
|
+
- [ ] Test with free user
|
|
181
|
+
- [ ] Test with premium user
|
|
182
|
+
- [ ] Test with no credits
|
|
183
|
+
- [ ] Test with insufficient credits
|
|
412
184
|
|
|
413
|
-
|
|
185
|
+
### Common Patterns
|
|
414
186
|
|
|
415
|
-
|
|
187
|
+
1. **Premium Feature**: Use `usePremiumGate`
|
|
188
|
+
2. **Credit Feature**: Use `useCreditsGate` or `useDeductCredit`
|
|
189
|
+
3. **Auth Feature**: Use `useAuthGate`
|
|
190
|
+
4. **Combined Gates**: Use `useFeatureGate` for complex scenarios
|
|
191
|
+
5. **Paywall Trigger**: Use `usePaywallVisibility` for global state
|
|
416
192
|
|
|
417
|
-
|
|
418
|
-
┌─────────────────────────────────────────┐
|
|
419
|
-
│ Presentation Layer │
|
|
420
|
-
│ (React Hooks & Components) │
|
|
421
|
-
├─────────────────────────────────────────┤
|
|
422
|
-
│ Application Layer │
|
|
423
|
-
│ (Use Cases & Service Contracts) │
|
|
424
|
-
├─────────────────────────────────────────┤
|
|
425
|
-
│ Domain Layer │
|
|
426
|
-
│ (Entities & Business Logic) │
|
|
427
|
-
├─────────────────────────────────────────┤
|
|
428
|
-
│ Infrastructure Layer │
|
|
429
|
-
│ (External Services & Repositories) │
|
|
430
|
-
└─────────────────────────────────────────┘
|
|
431
|
-
```
|
|
193
|
+
### Error Scenarios to Handle
|
|
432
194
|
|
|
433
|
-
|
|
195
|
+
- **No Subscription**: Show upgrade prompt
|
|
196
|
+
- **Expired Subscription**: Show renewal prompt
|
|
197
|
+
- **No Credits**: Show credit purchase prompt
|
|
198
|
+
- **Insufficient Credits**: Show credit cost and purchase option
|
|
199
|
+
- **Network Error**: Show retry option
|
|
200
|
+
- **Purchase Failed**: Show error message and retry
|
|
434
201
|
|
|
435
|
-
|
|
436
|
-
2. **Use gate hooks** (`usePremiumGate`, `useCreditsGate`) for feature access control
|
|
437
|
-
3. **Handle errors gracefully** and show user-friendly messages
|
|
438
|
-
4. **Provide restore purchase** option for iOS and Android
|
|
439
|
-
5. **Track subscription events** with analytics
|
|
440
|
-
6. **Use translations** for multi-language support
|
|
441
|
-
7. **Test different subscription states** (guest, free, premium, expired)
|
|
202
|
+
## Documentation Structure
|
|
442
203
|
|
|
443
|
-
|
|
204
|
+
### Domain Documentation
|
|
444
205
|
|
|
445
|
-
|
|
206
|
+
- **[Wallet Domain](./src/domains/wallet/README.md)**: Credits and transactions
|
|
207
|
+
- **[Paywall Domain](./src/domains/paywall/README.md)**: Paywall components
|
|
208
|
+
- **[Config Domain](./src/domains/config/README.md)**: Configuration management
|
|
446
209
|
|
|
447
|
-
|
|
210
|
+
### Layer Documentation
|
|
448
211
|
|
|
449
|
-
|
|
212
|
+
- **[Presentation Layer](./src/presentation/README.md)**: Hooks and components
|
|
213
|
+
- **[Application Layer](./src/application/README.md)**: Use cases and ports
|
|
214
|
+
- **[Domain Layer](./src/domain/README.md)**: Entities and logic
|
|
215
|
+
- **[Infrastructure Layer](./src/infrastructure/README.md)**: Repositories and services
|
|
216
|
+
|
|
217
|
+
### Feature Documentation
|
|
218
|
+
|
|
219
|
+
- **[RevenueCat Integration](./src/revenuecat/README.md)**: RevenueCat setup
|
|
220
|
+
- **[Subscription Hooks](./src/presentation/hooks/README.md)**: Available hooks
|
|
221
|
+
- **[Premium Components](./src/presentation/components/README.md)**: UI components
|
|
222
|
+
|
|
223
|
+
### Quick Reference
|
|
224
|
+
|
|
225
|
+
#### Subscription Hooks
|
|
226
|
+
|
|
227
|
+
Location: `src/presentation/hooks/`
|
|
228
|
+
|
|
229
|
+
- `useSubscription` - Core subscription management
|
|
230
|
+
- `usePremium` - Check premium status
|
|
231
|
+
- `usePremiumGate` - Gate premium features
|
|
232
|
+
- `useUserTier` - Get user tier (guest/free/premium)
|
|
450
233
|
|
|
451
|
-
|
|
234
|
+
#### Credit Hooks
|
|
452
235
|
|
|
453
|
-
|
|
236
|
+
Location: `src/presentation/hooks/`
|
|
454
237
|
|
|
455
|
-
|
|
238
|
+
- `useCredits` - Access credit balance
|
|
239
|
+
- `useDeductCredit` - Deduct credits with optimistic updates
|
|
240
|
+
- `useCreditChecker` - Check credit availability
|
|
241
|
+
- `useCreditsGate` - Gate features by credits
|
|
456
242
|
|
|
457
|
-
|
|
458
|
-
|
|
243
|
+
#### Paywall Hooks
|
|
244
|
+
|
|
245
|
+
Location: `src/presentation/hooks/`
|
|
246
|
+
|
|
247
|
+
- `usePaywallVisibility` - Manage paywall state
|
|
248
|
+
- `usePaywallOperations` - Handle purchase operations
|
|
249
|
+
|
|
250
|
+
#### Components
|
|
251
|
+
|
|
252
|
+
Location: `src/presentation/components/`
|
|
253
|
+
|
|
254
|
+
- `PremiumDetailsCard` - Display subscription details
|
|
255
|
+
- `PremiumStatusBadge` - Show subscription badge
|
|
256
|
+
- `PaywallModal` - Full paywall modal
|
|
257
|
+
- `CreditRow` - Display credit balance with progress
|
|
258
|
+
|
|
259
|
+
## Contributing
|
|
260
|
+
|
|
261
|
+
When contributing to this package:
|
|
262
|
+
|
|
263
|
+
1. **Follow Documentation Template**: Use `README_TEMPLATE.md`
|
|
264
|
+
2. **Update Strategy Section**: Document architectural decisions
|
|
265
|
+
3. **List Restrictions**: Clearly state what's required/prohibited
|
|
266
|
+
4. **Provide Rules**: Show correct/incorrect usage
|
|
267
|
+
5. **AI Guidelines**: Include agent instructions
|
|
268
|
+
6. **No Code Examples**: Keep documentation code-agnostic
|
|
269
|
+
7. **English Only**: All documentation in English
|
|
459
270
|
|
|
460
271
|
## Support
|
|
461
272
|
|
|
462
|
-
|
|
273
|
+
- **Issues**: [GitHub Issues](https://github.com/umituz/react-native-subscription/issues)
|
|
274
|
+
- **Author**: Ümit UZ <umit@umituz.com>
|
|
275
|
+
|
|
276
|
+
## License
|
|
277
|
+
|
|
278
|
+
MIT License - see LICENSE file for details
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.100",
|
|
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",
|