@umituz/react-native-subscription 2.14.60 → 2.14.62
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.62",
|
|
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",
|
|
@@ -20,6 +20,8 @@ export interface CreditsConfig {
|
|
|
20
20
|
imageCreditLimit: number;
|
|
21
21
|
/** When true, stores credits at users/{userId}/credits instead of {collectionName}/{userId} */
|
|
22
22
|
useUserSubcollection?: boolean;
|
|
23
|
+
/** Credit amounts per product ID for consumable credit packages */
|
|
24
|
+
creditPackageAmounts?: Record<string, number>;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export interface CreditsResult<T = UserCredits> {
|
|
@@ -25,6 +25,8 @@ import { initializeCreditsTransaction } from "../services/CreditsInitializer";
|
|
|
25
25
|
import { detectPackageType } from "../../utils/packageTypeDetector";
|
|
26
26
|
import { getCreditAllocation } from "../../utils/creditMapper";
|
|
27
27
|
|
|
28
|
+
declare const __DEV__: boolean;
|
|
29
|
+
|
|
28
30
|
export class CreditsRepository extends BaseRepository {
|
|
29
31
|
private config: CreditsConfig;
|
|
30
32
|
|
|
@@ -35,7 +37,8 @@ export class CreditsRepository extends BaseRepository {
|
|
|
35
37
|
|
|
36
38
|
private getCreditsDocRef(db: Firestore, userId: string) {
|
|
37
39
|
if (this.config.useUserSubcollection) {
|
|
38
|
-
|
|
40
|
+
// Path: users/{userId} - credits stored directly on user document
|
|
41
|
+
return doc(db, "users", userId);
|
|
39
42
|
}
|
|
40
43
|
return doc(db, this.config.collectionName, userId);
|
|
41
44
|
}
|
|
@@ -98,15 +101,31 @@ export class CreditsRepository extends BaseRepository {
|
|
|
98
101
|
let configToUse = this.config;
|
|
99
102
|
|
|
100
103
|
if (productId) {
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
if (
|
|
104
|
+
// First check credit package amounts (for consumable credit packages)
|
|
105
|
+
const creditPackageAmount = this.config.creditPackageAmounts?.[productId];
|
|
106
|
+
|
|
107
|
+
if (creditPackageAmount) {
|
|
108
|
+
// Credit package: use the configured amount
|
|
109
|
+
if (__DEV__) {
|
|
110
|
+
console.log("[CreditsRepository] Credit package detected:", { productId, amount: creditPackageAmount });
|
|
111
|
+
}
|
|
105
112
|
configToUse = {
|
|
106
113
|
...this.config,
|
|
107
|
-
imageCreditLimit:
|
|
108
|
-
textCreditLimit:
|
|
114
|
+
imageCreditLimit: creditPackageAmount,
|
|
115
|
+
textCreditLimit: creditPackageAmount,
|
|
109
116
|
};
|
|
117
|
+
} else {
|
|
118
|
+
// Subscription package: use package type detection
|
|
119
|
+
const packageType = detectPackageType(productId);
|
|
120
|
+
const allocation = getCreditAllocation(packageType);
|
|
121
|
+
|
|
122
|
+
if (allocation) {
|
|
123
|
+
configToUse = {
|
|
124
|
+
...this.config,
|
|
125
|
+
imageCreditLimit: allocation.imageCredits,
|
|
126
|
+
textCreditLimit: allocation.textCredits,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
110
129
|
}
|
|
111
130
|
}
|
|
112
131
|
|
|
@@ -53,14 +53,17 @@ export async function initializeCreditsTransaction(
|
|
|
53
53
|
processedPurchases = [...processedPurchases, purchaseId].slice(-10);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
const creditsData = {
|
|
57
57
|
textCredits: newTextCredits,
|
|
58
58
|
imageCredits: newImageCredits,
|
|
59
59
|
purchasedAt,
|
|
60
60
|
lastUpdatedAt: now,
|
|
61
61
|
lastPurchaseAt: now,
|
|
62
62
|
processedPurchases,
|
|
63
|
-
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Use merge:true to avoid overwriting other user fields
|
|
66
|
+
transaction.set(creditsRef, creditsData, { merge: true });
|
|
64
67
|
|
|
65
68
|
return { textCredits: newTextCredits, imageCredits: newImageCredits };
|
|
66
69
|
});
|
|
@@ -99,7 +99,12 @@ export const initializeSubscription = async (
|
|
|
99
99
|
throw new Error("RevenueCat API key is required");
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
// Merge credit package amounts into credits config
|
|
103
|
+
const creditsConfigWithPackages = {
|
|
104
|
+
...credits,
|
|
105
|
+
creditPackageAmounts: creditPackages?.amounts,
|
|
106
|
+
};
|
|
107
|
+
configureCreditsRepository(creditsConfigWithPackages);
|
|
103
108
|
|
|
104
109
|
// Build consumable product identifiers from credit package pattern
|
|
105
110
|
const consumableIdentifiers: string[] = [];
|