@umituz/react-native-subscription 2.17.7 → 2.17.8
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 +2 -0
- package/src/infrastructure/mappers/CreditsMapper.ts +2 -0
- package/src/infrastructure/models/UserCreditsDocument.ts +2 -0
- package/src/infrastructure/repositories/CreditsRepository.ts +4 -4
- package/src/infrastructure/services/CreditsInitializer.ts +4 -1
- package/src/presentation/hooks/useSubscriptionSettingsConfig.ts +4 -1
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.8",
|
|
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,6 +7,8 @@ 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,
|
|
10
12
|
};
|
|
11
13
|
}
|
|
12
14
|
|
|
@@ -46,14 +46,14 @@ 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);
|
|
50
|
-
return {
|
|
51
|
-
success: true,
|
|
49
|
+
const res = await initializeCreditsTransaction(db, this.getRef(db, userId), cfg, purchaseId, productId);
|
|
50
|
+
return {
|
|
51
|
+
success: true,
|
|
52
52
|
data: CreditsMapper.toEntity({
|
|
53
53
|
...res,
|
|
54
54
|
purchasedAt: undefined,
|
|
55
55
|
lastUpdatedAt: undefined,
|
|
56
|
-
})
|
|
56
|
+
})
|
|
57
57
|
};
|
|
58
58
|
} catch (e: any) { return { success: false, error: { message: e.message, code: "INIT_ERR" } }; }
|
|
59
59
|
}
|
|
@@ -17,7 +17,8 @@ export async function initializeCreditsTransaction(
|
|
|
17
17
|
db: Firestore,
|
|
18
18
|
creditsRef: DocumentReference,
|
|
19
19
|
config: CreditsConfig,
|
|
20
|
-
purchaseId?: string
|
|
20
|
+
purchaseId?: string,
|
|
21
|
+
productId?: string
|
|
21
22
|
): Promise<InitializationResult> {
|
|
22
23
|
return runTransaction(db, async (transaction: Transaction) => {
|
|
23
24
|
const creditsDoc = await transaction.get(creditsRef);
|
|
@@ -55,6 +56,8 @@ export async function initializeCreditsTransaction(
|
|
|
55
56
|
lastUpdatedAt: now,
|
|
56
57
|
lastPurchaseAt: now,
|
|
57
58
|
processedPurchases,
|
|
59
|
+
activeProductId: productId || undefined,
|
|
60
|
+
activeCreditLimit: config.creditLimit,
|
|
58
61
|
};
|
|
59
62
|
|
|
60
63
|
// Use merge:true to avoid overwriting other user fields
|
|
@@ -64,6 +64,9 @@ export const useSubscriptionSettingsConfig = (
|
|
|
64
64
|
const isPremium = !!premiumEntitlement || subscriptionActive;
|
|
65
65
|
|
|
66
66
|
const dynamicCreditLimit = useMemo(() => {
|
|
67
|
+
if (credits?.activeCreditLimit) {
|
|
68
|
+
return credits.activeCreditLimit;
|
|
69
|
+
}
|
|
67
70
|
if (!premiumEntitlement?.productIdentifier) {
|
|
68
71
|
return creditLimit;
|
|
69
72
|
}
|
|
@@ -71,7 +74,7 @@ export const useSubscriptionSettingsConfig = (
|
|
|
71
74
|
const packageType = detectPackageType(premiumEntitlement.productIdentifier);
|
|
72
75
|
const allocation = getCreditAllocation(packageType, config.packageAllocations);
|
|
73
76
|
return allocation ?? creditLimit ?? config.creditLimit;
|
|
74
|
-
}, [premiumEntitlement?.productIdentifier, creditLimit]);
|
|
77
|
+
}, [credits?.activeCreditLimit, premiumEntitlement?.productIdentifier, creditLimit]);
|
|
75
78
|
|
|
76
79
|
// Get expiration date directly from RevenueCat (source of truth)
|
|
77
80
|
const entitlementExpirationDate = premiumEntitlement?.expirationDate ?? null;
|