@umituz/react-native-subscription 2.14.98 → 2.14.99
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 +0 -1
- package/package.json +1 -1
- package/src/domains/README.md +240 -0
- package/src/domains/config/domain/README.md +390 -0
- package/src/domains/config/domain/entities/README.md +350 -0
- package/src/presentation/hooks/useDeductCredit.md +146 -130
- package/src/revenuecat/application/README.md +158 -0
- package/src/revenuecat/application/ports/README.md +169 -0
- package/src/revenuecat/domain/constants/README.md +183 -0
- package/src/revenuecat/domain/entities/README.md +382 -0
- package/src/revenuecat/domain/types/README.md +373 -0
- package/src/revenuecat/domain/value-objects/README.md +441 -0
- package/src/revenuecat/infrastructure/README.md +50 -0
- package/src/revenuecat/infrastructure/handlers/README.md +218 -0
- package/src/revenuecat/infrastructure/services/README.md +325 -0
- package/src/revenuecat/infrastructure/utils/README.md +382 -0
- package/src/revenuecat/presentation/README.md +184 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# RevenueCat Presentation
|
|
2
|
+
|
|
3
|
+
Presentation layer for RevenueCat integration.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This directory contains React hooks, components, and utilities for integrating RevenueCat functionality into the UI layer.
|
|
8
|
+
|
|
9
|
+
## Components
|
|
10
|
+
|
|
11
|
+
This directory may contain:
|
|
12
|
+
|
|
13
|
+
### Hooks
|
|
14
|
+
|
|
15
|
+
Custom React hooks for RevenueCat operations.
|
|
16
|
+
|
|
17
|
+
**Potential Hooks:**
|
|
18
|
+
- `useRevenueCatCustomerInfo` - Fetch and monitor customer info
|
|
19
|
+
- `useRevenueCatOfferings` - Fetch available offerings
|
|
20
|
+
- `useRevenueCatPurchase` - Handle purchase flow
|
|
21
|
+
- `useRevenueCatEntitlement` - Check entitlement status
|
|
22
|
+
|
|
23
|
+
**Example:**
|
|
24
|
+
```typescript
|
|
25
|
+
function useRevenueCatOfferings() {
|
|
26
|
+
const [offerings, setOfferings] = useState<Offerings | null>(null);
|
|
27
|
+
const [loading, setLoading] = useState(true);
|
|
28
|
+
const [error, setError] = useState<Error | null>(null);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
loadOfferings();
|
|
32
|
+
}, []);
|
|
33
|
+
|
|
34
|
+
const loadOfferings = async () => {
|
|
35
|
+
try {
|
|
36
|
+
setLoading(true);
|
|
37
|
+
const service = getRevenueCatService();
|
|
38
|
+
const result = await service.getOfferings();
|
|
39
|
+
setOfferings(result);
|
|
40
|
+
} catch (err) {
|
|
41
|
+
setError(err as Error);
|
|
42
|
+
} finally {
|
|
43
|
+
setLoading(false);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return { offerings, loading, error, refetch: loadOfferings };
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Components
|
|
52
|
+
|
|
53
|
+
React components for displaying RevenueCat data.
|
|
54
|
+
|
|
55
|
+
**Potential Components:**
|
|
56
|
+
- `PackageList` - Display available packages
|
|
57
|
+
- `PackageCard` - Display individual package
|
|
58
|
+
- `EntitlementBadge` - Show entitlement status
|
|
59
|
+
- `SubscriptionStatus` - Display subscription status
|
|
60
|
+
|
|
61
|
+
**Example:**
|
|
62
|
+
```typescript
|
|
63
|
+
function PackageCard({
|
|
64
|
+
package,
|
|
65
|
+
onPress,
|
|
66
|
+
highlight = false,
|
|
67
|
+
}: {
|
|
68
|
+
package: Package;
|
|
69
|
+
onPress: () => void;
|
|
70
|
+
highlight?: boolean;
|
|
71
|
+
}) {
|
|
72
|
+
return (
|
|
73
|
+
<TouchableOpacity
|
|
74
|
+
onPress={onPress}
|
|
75
|
+
style={[styles.card, highlight && styles.highlight]}
|
|
76
|
+
>
|
|
77
|
+
<Text style={styles.title}>
|
|
78
|
+
{package.product.title}
|
|
79
|
+
</Text>
|
|
80
|
+
<Text style={styles.price}>
|
|
81
|
+
{package.localizedPriceString}
|
|
82
|
+
</Text>
|
|
83
|
+
{package.product.description && (
|
|
84
|
+
<Text style={styles.description}>
|
|
85
|
+
{package.product.description}
|
|
86
|
+
</Text>
|
|
87
|
+
)}
|
|
88
|
+
</TouchableOpacity>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Usage Patterns
|
|
94
|
+
|
|
95
|
+
### Displaying Offerings
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { useRevenueCatOfferings } from './hooks/useRevenueCatOfferings';
|
|
99
|
+
import { PackageCard } from './components/PackageCard';
|
|
100
|
+
|
|
101
|
+
function PremiumPackages() {
|
|
102
|
+
const { offerings, loading, error } = useRevenueCatOfferings();
|
|
103
|
+
|
|
104
|
+
if (loading) return <LoadingSpinner />;
|
|
105
|
+
if (error) return <Error message={error.message} />;
|
|
106
|
+
if (!offerings?.current) return <EmptyState />;
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<ScrollView horizontal>
|
|
110
|
+
{offerings.current.availablePackages.map(pkg => (
|
|
111
|
+
<PackageCard
|
|
112
|
+
key={pkg.identifier}
|
|
113
|
+
package={pkg}
|
|
114
|
+
onPress={() => handlePurchase(pkg)}
|
|
115
|
+
highlight={pkg.packageType === 'annual'}
|
|
116
|
+
/>
|
|
117
|
+
))}
|
|
118
|
+
</ScrollView>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Checking Entitlements
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { useRevenueCatCustomerInfo } from './hooks/useRevenueCatCustomerInfo';
|
|
127
|
+
|
|
128
|
+
function PremiumContent() {
|
|
129
|
+
const { customerInfo, loading } = useRevenueCatCustomerInfo();
|
|
130
|
+
|
|
131
|
+
if (loading) return <LoadingSpinner />;
|
|
132
|
+
|
|
133
|
+
const hasPremium = customerInfo?.entitlements.premium?.isActive ?? false;
|
|
134
|
+
|
|
135
|
+
if (!hasPremium) {
|
|
136
|
+
return <UpgradePrompt />;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return <PremiumFeatures />;
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Purchase Flow
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { useRevenueCatPurchase } from './hooks/useRevenueCatPurchase';
|
|
147
|
+
|
|
148
|
+
function PurchaseButton({ package }: { package: Package }) {
|
|
149
|
+
const { purchase, purchasing } = useRevenueCatPurchase();
|
|
150
|
+
|
|
151
|
+
const handlePurchase = async () => {
|
|
152
|
+
const result = await purchase(package);
|
|
153
|
+
|
|
154
|
+
if (result.error) {
|
|
155
|
+
Alert.alert('Purchase Failed', result.error.message);
|
|
156
|
+
} else {
|
|
157
|
+
Alert.alert('Success', 'Purchase completed!');
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<Button onPress={handlePurchase} disabled={purchasing}>
|
|
163
|
+
{purchasing ? 'Purchasing...' : 'Subscribe'}
|
|
164
|
+
</Button>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Best Practices
|
|
170
|
+
|
|
171
|
+
1. **Loading States**: Always show loading states during async operations
|
|
172
|
+
2. **Error Handling**: Handle and display errors appropriately
|
|
173
|
+
3. **Optimistic Updates**: Update UI optimistically where possible
|
|
174
|
+
4. **Caching**: Cache customer info and offerings
|
|
175
|
+
5. **Reactivity**: Re-render on entitlement changes
|
|
176
|
+
6. **User Feedback**: Provide clear feedback during purchases
|
|
177
|
+
7. **Validation**: Validate data before displaying
|
|
178
|
+
|
|
179
|
+
## Related
|
|
180
|
+
|
|
181
|
+
- [RevenueCat Integration](../README.md)
|
|
182
|
+
- [RevenueCat Application](../application/README.md)
|
|
183
|
+
- [RevenueCat Infrastructure](../infrastructure/README.md)
|
|
184
|
+
- [RevenueCat Domain](../domain/README.md)
|