@umituz/react-native-subscription 2.14.99 → 2.14.101

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.
Files changed (98) hide show
  1. package/README.md +211 -394
  2. package/package.json +3 -3
  3. package/src/application/README.md +46 -225
  4. package/src/application/ports/README.md +42 -97
  5. package/src/domain/README.md +36 -384
  6. package/src/domain/constants/README.md +0 -56
  7. package/src/domain/entities/README.md +43 -169
  8. package/src/domain/entities/SubscriptionStatus.ts +1 -1
  9. package/src/domain/errors/README.md +33 -287
  10. package/src/domain/value-objects/README.md +43 -179
  11. package/src/domains/README.md +50 -238
  12. package/src/domains/README.md.bak +274 -0
  13. package/src/domains/config/README.md +93 -383
  14. package/src/domains/config/domain/README.md +23 -376
  15. package/src/domains/config/domain/entities/README.md +34 -343
  16. package/src/domains/paywall/README.md +99 -369
  17. package/src/domains/paywall/components/README.md +34 -178
  18. package/src/domains/paywall/entities/README.md +34 -193
  19. package/src/domains/paywall/hooks/README.md +34 -122
  20. package/src/domains/wallet/README.md +34 -275
  21. package/src/domains/wallet/README.md.bak +209 -0
  22. package/src/domains/wallet/domain/README.md +34 -101
  23. package/src/domains/wallet/domain/entities/README.md +34 -115
  24. package/src/domains/wallet/domain/errors/README.md +34 -151
  25. package/src/domains/wallet/infrastructure/README.md +34 -89
  26. package/src/domains/wallet/presentation/components/README.md +34 -224
  27. package/src/domains/wallet/presentation/components/TransactionItem.tsx +1 -1
  28. package/src/domains/wallet/presentation/hooks/README.md +34 -248
  29. package/src/infrastructure/README.md +37 -496
  30. package/src/infrastructure/mappers/README.md +0 -13
  31. package/src/infrastructure/repositories/README.md +74 -360
  32. package/src/infrastructure/services/ActivationHandler.ts +1 -1
  33. package/src/infrastructure/services/README.md +95 -370
  34. package/src/infrastructure/services/SubscriptionService.ts +1 -1
  35. package/src/presentation/README.md +123 -408
  36. package/src/presentation/README.md.bak +172 -0
  37. package/src/presentation/components/README.md +151 -179
  38. package/src/presentation/components/README.md.bak +217 -0
  39. package/src/presentation/components/details/CreditRow.md +65 -310
  40. package/src/presentation/components/details/DetailRow.md +63 -255
  41. package/src/presentation/components/details/PremiumDetailsCard.md +65 -238
  42. package/src/presentation/components/details/PremiumStatusBadge.md +64 -239
  43. package/src/presentation/components/details/README.md +97 -447
  44. package/src/presentation/components/feedback/PaywallFeedbackModal.md +63 -287
  45. package/src/presentation/components/feedback/README.md +97 -445
  46. package/src/presentation/components/paywall/PaywallModal.md +66 -416
  47. package/src/presentation/components/paywall/README.md +50 -186
  48. package/src/presentation/components/sections/README.md +97 -466
  49. package/src/presentation/components/sections/SubscriptionSection.md +92 -244
  50. package/src/presentation/hooks/README.md +154 -741
  51. package/src/presentation/hooks/useAuthAwarePurchase.md +58 -325
  52. package/src/presentation/hooks/useAuthGate.md +61 -375
  53. package/src/presentation/hooks/useAuthSubscriptionSync.md +66 -370
  54. package/src/presentation/hooks/useCreditChecker.md +73 -378
  55. package/src/presentation/hooks/useCredits.md +74 -313
  56. package/src/presentation/hooks/useCredits.md.bak +231 -0
  57. package/src/presentation/hooks/useCreditsGate.md +66 -318
  58. package/src/presentation/hooks/useDeductCredit.md +0 -76
  59. package/src/presentation/hooks/useDeductCredit.ts +1 -1
  60. package/src/presentation/hooks/useDevTestCallbacks.md +63 -394
  61. package/src/presentation/hooks/useFeatureGate.md +105 -150
  62. package/src/presentation/hooks/useFeatureGate.md.bak +284 -0
  63. package/src/presentation/hooks/useInitializeCredits.md +64 -430
  64. package/src/presentation/hooks/usePaywall.md +61 -306
  65. package/src/presentation/hooks/usePaywallOperations.md +64 -458
  66. package/src/presentation/hooks/usePaywallVisibility.md +67 -316
  67. package/src/presentation/hooks/usePremium.md +84 -226
  68. package/src/presentation/hooks/usePremiumGate.md +60 -395
  69. package/src/presentation/hooks/usePremiumWithCredits.md +64 -401
  70. package/src/presentation/hooks/useSubscription.md +66 -422
  71. package/src/presentation/hooks/useSubscriptionDetails.md +65 -410
  72. package/src/presentation/hooks/useSubscriptionGate.md +80 -164
  73. package/src/presentation/hooks/useSubscriptionSettingsConfig.md +66 -346
  74. package/src/presentation/hooks/useSubscriptionStatus.md +66 -396
  75. package/src/presentation/hooks/useUserTier.md +63 -328
  76. package/src/presentation/hooks/useUserTierWithRepository.md +64 -424
  77. package/src/presentation/screens/README.md +48 -190
  78. package/src/presentation/types/README.md +0 -16
  79. package/src/presentation/utils/README.md +0 -21
  80. package/src/presentation/utils/subscriptionDateUtils.ts +1 -1
  81. package/src/revenuecat/README.md +99 -518
  82. package/src/revenuecat/application/README.md +35 -150
  83. package/src/revenuecat/application/ports/README.md +34 -162
  84. package/src/revenuecat/domain/README.md +42 -141
  85. package/src/revenuecat/domain/constants/README.md +34 -176
  86. package/src/revenuecat/domain/entities/README.md +34 -374
  87. package/src/revenuecat/domain/errors/README.md +47 -191
  88. package/src/revenuecat/domain/types/README.md +34 -366
  89. package/src/revenuecat/domain/value-objects/README.md +34 -434
  90. package/src/revenuecat/infrastructure/README.md +34 -43
  91. package/src/revenuecat/infrastructure/config/README.md +32 -23
  92. package/src/revenuecat/infrastructure/handlers/README.md +34 -211
  93. package/src/revenuecat/infrastructure/managers/README.md +34 -42
  94. package/src/revenuecat/infrastructure/services/README.md +35 -318
  95. package/src/revenuecat/infrastructure/utils/README.md +34 -375
  96. package/src/revenuecat/presentation/README.md +34 -176
  97. package/src/revenuecat/presentation/hooks/README.md +29 -35
  98. package/src/utils/README.md +38 -525
@@ -1,743 +1,156 @@
1
1
  # Subscription Hooks
2
2
 
3
- Abonelik, premium ve kredi yönetimi için React Hooks koleksiyonu.
4
-
5
- ## İçindekiler
6
-
7
- - [Subscription Hooks](#subscription-hooks)
8
- - [Premium Hooks](#premium-hooks)
9
- - [Credits Hooks](#credits-hooks)
10
- - [Gate Hooks](#gate-hooks)
11
- - [Auth Hooks](#auth-hooks)
12
- - [Paywall Hooks](#paywall-hooks)
13
-
14
- ## Subscription Hooks
15
-
16
- ### useSubscription
17
-
18
- Kullanıcının abonelik durumunu yönetmek için:
19
-
20
- ```typescript
21
- import { useSubscription } from '@umituz/react-native-subscription';
22
-
23
- function MyComponent() {
24
- const {
25
- isSubscribed,
26
- isActive,
27
- subscription,
28
- isLoading,
29
- error,
30
- checkSubscription,
31
- } = useSubscription();
32
-
33
- if (isLoading) return <ActivityIndicator />;
34
-
35
- return (
36
- <View>
37
- <Text>Status: {isSubscribed ? 'Premium' : 'Free'}</Text>
38
- {subscription && (
39
- <Text>
40
- Expires: {new Date(subscription.expirationDate).toLocaleDateString()}
41
- </Text>
42
- )}
43
- </View>
44
- );
45
- }
46
- ```
47
-
48
- ### useSubscriptionStatus
49
-
50
- Detaylı abonelik durumu bilgileri için:
51
-
52
- ```typescript
53
- import { useSubscriptionStatus } from '@umituz/react-native-subscription';
54
-
55
- function SubscriptionBadge() {
56
- const {
57
- status,
58
- tier,
59
- isActive,
60
- willRenew,
61
- expirationDate,
62
- isLoading,
63
- } = useSubscriptionStatus();
64
-
65
- if (isLoading) return null;
66
-
67
- return (
68
- <View>
69
- <Badge
70
- color={isActive ? 'green' : 'gray'}
71
- >
72
- {tier.toUpperCase()}
73
- </Badge>
74
- {willRenew && <Text>Auto-renewal on</Text>}
75
- {expirationDate && (
76
- <Text>
77
- Expires: {new Date(expirationDate).toLocaleDateString()}
78
- </Text>
79
- )}
80
- </View>
81
- );
82
- }
83
- ```
84
-
85
- ### useSubscriptionDetails
86
-
87
- Abonelik detaylarını görüntülemek için:
88
-
89
- ```typescript
90
- import { useSubscriptionDetails } from '@umituz/react-native-subscription';
91
-
92
- function SubscriptionDetails() {
93
- const {
94
- subscription,
95
- package,
96
- period,
97
- price,
98
- features,
99
- isLoading,
100
- refetch,
101
- } = useSubscriptionDetails();
102
-
103
- if (isLoading) return <ActivityIndicator />;
104
-
105
- return (
106
- <Card>
107
- <Text>{package?.title}</Text>
108
- <Text>{price} / {period}</Text>
109
- <Text>Features:</Text>
110
- {features?.map((feature) => (
111
- <Text key={feature}>• {feature}</Text>
112
- ))}
113
- <Button onPress={refetch} title="Refresh" />
114
- </Card>
115
- );
116
- }
117
- ```
118
-
119
- ## Premium Hooks
120
-
121
- ### usePremium
122
-
123
- Premium durumunu kontrol etmek için:
124
-
125
- ```typescript
126
- import { usePremium } from '@umituz/react-native-subscription';
127
-
128
- function PremiumFeature() {
129
- const { isPremium, isLoading } = usePremium();
130
-
131
- if (isLoading) return <ActivityIndicator />;
132
-
133
- if (!isPremium) {
134
- return <UpgradePrompt />;
135
- }
136
-
137
- return <PremiumContent />;
138
- }
139
- ```
140
-
141
- ### usePremiumGate
142
-
143
- Premium özelliklere erişimi kontrol etmek için:
144
-
145
- ```typescript
146
- import { usePremiumGate } from '@umituz/react-native-subscription';
147
-
148
- function ProtectedFeature() {
149
- const { isPremium, showPaywall, canAccess } = usePremiumGate({
150
- featureId: 'advanced_analytics',
151
- onUpgradeRequired: showPaywall,
152
- });
153
-
154
- const handleAction = () => {
155
- if (!canAccess) {
156
- showPaywall();
157
- return;
158
- }
159
- // Premium feature logic
160
- };
161
-
162
- return (
163
- <Button onPress={handleAction} title="Run Analytics" />
164
- );
165
- }
166
- ```
167
-
168
- ### usePremiumWithCredits
169
-
170
- Premium veya kredi ile kullanılabilen özellikler için:
171
-
172
- ```typescript
173
- import { usePremiumWithCredits } from '@umituz/react-native-subscription';
174
-
175
- function HybridFeature() {
176
- const {
177
- isPremium,
178
- hasCredits,
179
- credits,
180
- consumeCredit,
181
- isLoading,
182
- } = usePremiumWithCredits({
183
- creditCost: 1,
184
- featureId: 'ai_generation',
185
- });
186
-
187
- const handleGenerate = async () => {
188
- if (isPremium) {
189
- // Premium users have unlimited access
190
- await generateContent();
191
- } else if (hasCredits) {
192
- // Use credits
193
- const result = await consumeCredit();
194
- if (result.success) {
195
- await generateContent();
196
- }
197
- } else {
198
- // Show upgrade prompt
199
- showPaywall();
200
- }
201
- };
202
-
203
- return (
204
- <View>
205
- <Button onPress={handleGenerate} title="Generate" />
206
- {!isPremium && <Text>Credits: {credits}</Text>}
207
- </View>
208
- );
209
- }
210
- ```
211
-
212
- ## Credits Hooks
213
-
214
- ### useCredits
215
-
216
- Kredi bakiyesi yönetimi için:
217
-
218
- ```typescript
219
- import { useCredits } from '@umituz/react-native-subscription';
220
-
221
- function CreditsDisplay() {
222
- const {
223
- credits,
224
- balance,
225
- isLoading,
226
- refetch,
227
- } = useCredits();
228
-
229
- return (
230
- <View>
231
- <Text>Credits: {credits}</Text>
232
- <Text>Balance: ${balance}</Text>
233
- <Button onPress={refetch} title="Refresh" />
234
- </View>
235
- );
236
- }
237
- ```
238
-
239
- ### useCreditsGate
240
-
241
- Kredi gerektiren özellikler için:
242
-
243
- ```typescript
244
- import { useCreditsGate } from '@umituz/react-native-subscription';
245
-
246
- function CreditBasedFeature() {
247
- const {
248
- hasCredits,
249
- credits,
250
- consumeCredit,
251
- isLoading,
252
- showPurchasePrompt,
253
- } = useCreditsGate({
254
- creditCost: 5,
255
- featureId: 'export',
256
- });
257
-
258
- const handleExport = async () => {
259
- if (!hasCredits) {
260
- showPurchasePrompt();
261
- return;
262
- }
263
-
264
- const result = await consumeCredit();
265
- if (result.success) {
266
- await exportData();
267
- }
268
- };
269
-
270
- return (
271
- <Button onPress={handleExport} title="Export (5 credits)" />
272
- );
273
- }
274
- ```
275
-
276
- ### useDeductCredit
277
-
278
- Kredi düşme işlemi için:
279
-
280
- ```typescript
281
- import { useDeductCredit } from '@umituz/react-native-subscription';
282
-
283
- function PaidAction() {
284
- const { deductCredit, isLoading } = useDeductCredit();
285
-
286
- const handleAction = async () => {
287
- const result = await deductCredit({
288
- amount: 10,
289
- reason: 'feature_usage',
290
- metadata: { featureId: 'ai_analysis' },
291
- });
292
-
293
- if (result.success) {
294
- console.log('Credit deducted successfully');
295
- // Continue with action
296
- } else {
297
- Alert.alert('Error', result.error?.message);
298
- }
299
- };
300
-
301
- return <Button onPress={handleAction} title="Use Feature (10 credits)" />;
302
- }
303
- ```
304
-
305
- ### useInitializeCredits
306
-
307
- Kredi sistemini başlatmak için:
308
-
309
- ```typescript
310
- import { useInitializeCredits } from '@umituz/react-native-subscription';
311
-
312
- function App() {
313
- const { isInitialized, initialize, error } = useInitializeCredits();
314
-
315
- useEffect(() => {
316
- if (!isInitialized) {
317
- initialize({
318
- initialCredits: 100,
319
- creditPackages: [
320
- { id: 'small', amount: 100, price: 0.99 },
321
- { id: 'medium', amount: 500, price: 3.99 },
322
- ],
323
- });
324
- }
325
- }, []);
326
-
327
- if (error) {
328
- return <ErrorScreen error={error} />;
329
- }
330
-
331
- return <AppContent />;
332
- }
333
- ```
334
-
335
- ## Gate Hooks
336
-
337
- ### useFeatureGate
338
-
339
- Genel özellik erişim kontrolü için:
340
-
341
- ```typescript
342
- import { useFeatureGate } from '@umituz/react-native-subscription';
343
-
344
- function GatedFeature() {
345
- const { canAccess, gateState, showUpgradePrompt } = useFeatureGate({
346
- featureId: 'advanced_filters',
347
- requirements: {
348
- tier: 'premium',
349
- minCredits: 0,
350
- },
351
- });
352
-
353
- if (!canAccess) {
354
- return (
355
- <View>
356
- <Text>This feature requires Premium</Text>
357
- <Button onPress={showUpgradePrompt} title="Upgrade" />
358
- </View>
359
- );
360
- }
361
-
362
- return <FeatureContent />;
363
- }
364
- ```
365
-
366
- ### useSubscriptionGate
367
-
368
- Abonelik kontrolü için:
369
-
370
- ```typescript
371
- import { useSubscriptionGate } from '@umituz/react-native-subscription';
372
-
373
- function SubscriptionOnlyFeature() {
374
- const {
375
- isSubscribed,
376
- subscriptionType,
377
- canAccess,
378
- showPaywall,
379
- } = useSubscriptionGate({
380
- requiredTier: 'premium',
381
- });
382
-
383
- if (!canAccess) {
384
- return (
385
- <LockedScreen
386
- onUpgrade={showPaywall}
387
- message="Upgrade to Premium to access this feature"
388
- />
389
- );
390
- }
391
-
392
- return <FeatureContent />;
393
- }
394
- ```
395
-
396
- ### useAuthGate
397
-
398
- Auth + abonelik kontrolü için:
399
-
400
- ```typescript
401
- import { useAuthGate } from '@umituz/react-native-subscription';
402
-
403
- function ProtectedContent() {
404
- const {
405
- isAuthenticated,
406
- isAuthorized,
407
- user,
408
- signIn,
409
- signOut,
410
- } = useAuthGate({
411
- requireAuth: true,
412
- requireSubscription: true,
413
- });
414
-
415
- if (!isAuthenticated) {
416
- return <SignInPrompt onSignIn={signIn} />;
417
- }
418
-
419
- if (!isAuthorized) {
420
- return <UpgradePrompt />;
421
- }
422
-
423
- return <ProtectedData />;
424
- }
425
- ```
426
-
427
- ## Auth Hooks
428
-
429
- ### useAuthAwarePurchase
430
-
431
- Auth-aware satın alma için:
432
-
433
- ```typescript
434
- import { useAuthAwarePurchase } from '@umituz/react-native-subscription';
435
-
436
- function PurchaseButton() {
437
- const { purchase, isLoading, requiresAuth } = useAuthAwarePurchase({
438
- productId: 'premium_monthly',
439
- });
440
-
441
- const handlePurchase = async () => {
442
- const result = await purchase();
443
-
444
- if (result.requiresAuth) {
445
- // Show auth screen
446
- navigateToAuth();
447
- } else if (result.success) {
448
- // Purchase successful
449
- Alert.alert('Success', 'You are now Premium!');
450
- }
451
- };
452
-
453
- return (
454
- <Button
455
- onPress={handlePurchase}
456
- disabled={isLoading}
457
- title="Subscribe"
458
- />
459
- );
460
- }
461
- ```
462
-
463
- ### useAuthSubscriptionSync
464
-
465
- Auth ve abonelik senkronizasyonu için:
466
-
467
- ```typescript
468
- import { useAuthSubscriptionSync } from '@umituz/react-native-subscription';
469
-
470
- function AuthManager() {
471
- const { user } = useAuth();
472
- const { syncSubscription, clearSubscription } = useAuthSubscriptionSync();
473
-
474
- useEffect(() => {
475
- if (user) {
476
- // Sync subscription with auth user
477
- syncSubscription(user.uid);
478
- } else {
479
- // Clear subscription on logout
480
- clearSubscription();
481
- }
482
- }, [user?.uid]);
483
-
484
- return null;
485
- }
486
- ```
487
-
488
- ## Paywall Hooks
489
-
490
- ### usePaywallOperations
491
-
492
- Paywall işlemleri için:
493
-
494
- ```typescript
495
- import { usePaywallOperations } from '@umituz/react-native-subscription';
496
-
497
- function PaywallManager() {
498
- const {
499
- showPaywall,
500
- hidePaywall,
501
- isPaywallVisible,
502
- paywallState,
503
- } = usePaywallOperations();
504
-
505
- const handleUpgradeClick = () => {
506
- showPaywall({
507
- trigger: 'upgrade_button',
508
- featureId: 'advanced_features',
509
- });
510
- };
511
-
512
- return (
513
- <>
514
- <Button onPress={handleUpgradeClick} title="Upgrade" />
515
- <Paywall isVisible={isPaywallVisible} onClose={hidePaywall} />
516
- </>
517
- );
518
- }
519
- ```
520
-
521
- ### usePaywallVisibility
522
-
523
- Paywall görünürlük kontrolü için:
524
-
525
- ```typescript
526
- import { usePaywallVisibility } from '@umituz/react-native-subscription';
527
-
528
- function AutoPaywall() {
529
- const {
530
- shouldShowPaywall,
531
- showPaywall,
532
- dismissPaywall,
533
- hasSeenPaywall,
534
- } = usePaywallVisibility({
535
- trigger: 'feature_usage_limit',
536
- showAfter: 3, // Show after 3 actions
537
- frequency: 'once_per_session',
538
- });
539
-
540
- useEffect(() => {
541
- if (shouldShowPaywall) {
542
- showPaywall();
543
- }
544
- }, [shouldShowPaywall]);
545
-
546
- return <FeatureContent />;
547
- }
548
- ```
549
-
550
- ### useUserTier
551
-
552
- Kullanıcı tier yönetimi için:
553
-
554
- ```typescript
555
- import { useUserTier } from '@umituz/react-native-subscription';
556
-
557
- function TierAwareComponent() {
558
- const {
559
- tier,
560
- isGuest,
561
- isFree,
562
- isPremium,
563
- canUpgrade,
564
- isLoading,
565
- } = useUserTier();
566
-
567
- return (
568
- <View>
569
- <Badge>{tier?.toUpperCase()}</Badge>
570
-
571
- {isGuest && <Text>Sign in to save your progress</Text>}
572
- {isFree && <Button onPress={showUpgrade} title="Go Premium" />}
573
- {isPremium && <Text>Welcome, Premium user!</Text>}
574
- </View>
575
- );
576
- }
577
- ```
578
-
579
- ## Helper Hooks
580
-
581
- ### useCreditChecker
582
-
583
- Kredi kontrolü için basit hook:
584
-
585
- ```typescript
586
- import { useCreditChecker } from '@umituz/react-native-subscription';
587
-
588
- function FeatureWithCreditCheck() {
589
- const { hasEnoughCredits, credits, checkCredits } = useCreditChecker(10);
590
-
591
- const handleAction = () => {
592
- if (hasEnoughCredits) {
593
- // Execute action
594
- } else {
595
- Alert.alert('Insufficient credits', `You need 10 credits, have ${credits}`);
596
- }
597
- };
598
-
599
- return <Button onPress={handleAction} title="Execute" />;
600
- }
601
- ```
602
-
603
- ### useDevTestCallbacks
604
-
605
- Development ve test için callback hook'u:
606
-
607
- ```typescript
608
- import { useDevTestCallbacks } from '@umituz/react-native-subscription';
609
-
610
- function DevTestPanel() {
611
- const { setTestPremium, setTestCredits, resetTestState } = useDevTestCallbacks();
612
-
613
- if (!__DEV__) return null;
614
-
615
- return (
616
- <View>
617
- <Button onPress={() => setTestPremium(true)} title="Set Premium" />
618
- <Button onPress={() => setTestCredits(100)} title="Add 100 Credits" />
619
- <Button onPress={resetTestState} title="Reset" />
620
- </View>
621
- );
622
- }
623
- ```
624
-
625
- ## Best Practices
626
-
627
- 1. **Loading States**: Her zaman loading durumunu kontrol edin
628
- 2. **Error Handling**: Hataları uygun şekilde yakalayın ve gösterin
629
- 3. **Gate Hooks**: Özellik erişimi için gate hooks kullanın
630
- 4. **User Experience**: Anlaşılır mesajlar ve smooth transitions sağlayın
631
- 5. **Cache**: Gereksiz re-render'lardan kaçınmak için veriyi cache'leyin
632
- 6. **Cleanup**: Component unmount olduğunda subscription'ları temizleyin
633
-
634
- ## Örnek Uygulama
635
-
636
- ```typescript
637
- import React from 'react';
638
- import { View, Text, Button } from 'react-native';
639
- import {
640
- usePremiumGate,
641
- useCreditsGate,
642
- useUserTier,
643
- } from '@umituz/react-native-subscription';
644
-
645
- export default function FeatureExample() {
646
- const { tier, isPremium } = useUserTier();
647
-
648
- // Premium gate
649
- const { canAccess: canAccessPremium, showPaywall } = usePremiumGate({
650
- featureId: 'ai_tools',
651
- });
652
-
653
- // Credits gate
654
- const {
655
- hasCredits,
656
- credits,
657
- consumeCredit,
658
- } = useCreditsGate({
659
- creditCost: 5,
660
- featureId: 'ai_generation',
661
- });
662
-
663
- const handleAIAction = async () => {
664
- if (!canAccessPremium) {
665
- showPaywall();
666
- return;
667
- }
668
-
669
- if (isPremium) {
670
- // Premium users: unlimited access
671
- await performAIAction();
672
- } else if (hasCredits) {
673
- // Free users: use credits
674
- const result = await consumeCredit();
675
- if (result.success) {
676
- await performAIAction();
677
- }
678
- } else {
679
- // No credits: show purchase prompt
680
- showCreditPurchasePrompt();
681
- }
682
- };
683
-
684
- return (
685
- <View>
686
- <Text>Current Tier: {tier}</Text>
687
- {!isPremium && <Text>Credits: {credits}</Text>}
688
-
689
- <Button
690
- onPress={handleAIAction}
691
- title={isPremium ? "Generate (Unlimited)" : "Generate (5 credits)"}
692
- />
693
- </View>
694
- );
695
- }
696
- ```
697
-
698
- ## Hook Reference
699
-
700
- ### Tüm Export Edilen Hooks
701
-
702
- ```typescript
703
- // Auth & Sync
704
- export { useAuthAwarePurchase } from './useAuthAwarePurchase';
705
- export { useAuthGate } from './useAuthGate';
706
- export { useAuthSubscriptionSync } from './useAuthSubscriptionSync';
707
-
708
- // Credits
709
- export { useCreditChecker } from './useCreditChecker';
710
- export { useCredits } from './useCredits';
711
- export { useCreditsGate } from './useCreditsGate';
712
- export { useDeductCredit } from './useDeductCredit';
713
- export { useInitializeCredits } from './useInitializeCredits';
714
-
715
- // Features
716
- export { useFeatureGate } from './useFeatureGate';
717
-
718
- // Premium
719
- export { usePremium } from './usePremium';
720
- export { usePremiumGate } from './usePremiumGate';
721
- export { usePremiumWithCredits } from './usePremiumWithCredits';
722
-
723
- // Subscription
724
- export { useSubscription } from './useSubscription';
725
- export { useSubscriptionDetails } from './useSubscriptionDetails';
726
- export { useSubscriptionGate } from './useSubscriptionGate';
727
- export { useSubscriptionSettingsConfig } from './useSubscriptionSettingsConfig';
728
- export { useSubscriptionStatus } from './useSubscriptionStatus';
729
-
730
- // User Tier
731
- export { useUserTier } from './useUserTier';
732
- export { useUserTierWithRepository } from './useUserTierWithRepository';
733
-
734
- // Paywall
735
- export { usePaywallOperations } from './usePaywallOperations';
736
- export { usePaywallVisibility } from './usePaywallVisibility';
737
-
738
- // Feedback
739
- export { usePaywallFeedback } from './feedback/usePaywallFeedback';
740
-
741
- // Dev/Test
742
- export { useDevTestCallbacks } from './useDevTestCallbacks';
743
- ```
3
+ Collection of React hooks for subscription, premium, and credits management.
4
+
5
+ ## Location
6
+
7
+ **Import Path**: `@umituz/react-native-subscription`
8
+
9
+ **Directory**: `src/presentation/hooks/`
10
+
11
+ **Type**: Hooks Collection
12
+
13
+ ## Strategy
14
+
15
+ ### Hook Organization
16
+
17
+ Hooks are organized by functionality:
18
+
19
+ 1. **Subscription Hooks**: Manage subscription status and details
20
+ 2. **Premium Hooks**: Check and manage premium access
21
+ 3. **Credits Hooks**: Handle credit balance and operations
22
+ 4. **Gate Hooks**: Control feature access based on user state
23
+ 5. **Auth Hooks**: Authentication-aware purchase flows
24
+ 6. **Paywall Hooks**: Paywall display and management
25
+
26
+ ### Integration Pattern
27
+
28
+ All hooks follow consistent patterns:
29
+ - Return loading, error, and data states
30
+ - Provide refetch/refresh functions
31
+ - Use TanStack Query for caching
32
+ - Handle optimistic updates
33
+ - Support real-time updates
34
+
35
+ ## Hook Categories
36
+
37
+ ### Subscription Hooks
38
+
39
+ - **useSubscription**: Core subscription status management
40
+ - **useSubscriptionStatus**: Detailed subscription status
41
+ - **useSubscriptionDetails**: Subscription package and feature details
42
+ - **useSubscriptionSettingsConfig**: Settings and configuration
43
+
44
+ ### Premium Hooks
45
+
46
+ - **usePremium**: Premium status checker
47
+ - **usePremiumGate**: Premium feature gating
48
+ - **usePremiumWithCredits**: Hybrid premium/credits access
49
+
50
+ ### Credits Hooks
51
+
52
+ - **useCredits**: Credit balance and transactions
53
+ - **useCreditChecker**: Simple credit validation
54
+ - **useDeductCredit**: Credit deduction with optimistic updates
55
+ - **useInitializeCredits**: Initialize credits after purchase
56
+
57
+ ### Gate Hooks
58
+
59
+ - **useFeatureGate**: Unified auth, subscription, and credits gating
60
+ - **useSubscriptionGate**: Subscription-only gating
61
+ - **useCreditsGate**: Credits-only gating
62
+ - **usePremiumGate**: Premium-only gating
63
+ - **useAuthGate**: Authentication gating
64
+
65
+ ### Auth Hooks
66
+
67
+ - **useAuthAwarePurchase**: Authentication-aware purchase flow
68
+ - **useAuthSubscriptionSync**: Auth and subscription synchronization
69
+
70
+ ### Paywall Hooks
71
+
72
+ - **usePaywall**: Paywall display management
73
+ - **usePaywallOperations**: Paywall show/hide operations
74
+ - **usePaywallVisibility**: Paywall visibility rules
75
+
76
+ ### User Tier Hooks
77
+
78
+ - **useUserTier**: User tier management
79
+ - **useUserTierWithRepository**: Repository-based tier management
80
+
81
+ ### Development Hooks
82
+
83
+ - **useDevTestCallbacks**: Development and testing utilities
84
+
85
+ ## Restrictions
86
+
87
+ ### REQUIRED
88
+
89
+ - **Import Path**: MUST import from `@umituz/react-native-subscription`
90
+ - **Loading States**: MUST handle loading state in UI
91
+ - **Error Handling**: MUST handle error state
92
+ - **User Authentication**: Most hooks require authenticated user
93
+
94
+ ### PROHIBITED
95
+
96
+ - **NEVER** use hooks outside React components
97
+ - **NEVER** ignore loading states
98
+ - **NEVER** skip error handling
99
+ - **DO NOT** use hook returns for security decisions (server-side validation required)
100
+
101
+ ### CRITICAL SAFETY
102
+
103
+ - **ALWAYS** handle loading and error states
104
+ - **NEVER** trust client-side state for security
105
+ - **MUST** implement error boundaries
106
+ - **ALWAYS** test with various user states (guest, free, premium)
107
+
108
+ ## AI Agent Guidelines
109
+
110
+ ### When Using Subscription Hooks
111
+
112
+ 1. **Always** handle loading and error states
113
+ 2. **Always** use appropriate gate hooks for feature access
114
+ 3. **Always** provide user feedback for all operations
115
+ 4. **Never** trust client-side state for security
116
+ 5. **Always** test with different user tiers
117
+
118
+ ### Integration Checklist
119
+
120
+ - [ ] Import from correct path: `@umituz/react-native-subscription`
121
+ - [ ] Choose appropriate hook for use case
122
+ - [ ] Handle loading state
123
+ - [ ] Handle error state
124
+ - [ ] Implement error boundaries
125
+ - [ ] Use gate hooks for feature access
126
+ - [ ] Test with all user tiers
127
+ - [ ] Test offline scenarios
128
+ - [ ] Test error scenarios
129
+
130
+ ### Common Patterns
131
+
132
+ 1. **Feature Gating**: Use `useFeatureGate` for unified access control
133
+ 2. **Credit Operations**: Check → Deduct → Execute pattern
134
+ 3. **Subscription Display**: Show status, expiration, renewal info
135
+ 4. **Premium Features**: Gate content, provide upgrade path
136
+ 5. **Paywall Integration**: Automatic display on access denial
137
+ 6. **Real-time Updates**: Refresh on focus, background sync
138
+
139
+ ## Related Documentation
140
+
141
+ - **Subscription Domain**: `src/domains/wallet/README.md`
142
+ - **Paywall Domain**: `src/domains/paywall/README.md`
143
+ - **Config Domain**: `src/domains/config/README.md`
144
+ - **RevenueCat Integration**: `src/revenuecat/README.md`
145
+ - **Presentation Components**: `src/presentation/components/README.md`
146
+
147
+ ## Individual Hook Documentation
148
+
149
+ - [useDeductCredit](./useDeductCredit.md) - Credit deduction with optimistic updates
150
+ - [useCredits](./useCredits.md) - Credit balance access
151
+ - [useCreditChecker](./useCreditChecker.md) - Simple credit validation
152
+ - [useFeatureGate](./useFeatureGate.md) - Unified feature gating
153
+ - [useSubscription](./useSubscription.md) - Subscription status management
154
+ - [usePremium](./usePremium.md) - Premium status checker
155
+ - [useCreditsGate](./useCreditsGate.md) - Credits-based feature gating
156
+ - [useInitializeCredits](./useInitializeCredits.md) - Initialize credits after purchase