@umituz/react-native-subscription 2.27.92 → 2.27.94
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 +1 -1
- package/src/domains/credits/application/CreditsInitializer.ts +99 -40
- package/src/domains/credits/application/DeductCreditsCommand.ts +31 -13
- package/src/domains/credits/application/PurchaseMetadataGenerator.ts +17 -23
- package/src/domains/credits/core/Credits.ts +39 -39
- package/src/domains/credits/core/CreditsMapper.ts +11 -10
- package/src/domains/credits/core/UserCreditsDocument.ts +33 -33
- package/src/domains/credits/infrastructure/CreditsRepository.ts +46 -59
- package/src/domains/paywall/components/PaywallModal.tsx +1 -1
- package/src/domains/subscription/application/SubscriptionInitializer.ts +59 -18
- package/src/domains/subscription/application/SubscriptionInitializerTypes.ts +20 -20
- package/src/domains/subscription/infrastructure/handlers/PackageHandler.ts +46 -27
- package/src/domains/subscription/infrastructure/managers/SubscriptionManager.ts +106 -42
- package/src/domains/subscription/infrastructure/services/RestoreHandler.ts +4 -2
- package/src/domains/subscription/infrastructure/services/RevenueCatInitializer.ts +1 -2
- package/src/domains/subscription/infrastructure/utils/RenewalDetector.ts +1 -1
- package/src/domains/subscription/presentation/components/details/PremiumStatusBadge.tsx +6 -4
- package/src/domains/subscription/presentation/components/feedback/PaywallFeedbackModal.tsx +1 -1
- package/src/domains/subscription/presentation/types/SubscriptionDetailTypes.ts +4 -2
- package/src/domains/subscription/presentation/types/SubscriptionSettingsTypes.ts +1 -1
- package/src/domains/subscription/presentation/usePremiumGate.ts +1 -1
- package/src/domains/subscription/presentation/useSavedPurchaseAutoExecution.ts +1 -1
- package/src/domains/subscription/presentation/useSubscriptionSettingsConfig.ts +4 -3
- package/src/domains/subscription/presentation/useSubscriptionSettingsConfig.utils.ts +1 -1
- package/src/domains/trial/application/TrialEligibilityService.ts +1 -1
- package/src/domains/trial/infrastructure/DeviceTrialRepository.ts +2 -2
- package/src/shared/application/ports/IRevenueCatService.ts +2 -0
- package/src/shared/infrastructure/SubscriptionEventBus.ts +5 -2
- package/src/presentation/README.md +0 -125
- package/src/presentation/hooks/README.md +0 -156
- package/src/presentation/hooks/useAuthSubscriptionSync.md +0 -94
- package/src/presentation/hooks/useCredits.md +0 -103
- package/src/presentation/hooks/useDeductCredit.md +0 -100
- package/src/presentation/hooks/useFeatureGate.md +0 -112
- package/src/presentation/hooks/usePaywall.md +0 -89
- package/src/presentation/hooks/usePaywallOperations.md +0 -92
- package/src/presentation/hooks/usePaywallVisibility.md +0 -95
- package/src/presentation/hooks/usePremium.md +0 -88
- package/src/presentation/hooks/useSubscriptionSettingsConfig.md +0 -94
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
# useDeductCredit Hook
|
|
2
|
-
|
|
3
|
-
Hook for deducting credits from user balance with optimistic updates.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Import Path**: `@umituz/react-native-subscription`
|
|
8
|
-
|
|
9
|
-
**File**: `src/presentation/hooks/useDeductCredit.ts`
|
|
10
|
-
|
|
11
|
-
## Strategy
|
|
12
|
-
|
|
13
|
-
### Credit Deduction Flow
|
|
14
|
-
|
|
15
|
-
1. **Pre-deduction Validation**
|
|
16
|
-
- Verify user is authenticated (userId must be defined)
|
|
17
|
-
- Check if sufficient credits exist
|
|
18
|
-
- Validate deduction amount is positive
|
|
19
|
-
|
|
20
|
-
2. **Optimistic Update**
|
|
21
|
-
- Immediately update UI with new balance
|
|
22
|
-
- Store previous state for potential rollback
|
|
23
|
-
- Update TanStack Query cache
|
|
24
|
-
|
|
25
|
-
3. **Server Synchronization**
|
|
26
|
-
- Send deduction request to backend
|
|
27
|
-
- Handle success/failure responses
|
|
28
|
-
- Rollback on failure
|
|
29
|
-
|
|
30
|
-
4. **Post-deduction Handling**
|
|
31
|
-
- Trigger `onCreditsExhausted` callback if balance reaches zero
|
|
32
|
-
- Return success/failure boolean
|
|
33
|
-
- Reset loading state
|
|
34
|
-
|
|
35
|
-
### Integration Points
|
|
36
|
-
|
|
37
|
-
- **Credits Repository**: `src/domains/wallet/infrastructure/repositories/CreditsRepository.ts`
|
|
38
|
-
- **Credits Entity**: `src/domains/wallet/domain/entities/UserCredits.ts`
|
|
39
|
-
- **TanStack Query**: For cache management and optimistic updates
|
|
40
|
-
|
|
41
|
-
## Restrictions
|
|
42
|
-
|
|
43
|
-
### REQUIRED
|
|
44
|
-
|
|
45
|
-
- **User Authentication**: `userId` parameter MUST be provided and cannot be undefined
|
|
46
|
-
- **Positive Amount**: Credit cost MUST be greater than zero
|
|
47
|
-
- **Callback Implementation**: `onCreditsExhausted` callback SHOULD be implemented to handle zero balance scenarios
|
|
48
|
-
|
|
49
|
-
### PROHIBITED
|
|
50
|
-
|
|
51
|
-
- **NEVER** call `deductCredit` or `deductCredits` without checking `isDeducting` state first
|
|
52
|
-
- **NEVER** allow multiple simultaneous deduction calls for the same user
|
|
53
|
-
- **NEVER** deduce credits when balance is insufficient (should check with `useCreditChecker` first)
|
|
54
|
-
- **DO NOT** use this hook for guest users (userId undefined)
|
|
55
|
-
|
|
56
|
-
### CRITICAL SAFETY
|
|
57
|
-
|
|
58
|
-
- **ALWAYS** check return value before proceeding with feature execution
|
|
59
|
-
- **ALWAYS** handle the case where deduction returns `false`
|
|
60
|
-
- **NEVER** assume deduction succeeded without checking return value
|
|
61
|
-
- **MUST** implement error boundaries when using this hook
|
|
62
|
-
|
|
63
|
-
## AI Agent Guidelines
|
|
64
|
-
|
|
65
|
-
### When Implementing Features
|
|
66
|
-
|
|
67
|
-
1. **Always** check if user has sufficient credits BEFORE allowing action
|
|
68
|
-
2. **Always** show the credit cost to user before deducting
|
|
69
|
-
3. **Always** disable buttons while `isDeducting` is true
|
|
70
|
-
4. **Always** handle the case where deduction returns false
|
|
71
|
-
5. **Never** allow zero or negative credit costs
|
|
72
|
-
|
|
73
|
-
### Integration Checklist
|
|
74
|
-
|
|
75
|
-
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
76
|
-
- [ ] Provide valid `userId` from authentication context
|
|
77
|
-
- [ ] Implement `onCreditsExhausted` callback
|
|
78
|
-
- [ ] Check `isDeducting` before calling deduct functions
|
|
79
|
-
- [ ] Validate return value before proceeding
|
|
80
|
-
- [ ] Show credit cost to user before action
|
|
81
|
-
- [ ] Handle error cases gracefully
|
|
82
|
-
- [ ] Test with insufficient credits
|
|
83
|
-
- [ ] Test with zero balance
|
|
84
|
-
|
|
85
|
-
### Common Patterns to Implement
|
|
86
|
-
|
|
87
|
-
1. **Pre-check**: Use `useCreditChecker` before showing feature button
|
|
88
|
-
2. **Confirmation Dialog**: Ask user before expensive operations (>5 credits)
|
|
89
|
-
3. **Success Feedback**: Show success message after deduction
|
|
90
|
-
4. **Failure Handling**: Show appropriate error message on failure
|
|
91
|
-
5. **Purchase Flow**: Navigate to purchase screen on exhaustion
|
|
92
|
-
|
|
93
|
-
## Related Documentation
|
|
94
|
-
|
|
95
|
-
- **useCredits**: Access current credit balance
|
|
96
|
-
- **useCreditChecker**: Check credit availability before operations
|
|
97
|
-
- **useInitializeCredits**: Initialize credits after purchase
|
|
98
|
-
- **useFeatureGate**: Unified feature gating with credits
|
|
99
|
-
- **Credits Repository**: `src/domains/wallet/infrastructure/repositories/README.md`
|
|
100
|
-
- **Wallet Domain**: `src/domains/wallet/README.md`
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
# useFeatureGate Hook
|
|
2
|
-
|
|
3
|
-
Unified feature gate combining authentication, subscription, and credits checks.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Import Path**: `@umituz/react-native-subscription`
|
|
8
|
-
|
|
9
|
-
**File**: `src/presentation/hooks/useFeatureGate.ts`
|
|
10
|
-
|
|
11
|
-
**Type**: Hook
|
|
12
|
-
|
|
13
|
-
## Strategy
|
|
14
|
-
|
|
15
|
-
### Progressive Access Control
|
|
16
|
-
|
|
17
|
-
1. **Authentication Check**
|
|
18
|
-
- Verify user is authenticated
|
|
19
|
-
- Show auth modal if not authenticated
|
|
20
|
-
- Queue pending action for post-auth execution
|
|
21
|
-
|
|
22
|
-
2. **Subscription Check**
|
|
23
|
-
- Verify user has required subscription tier
|
|
24
|
-
- Show paywall if subscription insufficient
|
|
25
|
-
- Bypass credit check for premium users
|
|
26
|
-
|
|
27
|
-
3. **Credit Check**
|
|
28
|
-
- Verify sufficient credit balance
|
|
29
|
-
- Show purchase prompt if insufficient
|
|
30
|
-
- Deduct credits only after all checks pass
|
|
31
|
-
|
|
32
|
-
4. **Action Execution**
|
|
33
|
-
- Execute gated action only if all checks pass
|
|
34
|
-
- Handle failures gracefully
|
|
35
|
-
- Update UI state appropriately
|
|
36
|
-
|
|
37
|
-
### Integration Points
|
|
38
|
-
|
|
39
|
-
- **useAuth**: For authentication state
|
|
40
|
-
- **usePremium**: For subscription status
|
|
41
|
-
- **useCredits**: For credit balance
|
|
42
|
-
- **useDeductCredit**: For credit deduction
|
|
43
|
-
- **Auth Modals**: Custom authentication UI
|
|
44
|
-
- **Paywall Components**: Upgrade prompts
|
|
45
|
-
|
|
46
|
-
## Restrictions
|
|
47
|
-
|
|
48
|
-
### REQUIRED
|
|
49
|
-
|
|
50
|
-
- **Authentication Check**: MUST implement `onShowAuthModal` callback
|
|
51
|
-
- **Paywall Handler**: MUST implement `onShowPaywall` callback
|
|
52
|
-
- **Credit Validation**: MUST check `hasCredits` before allowing actions
|
|
53
|
-
- **State Management**: MUST respect `canAccess` boolean
|
|
54
|
-
|
|
55
|
-
### PROHIBITED
|
|
56
|
-
|
|
57
|
-
- **NEVER** bypass authentication check for sensitive features
|
|
58
|
-
- **NEVER** show feature gate if user has access (confusing UX)
|
|
59
|
-
- **NEVER** execute action without checking all gates first
|
|
60
|
-
- **DO NOT** hardcode gate logic (use hook parameters)
|
|
61
|
-
- **NEVER** deduct credits without checking subscription status first
|
|
62
|
-
|
|
63
|
-
### CRITICAL SAFETY
|
|
64
|
-
|
|
65
|
-
- **ALWAYS** check gates in order: Auth → Subscription → Credits
|
|
66
|
-
- **ALWAYS** provide clear messaging about why access is denied
|
|
67
|
-
- **ALWAYS** preserve user intent through auth/purchase flows
|
|
68
|
-
- **NEVER** trust client-side gate for security (server-side validation required)
|
|
69
|
-
- **MUST** implement proper error boundaries around gated actions
|
|
70
|
-
|
|
71
|
-
## AI Agent Guidelines
|
|
72
|
-
|
|
73
|
-
### When Implementing Feature Gates
|
|
74
|
-
|
|
75
|
-
1. **Always** check gates in order: Auth → Subscription → Credits
|
|
76
|
-
2. **Always** provide clear, specific messaging for each gate
|
|
77
|
-
3. **Always** preserve user intent through auth/purchase flows
|
|
78
|
-
4. **Always** bypass credit check for premium users (if applicable)
|
|
79
|
-
5. **Never** trust client-side gates for security (server validation required)
|
|
80
|
-
|
|
81
|
-
### Integration Checklist
|
|
82
|
-
|
|
83
|
-
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
84
|
-
- [ ] Implement `onShowAuthModal` with pending action preservation
|
|
85
|
-
- [ ] Implement `onShowPaywall` with context-aware messaging
|
|
86
|
-
- [ ] Check `canAccess` before showing feature
|
|
87
|
-
- [ ] Provide appropriate messaging for each gate state
|
|
88
|
-
- [ ] Respect premium status (bypass credit check if needed)
|
|
89
|
-
- [ ] Test all gate combinations (auth, subscription, credits)
|
|
90
|
-
- [ ] Test pending action execution after auth/purchase
|
|
91
|
-
- [ ] Implement error boundaries around gated actions
|
|
92
|
-
|
|
93
|
-
### Common Patterns to Implement
|
|
94
|
-
|
|
95
|
-
1. **Progressive Unlocking**: Show upgrade path for each gate
|
|
96
|
-
2. **Smart Paywalls**: Show subscription OR credits based on user state
|
|
97
|
-
3. **Intent Preservation**: Queue actions through auth/purchase flows
|
|
98
|
-
4. **Clear Messaging**: Tell users exactly what's required
|
|
99
|
-
5. **Premium Bypass**: Skip credit check for premium users
|
|
100
|
-
6. **Access Indicators**: Show lock/unlock status in UI
|
|
101
|
-
7. **Graceful Degradation**: Show limited version for free users
|
|
102
|
-
8. **Analytics Tracking**: Monitor gate triggers and conversions
|
|
103
|
-
|
|
104
|
-
## Related Documentation
|
|
105
|
-
|
|
106
|
-
- **useAuthGate**: Authentication gating only
|
|
107
|
-
- **useSubscriptionGate**: Subscription gating only
|
|
108
|
-
- **useCreditsGate**: Credits gating only
|
|
109
|
-
- **usePremiumGate**: Premium feature gating
|
|
110
|
-
- **useDeductCredit**: Credit deduction after gate passes
|
|
111
|
-
- **Feature Gating**: `../../../docs/FEATURE_GATING.md`
|
|
112
|
-
- **Access Control**: `../../../docs/ACCESS_PATTERNS.md`
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# usePaywall Hook
|
|
2
|
-
|
|
3
|
-
Hook for controlling paywall visibility and state.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Import Path**: `@umituz/react-native-subscription`
|
|
8
|
-
|
|
9
|
-
**File**: `src/presentation/hooks/usePaywall.ts`
|
|
10
|
-
|
|
11
|
-
**Type**: Hook
|
|
12
|
-
|
|
13
|
-
## Strategy
|
|
14
|
-
|
|
15
|
-
### Paywall State Management
|
|
16
|
-
|
|
17
|
-
1. **Visibility Control**: Show/hide paywall on demand
|
|
18
|
-
2. **Trigger Tracking**: Record what triggered paywall display
|
|
19
|
-
3. **Context Management**: Store paywall context and metadata
|
|
20
|
-
4. **Dynamic Configuration**: Support custom paywall configs per trigger
|
|
21
|
-
5. **State Persistence**: Maintain paywall state across component renders
|
|
22
|
-
6. **Event Tracking**: Enable analytics for paywall interactions
|
|
23
|
-
|
|
24
|
-
### Integration Points
|
|
25
|
-
|
|
26
|
-
- **Paywall Context**: Global paywall state management
|
|
27
|
-
- **Paywall Domain**: `src/domains/paywall/README.md`
|
|
28
|
-
- **Analytics**: For tracking paywall impressions and conversions
|
|
29
|
-
- **Navigation**: For paywall screen routing
|
|
30
|
-
|
|
31
|
-
## Restrictions
|
|
32
|
-
|
|
33
|
-
### REQUIRED
|
|
34
|
-
|
|
35
|
-
- **State Management**: MUST use showPaywall/hidePaywall functions
|
|
36
|
-
- **Trigger Tracking**: SHOULD include trigger information for analytics
|
|
37
|
-
- **Context**: SHOULD provide relevant context for paywall display
|
|
38
|
-
|
|
39
|
-
### PROHIBITED
|
|
40
|
-
|
|
41
|
-
- **NEVER** manage paywall state locally (use this hook instead)
|
|
42
|
-
- **NEVER** show paywall without user action or clear trigger
|
|
43
|
-
- **DO NOT** show paywall too frequently (respect user experience)
|
|
44
|
-
|
|
45
|
-
### CRITICAL SAFETY
|
|
46
|
-
|
|
47
|
-
- **ALWAYS** hide paywall on successful purchase
|
|
48
|
-
- **NEVER** trap users in paywall (provide clear exit)
|
|
49
|
-
- **MUST** track paywall triggers for analytics
|
|
50
|
-
- **ALWAYS** provide close/dismiss option
|
|
51
|
-
|
|
52
|
-
## AI Agent Guidelines
|
|
53
|
-
|
|
54
|
-
### When Implementing Paywall Triggers
|
|
55
|
-
|
|
56
|
-
1. **Always** include trigger source/context
|
|
57
|
-
2. **Always** track paywall impressions
|
|
58
|
-
3. **Always** provide clear close button
|
|
59
|
-
4. **Never** show paywall without clear reason
|
|
60
|
-
5. **Always** hide paywall after successful purchase
|
|
61
|
-
|
|
62
|
-
### Integration Checklist
|
|
63
|
-
|
|
64
|
-
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
65
|
-
- [ ] Use showPaywall with trigger information
|
|
66
|
-
- [ ] Implement hidePaywall callback
|
|
67
|
-
- [ ] Track paywall impressions in analytics
|
|
68
|
-
- [ ] Track paywall dismissals
|
|
69
|
-
- [ ] Provide clear close button
|
|
70
|
-
- [ ] Test manual trigger
|
|
71
|
-
- [ ] Test automatic trigger (usage limit, etc.)
|
|
72
|
-
- [ ] Test purchase flow completion
|
|
73
|
-
- [ ] Verify paywall hides after purchase
|
|
74
|
-
|
|
75
|
-
### Common Patterns
|
|
76
|
-
|
|
77
|
-
1. **Manual Trigger**: User clicks upgrade button
|
|
78
|
-
2. **Usage Limit**: Show after N free uses
|
|
79
|
-
3. **Feature Gate**: Show when accessing premium feature
|
|
80
|
-
4. **Time-based**: Show after certain time/usage
|
|
81
|
-
5. **Event-driven**: Show on specific app events
|
|
82
|
-
|
|
83
|
-
## Related Documentation
|
|
84
|
-
|
|
85
|
-
- **usePaywallActions**: Paywall purchase actions
|
|
86
|
-
- **usePaywallVisibility**: Conditional paywall display logic
|
|
87
|
-
- **usePaywallOperations**: Complete paywall operations
|
|
88
|
-
- **Paywall Domain**: `src/domains/paywall/README.md`
|
|
89
|
-
- **Paywall Components**: `src/presentation/components/paywall/README.md`
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
# usePaywallOperations Hook
|
|
2
|
-
|
|
3
|
-
Complete paywall purchase operations with authentication handling.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Import Path**: `@umituz/react-native-subscription`
|
|
8
|
-
|
|
9
|
-
**File**: `src/presentation/hooks/usePaywallOperations.ts`
|
|
10
|
-
|
|
11
|
-
**Type**: Hook
|
|
12
|
-
|
|
13
|
-
## Strategy
|
|
14
|
-
|
|
15
|
-
### Paywall Purchase Flow with Auth
|
|
16
|
-
|
|
17
|
-
1. **Auth Check**: Verify if user is authenticated before purchase
|
|
18
|
-
2. **Pending Package Management**: Store package when auth is required
|
|
19
|
-
3. **Auth Flow Trigger**: Show auth modal for unauthenticated users
|
|
20
|
-
4. **Purchase Execution**: Complete purchase after authentication
|
|
21
|
-
5. **Restore Support**: Handle purchase restoration with auth check
|
|
22
|
-
6. **Callback Handling**: Execute appropriate callbacks at each stage
|
|
23
|
-
|
|
24
|
-
### Integration Points
|
|
25
|
-
|
|
26
|
-
- **usePremium**: For purchase and restore operations
|
|
27
|
-
- **Auth Context**: User authentication state
|
|
28
|
-
- **Paywall Domain**: For paywall display and management
|
|
29
|
-
- **Auth UI**: For authentication modal
|
|
30
|
-
- **RevenueCat**: For purchase transactions
|
|
31
|
-
|
|
32
|
-
## Restrictions
|
|
33
|
-
|
|
34
|
-
### REQUIRED
|
|
35
|
-
|
|
36
|
-
- **User ID**: MUST provide valid userId parameter
|
|
37
|
-
- **Anonymous Check**: MUST provide isAnonymous parameter
|
|
38
|
-
- **Auth Required Callback**: MUST implement onAuthRequired callback
|
|
39
|
-
- **Error Handling**: MUST handle purchase failures
|
|
40
|
-
|
|
41
|
-
### PROHIBITED
|
|
42
|
-
|
|
43
|
-
- **NEVER** call without valid userId
|
|
44
|
-
- **NEVER** call without isAnonymous parameter
|
|
45
|
-
- **DO NOT** proceed with purchase without auth check
|
|
46
|
-
- **DO NOT** ignore pending package state
|
|
47
|
-
|
|
48
|
-
### CRITICAL SAFETY
|
|
49
|
-
|
|
50
|
-
- **ALWAYS** check authentication status before purchase
|
|
51
|
-
- **MUST** handle pending package after auth
|
|
52
|
-
- **ALWAYS** provide clear auth flow for users
|
|
53
|
-
- **NEVER** allow anonymous purchases without auth
|
|
54
|
-
|
|
55
|
-
## AI Agent Guidelines
|
|
56
|
-
|
|
57
|
-
### When Implementing Paywall Operations
|
|
58
|
-
|
|
59
|
-
1. **Always** provide valid userId
|
|
60
|
-
2. **Always** provide isAnonymous status
|
|
61
|
-
3. **Always** implement onAuthRequired with pending package handling
|
|
62
|
-
4. **Always** implement onPurchaseSuccess callback
|
|
63
|
-
5. **Always** handle purchase and restore failures
|
|
64
|
-
|
|
65
|
-
### Integration Checklist
|
|
66
|
-
|
|
67
|
-
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
68
|
-
- [ ] Provide valid userId
|
|
69
|
-
- [ ] Provide isAnonymous status
|
|
70
|
-
- [ ] Implement onAuthRequired callback
|
|
71
|
-
- [ ] Implement onPurchaseSuccess callback
|
|
72
|
-
- [ ] Implement onPaywallClose callback
|
|
73
|
-
- [ ] Handle pending package state
|
|
74
|
-
- [ ] Test purchase with authenticated user
|
|
75
|
-
- [ ] Test purchase with anonymous user
|
|
76
|
-
- [ ] Test purchase flow after authentication
|
|
77
|
-
|
|
78
|
-
### Common Patterns
|
|
79
|
-
|
|
80
|
-
1. **Pending Purchase Flow**: Store package, show auth, complete purchase
|
|
81
|
-
2. **In-App Purchases**: Use handleInAppPurchase for modal paywalls
|
|
82
|
-
3. **Purchase Analytics**: Track purchase attempts and completions
|
|
83
|
-
4. **Error Recovery**: Handle failures and provide retry options
|
|
84
|
-
5. **Post-Onboarding**: Handle purchases after onboarding flow
|
|
85
|
-
|
|
86
|
-
## Related Documentation
|
|
87
|
-
|
|
88
|
-
- **usePremium**: For purchase and restore operations
|
|
89
|
-
- **useAuthAwarePurchase**: For auth-gated purchases
|
|
90
|
-
- **usePaywallVisibility**: For paywall visibility control
|
|
91
|
-
- **Paywall Screen**: `src/presentation/screens/README.md`
|
|
92
|
-
- **Purchase Flow**: `src/docs/PURCHASE_FLOW.md`
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# usePaywallVisibility Hook
|
|
2
|
-
|
|
3
|
-
Simple global state management for paywall visibility using external store.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Import Path**: `@umituz/react-native-subscription`
|
|
8
|
-
|
|
9
|
-
**File**: `src/presentation/hooks/usePaywallVisibility.ts`
|
|
10
|
-
|
|
11
|
-
**Type**: Hook
|
|
12
|
-
|
|
13
|
-
## Strategy
|
|
14
|
-
|
|
15
|
-
### Global Paywall State Management
|
|
16
|
-
|
|
17
|
-
1. **External Store**: Use Zustand or similar for global state
|
|
18
|
-
2. **Visibility Control**: Simple boolean for show/hide
|
|
19
|
-
3. **Global Access**: Available from any component
|
|
20
|
-
4. **Direct Control**: Provide paywallControl for non-React contexts
|
|
21
|
-
5. **Single Instance**: One paywall modal at app root
|
|
22
|
-
6. **State Persistence**: Maintain visibility across component unmounts
|
|
23
|
-
|
|
24
|
-
### Integration Points
|
|
25
|
-
|
|
26
|
-
- **App Root**: Paywall modal should be placed at app root
|
|
27
|
-
- **Any Component**: Can trigger paywall from anywhere
|
|
28
|
-
- **Deep Links**: Can open paywall from URLs
|
|
29
|
-
- **Push Notifications**: Can open paywall from notifications
|
|
30
|
-
- **usePremium**: For conditional display based on status
|
|
31
|
-
|
|
32
|
-
## Restrictions
|
|
33
|
-
|
|
34
|
-
### REQUIRED
|
|
35
|
-
|
|
36
|
-
- **Single Modal**: MUST place paywall modal once at app root
|
|
37
|
-
- **Close Handler**: MUST provide close button in paywall
|
|
38
|
-
- **Premium Check**: SHOULD hide paywall when user becomes premium
|
|
39
|
-
- **Back Handler**: SHOULD handle Android back button
|
|
40
|
-
|
|
41
|
-
### PROHIBITED
|
|
42
|
-
|
|
43
|
-
- **NEVER** place multiple paywall modals in component tree
|
|
44
|
-
- **NEVER** manage visibility locally (use this hook instead)
|
|
45
|
-
- **DO NOT** show paywall too frequently
|
|
46
|
-
- **DO NOT** trap users without exit option
|
|
47
|
-
|
|
48
|
-
### CRITICAL SAFETY
|
|
49
|
-
|
|
50
|
-
- **ALWAYS** provide close button
|
|
51
|
-
- **NEVER** trap users in paywall
|
|
52
|
-
- **MUST** handle back button on Android
|
|
53
|
-
- **ALWAYS** hide paywall after successful purchase
|
|
54
|
-
|
|
55
|
-
## AI Agent Guidelines
|
|
56
|
-
|
|
57
|
-
### When Implementing Paywall Visibility
|
|
58
|
-
|
|
59
|
-
1. **Always** place paywall modal once at app root
|
|
60
|
-
2. **Always** provide close button
|
|
61
|
-
3. **Always** use openPaywall/closePaywall functions
|
|
62
|
-
4. **Always** hide paywall after successful purchase
|
|
63
|
-
5. **Never** manage visibility locally in components
|
|
64
|
-
|
|
65
|
-
### Integration Checklist
|
|
66
|
-
|
|
67
|
-
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
68
|
-
- [ ] Place paywall modal once at app root
|
|
69
|
-
- [ ] Use openPaywall to show paywall
|
|
70
|
-
- [ ] Use closePaywall to hide paywall
|
|
71
|
-
- [ ] Provide close button in paywall
|
|
72
|
-
- [ ] Handle Android back button
|
|
73
|
-
- [ ] Hide paywall when user becomes premium
|
|
74
|
-
- [ ] Test paywall opens from any component
|
|
75
|
-
- [ ] Test paywallControl for non-React contexts
|
|
76
|
-
- [ ] Test deep link integration
|
|
77
|
-
|
|
78
|
-
### Common Patterns
|
|
79
|
-
|
|
80
|
-
1. **App Root Setup**: Single modal instance at app root
|
|
81
|
-
2. **Trigger Button**: Any component can open paywall
|
|
82
|
-
3. **Direct Control**: Use paywallControl in non-React code
|
|
83
|
-
4. **Conditional Display**: Auto-show based on user status
|
|
84
|
-
5. **History/Navigation**: Handle navigation with paywall
|
|
85
|
-
6. **Timeout/Auto-Close**: Auto-close after timeout
|
|
86
|
-
7. **Deep Links**: Open from URL schemes
|
|
87
|
-
|
|
88
|
-
## Related Documentation
|
|
89
|
-
|
|
90
|
-
- **usePaywallOperations**: For paywall purchase operations
|
|
91
|
-
- **usePremium**: For subscription status
|
|
92
|
-
- **usePaywall**: For complete paywall management
|
|
93
|
-
- **Paywall Screen**: `src/presentation/screens/README.md`
|
|
94
|
-
- **Paywall Components**: `src/presentation/components/paywall/README.md`
|
|
95
|
-
- **Modal Integration**: `src/docs/MODAL_INTEGRATION.md`
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
# usePremium Hook
|
|
2
|
-
|
|
3
|
-
Hook for checking and managing premium subscription status.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Import Path**: `@umituz/react-native-subscription`
|
|
8
|
-
|
|
9
|
-
**File**: `src/presentation/hooks/usePremium.ts`
|
|
10
|
-
|
|
11
|
-
**Type**: Hook
|
|
12
|
-
|
|
13
|
-
## Strategy
|
|
14
|
-
|
|
15
|
-
### Premium Status Flow
|
|
16
|
-
|
|
17
|
-
1. **Initial Check**: Fetch current subscription status from repository
|
|
18
|
-
2. **Status Evaluation**: Determine if user has active premium subscription
|
|
19
|
-
3. **Real-time Updates**: Automatically update when user logs in/out or subscription changes
|
|
20
|
-
4. **Caching**: Cache status for 5 minutes (configurable) to reduce API calls
|
|
21
|
-
5. **Loading States**: Provide loading indicators during data fetch
|
|
22
|
-
6. **Error Handling**: Handle fetch errors gracefully
|
|
23
|
-
|
|
24
|
-
### Integration Points
|
|
25
|
-
|
|
26
|
-
- **Subscription Repository**: `src/infrastructure/repositories/SubscriptionRepository.ts`
|
|
27
|
-
- **TanStack Query**: For caching and real-time updates
|
|
28
|
-
- **Auth Context**: Sync with user authentication state
|
|
29
|
-
- **RevenueCat**: For subscription data source
|
|
30
|
-
|
|
31
|
-
## Restrictions
|
|
32
|
-
|
|
33
|
-
### REQUIRED
|
|
34
|
-
|
|
35
|
-
- **Loading State**: MUST handle loading state in UI
|
|
36
|
-
- **Error Handling**: MUST handle error state
|
|
37
|
-
- **Check Before Access**: MUST verify isPremium before showing premium features
|
|
38
|
-
|
|
39
|
-
### PROHIBITED
|
|
40
|
-
|
|
41
|
-
- **NEVER** use for security decisions (server-side validation required)
|
|
42
|
-
- **NEVER** assume instant data availability (always check loading state)
|
|
43
|
-
- **DO NOT** use for anonymous users without proper handling
|
|
44
|
-
|
|
45
|
-
### CRITICAL SAFETY
|
|
46
|
-
|
|
47
|
-
- **ALWAYS** handle loading state before rendering premium content
|
|
48
|
-
- **NEVER** trust client-side state for security enforcement
|
|
49
|
-
- **MUST** implement error boundaries when using this hook
|
|
50
|
-
|
|
51
|
-
## AI Agent Guidelines
|
|
52
|
-
|
|
53
|
-
### When Implementing Premium Features
|
|
54
|
-
|
|
55
|
-
1. **Always** check loading state first
|
|
56
|
-
2. **Always** handle error state
|
|
57
|
-
3. **Always** verify isPremium before showing premium content
|
|
58
|
-
4. **Never** use for security decisions without server validation
|
|
59
|
-
5. **Always** provide upgrade path for non-premium users
|
|
60
|
-
|
|
61
|
-
### Integration Checklist
|
|
62
|
-
|
|
63
|
-
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
64
|
-
- [ ] Handle loading state (show ActivityIndicator or skeleton)
|
|
65
|
-
- [ ] Handle error state (show error message)
|
|
66
|
-
- [ ] Check isPremium before rendering premium content
|
|
67
|
-
- [ ] Provide upgrade path for free users
|
|
68
|
-
- [ ] Test with premium user
|
|
69
|
-
- [ ] Test with free user
|
|
70
|
-
- [ ] Test with anonymous user
|
|
71
|
-
- [ ] Test offline scenario
|
|
72
|
-
|
|
73
|
-
### Common Patterns
|
|
74
|
-
|
|
75
|
-
1. **Conditional Rendering**: Show/hide features based on isPremium
|
|
76
|
-
2. **Premium Badge**: Display premium status badge
|
|
77
|
-
3. **Feature Gating**: Use usePremiumGate instead of manual checks
|
|
78
|
-
4. **Status Display**: Show subscription details with useSubscriptionDetails
|
|
79
|
-
5. **Upgrade Prompts**: Guide free users to paywall
|
|
80
|
-
|
|
81
|
-
## Related Documentation
|
|
82
|
-
|
|
83
|
-
- **usePremiumGate**: Gating premium features
|
|
84
|
-
- **useSubscription**: Detailed subscription status
|
|
85
|
-
- **useSubscriptionStatus**: Subscription status details
|
|
86
|
-
- **usePremiumWithCredits**: Hybrid premium/credits access
|
|
87
|
-
- **Subscription Repository**: `src/infrastructure/repositories/README.md`
|
|
88
|
-
- **Domain Layer**: `src/domain/README.md`
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# useSubscriptionSettingsConfig Hook
|
|
2
|
-
|
|
3
|
-
Returns ready-to-use configuration for subscription settings screens.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Import Path**: `@umituz/react-native-subscription`
|
|
8
|
-
|
|
9
|
-
**File**: `src/presentation/hooks/useSubscriptionSettingsConfig.ts`
|
|
10
|
-
|
|
11
|
-
**Type**: Hook
|
|
12
|
-
|
|
13
|
-
## Strategy
|
|
14
|
-
|
|
15
|
-
### Settings Configuration Generation
|
|
16
|
-
|
|
17
|
-
1. **Data Aggregation**: Combine subscription, credits, and tier information
|
|
18
|
-
2. **Status Determination**: Calculate status type (active/expired/free/canceled)
|
|
19
|
-
3. **Date Formatting**: Format expiration and purchase dates
|
|
20
|
-
4. **Credit Items**: Generate credit item list with optional limit
|
|
21
|
-
5. **Translation Support**: Apply provided translations to all strings
|
|
22
|
-
6. **Upgrade Prompt**: Optional upgrade prompt configuration
|
|
23
|
-
|
|
24
|
-
### Integration Points
|
|
25
|
-
|
|
26
|
-
- **useSubscriptionStatus**: For subscription status details
|
|
27
|
-
- **useCredits**: For credits information
|
|
28
|
-
- **useUserTier**: For tier determination
|
|
29
|
-
- **Settings UI**: For settings screen integration
|
|
30
|
-
- **Translation System**: For localization support
|
|
31
|
-
|
|
32
|
-
## Restrictions
|
|
33
|
-
|
|
34
|
-
### REQUIRED
|
|
35
|
-
|
|
36
|
-
- **User ID**: MUST provide valid userId parameter
|
|
37
|
-
- **Translations**: MUST provide all translation strings
|
|
38
|
-
- **Null Handling**: MUST handle null dates and values
|
|
39
|
-
- **Enabled Check**: MUST check config.enabled before use
|
|
40
|
-
|
|
41
|
-
### PROHIBITED
|
|
42
|
-
|
|
43
|
-
- **NEVER** use without providing all translations
|
|
44
|
-
- **NEVER** assume config is enabled (check enabled flag)
|
|
45
|
-
- **DO NOT** hardcode translation strings
|
|
46
|
-
- **DO NOT** use without userId
|
|
47
|
-
|
|
48
|
-
### CRITICAL SAFETY
|
|
49
|
-
|
|
50
|
-
- **ALWAYS** check config.enabled before rendering
|
|
51
|
-
- **MUST** provide complete translation objects
|
|
52
|
-
- **ALWAYS** handle null dates gracefully
|
|
53
|
-
- **NEVER** trust client-side config for security
|
|
54
|
-
|
|
55
|
-
## AI Agent Guidelines
|
|
56
|
-
|
|
57
|
-
### When Implementing Settings Config
|
|
58
|
-
|
|
59
|
-
1. **Always** provide complete translations
|
|
60
|
-
2. **Always** check config.enabled
|
|
61
|
-
3. **Always** handle null dates
|
|
62
|
-
4. **Always** format dates appropriately
|
|
63
|
-
5. **Never** use for security decisions without server validation
|
|
64
|
-
|
|
65
|
-
### Integration Checklist
|
|
66
|
-
|
|
67
|
-
- [ ] Import from correct path: `@umituz/react-native-subscription`
|
|
68
|
-
- [ ] Provide valid userId
|
|
69
|
-
- [ ] Provide complete translations
|
|
70
|
-
- [ ] Check config.enabled
|
|
71
|
-
- [ ] Handle null dates
|
|
72
|
-
- [ ] Format dates appropriately
|
|
73
|
-
- [ ] Apply credit limit if needed
|
|
74
|
-
- [ ] Configure upgrade prompt if needed
|
|
75
|
-
- [ ] Test with active subscription
|
|
76
|
-
- [ ] Test with expired subscription
|
|
77
|
-
- [ ] Test with free user
|
|
78
|
-
- [ ] Test with lifetime subscription
|
|
79
|
-
|
|
80
|
-
### Common Patterns
|
|
81
|
-
|
|
82
|
-
1. **Settings List Item**: Quick access item in settings
|
|
83
|
-
2. **Detailed Section**: Comprehensive subscription section
|
|
84
|
-
3. **Localized Settings**: Use with translation libraries
|
|
85
|
-
4. **Credit Limit**: Limit displayed credit items
|
|
86
|
-
5. **Upgrade Prompt**: Show upgrade prompt for free users
|
|
87
|
-
|
|
88
|
-
## Related Documentation
|
|
89
|
-
|
|
90
|
-
- **useSubscriptionStatus**: For subscription status details
|
|
91
|
-
- **useCredits**: For credits information
|
|
92
|
-
- **useSubscriptionDetails**: For package and pricing info
|
|
93
|
-
- **Settings Screen**: `src/presentation/screens/README.md`
|
|
94
|
-
- **Subscription Utilities**: `src/utils/subscriptionDateUtils.md`
|