@umituz/react-native-subscription 2.17.8 → 2.17.10
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/domain/entities/Credits.ts +0 -2
- package/src/domains/paywall/hooks/usePaywallActions.ts +1 -0
- package/src/infrastructure/mappers/CreditsMapper.ts +0 -2
- package/src/infrastructure/models/UserCreditsDocument.ts +0 -2
- package/src/infrastructure/repositories/CreditsRepository.ts +1 -1
- package/src/infrastructure/services/CreditsInitializer.ts +1 -5
- package/src/presentation/hooks/useSubscriptionSettingsConfig.ts +15 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.17.
|
|
3
|
+
"version": "2.17.10",
|
|
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",
|
|
@@ -7,8 +7,6 @@ export class CreditsMapper {
|
|
|
7
7
|
credits: snapData.credits,
|
|
8
8
|
purchasedAt: snapData.purchasedAt?.toDate?.() || null,
|
|
9
9
|
lastUpdatedAt: snapData.lastUpdatedAt?.toDate?.() || null,
|
|
10
|
-
activeProductId: snapData.activeProductId,
|
|
11
|
-
activeCreditLimit: snapData.activeCreditLimit,
|
|
12
10
|
};
|
|
13
11
|
}
|
|
14
12
|
|
|
@@ -46,7 +46,7 @@ export class CreditsRepository extends BaseRepository {
|
|
|
46
46
|
if (dynamicLimit !== null) cfg = { ...cfg, creditLimit: dynamicLimit };
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
const res = await initializeCreditsTransaction(db, this.getRef(db, userId), cfg, purchaseId
|
|
49
|
+
const res = await initializeCreditsTransaction(db, this.getRef(db, userId), cfg, purchaseId);
|
|
50
50
|
return {
|
|
51
51
|
success: true,
|
|
52
52
|
data: CreditsMapper.toEntity({
|
|
@@ -17,8 +17,7 @@ export async function initializeCreditsTransaction(
|
|
|
17
17
|
db: Firestore,
|
|
18
18
|
creditsRef: DocumentReference,
|
|
19
19
|
config: CreditsConfig,
|
|
20
|
-
purchaseId?: string
|
|
21
|
-
productId?: string
|
|
20
|
+
purchaseId?: string
|
|
22
21
|
): Promise<InitializationResult> {
|
|
23
22
|
return runTransaction(db, async (transaction: Transaction) => {
|
|
24
23
|
const creditsDoc = await transaction.get(creditsRef);
|
|
@@ -56,11 +55,8 @@ export async function initializeCreditsTransaction(
|
|
|
56
55
|
lastUpdatedAt: now,
|
|
57
56
|
lastPurchaseAt: now,
|
|
58
57
|
processedPurchases,
|
|
59
|
-
activeProductId: productId || undefined,
|
|
60
|
-
activeCreditLimit: config.creditLimit,
|
|
61
58
|
};
|
|
62
59
|
|
|
63
|
-
// Use merge:true to avoid overwriting other user fields
|
|
64
60
|
transaction.set(creditsRef, creditsData, { merge: true });
|
|
65
61
|
|
|
66
62
|
return { credits: newCredits };
|
|
@@ -64,17 +64,23 @@ export const useSubscriptionSettingsConfig = (
|
|
|
64
64
|
const isPremium = !!premiumEntitlement || subscriptionActive;
|
|
65
65
|
|
|
66
66
|
const dynamicCreditLimit = useMemo(() => {
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const config = getCreditsConfig();
|
|
68
|
+
|
|
69
|
+
if (premiumEntitlement?.productIdentifier) {
|
|
70
|
+
const packageType = detectPackageType(premiumEntitlement.productIdentifier);
|
|
71
|
+
const allocation = getCreditAllocation(packageType, config.packageAllocations);
|
|
72
|
+
if (allocation !== null) return allocation;
|
|
69
73
|
}
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
|
|
75
|
+
if (credits?.credits && config.packageAllocations) {
|
|
76
|
+
const currentCredits = credits.credits;
|
|
77
|
+
const allocations = Object.values(config.packageAllocations).map(a => a.credits);
|
|
78
|
+
const closest = allocations.find(a => a >= currentCredits) || Math.max(...allocations);
|
|
79
|
+
return closest;
|
|
72
80
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return allocation ?? creditLimit ?? config.creditLimit;
|
|
77
|
-
}, [credits?.activeCreditLimit, premiumEntitlement?.productIdentifier, creditLimit]);
|
|
81
|
+
|
|
82
|
+
return creditLimit ?? config.creditLimit;
|
|
83
|
+
}, [premiumEntitlement?.productIdentifier, credits?.credits, creditLimit]);
|
|
78
84
|
|
|
79
85
|
// Get expiration date directly from RevenueCat (source of truth)
|
|
80
86
|
const entitlementExpirationDate = premiumEntitlement?.expirationDate ?? null;
|