@umituz/react-native-subscription 2.14.58 → 2.14.59
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.59",
|
|
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",
|
|
@@ -30,8 +30,8 @@ export interface SubscriptionInitConfig {
|
|
|
30
30
|
getAnonymousUserId: () => Promise<string>;
|
|
31
31
|
getFirebaseAuth: () => FirebaseAuthLike | null;
|
|
32
32
|
showAuthModal: () => void;
|
|
33
|
+
/** Callback after credits are updated (for cache invalidation) */
|
|
33
34
|
onCreditsUpdated?: (userId: string) => void;
|
|
34
|
-
onCreditRenewal?: (userId: string, productId: string, renewalId: string) => Promise<void>;
|
|
35
35
|
/** Credit package configuration for consumable purchases */
|
|
36
36
|
creditPackages?: CreditPackageConfig;
|
|
37
37
|
timeoutMs?: number;
|
|
@@ -90,7 +90,6 @@ export const initializeSubscription = async (
|
|
|
90
90
|
getFirebaseAuth,
|
|
91
91
|
showAuthModal,
|
|
92
92
|
onCreditsUpdated,
|
|
93
|
-
onCreditRenewal,
|
|
94
93
|
creditPackages,
|
|
95
94
|
timeoutMs = 10000,
|
|
96
95
|
authStateTimeoutMs = 2000,
|
|
@@ -124,8 +123,6 @@ export const initializeSubscription = async (
|
|
|
124
123
|
|
|
125
124
|
try {
|
|
126
125
|
const repository = getCreditsRepository();
|
|
127
|
-
|
|
128
|
-
// Create a unique purchase ID to prevent duplicate credit additions
|
|
129
126
|
const purchaseId = `purchase_${productId}_${Date.now()}`;
|
|
130
127
|
|
|
131
128
|
await repository.initializeCredits(userId, purchaseId, productId);
|
|
@@ -138,7 +135,6 @@ export const initializeSubscription = async (
|
|
|
138
135
|
});
|
|
139
136
|
}
|
|
140
137
|
|
|
141
|
-
// Notify about credits update for cache invalidation
|
|
142
138
|
if (onCreditsUpdated) {
|
|
143
139
|
onCreditsUpdated(userId);
|
|
144
140
|
}
|
|
@@ -149,13 +145,41 @@ export const initializeSubscription = async (
|
|
|
149
145
|
}
|
|
150
146
|
};
|
|
151
147
|
|
|
148
|
+
// Create onCreditRenewal handler for subscription renewals
|
|
149
|
+
const handleCreditRenewal = async (
|
|
150
|
+
userId: string,
|
|
151
|
+
productId: string,
|
|
152
|
+
renewalId: string
|
|
153
|
+
): Promise<void> => {
|
|
154
|
+
try {
|
|
155
|
+
const repository = getCreditsRepository();
|
|
156
|
+
await repository.initializeCredits(userId, renewalId, productId);
|
|
157
|
+
|
|
158
|
+
if (__DEV__) {
|
|
159
|
+
console.log("[SubscriptionInitializer] Credits renewed:", {
|
|
160
|
+
userId,
|
|
161
|
+
productId,
|
|
162
|
+
renewalId,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (onCreditsUpdated) {
|
|
167
|
+
onCreditsUpdated(userId);
|
|
168
|
+
}
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (__DEV__) {
|
|
171
|
+
console.error("[SubscriptionInitializer] Failed to renew credits:", error);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
152
176
|
SubscriptionManager.configure({
|
|
153
177
|
config: {
|
|
154
178
|
apiKey,
|
|
155
179
|
testStoreKey,
|
|
156
180
|
entitlementIdentifier: entitlementId,
|
|
157
181
|
consumableProductIdentifiers: consumableIdentifiers,
|
|
158
|
-
onCreditRenewal,
|
|
182
|
+
onCreditRenewal: handleCreditRenewal,
|
|
159
183
|
onCreditsUpdated,
|
|
160
184
|
onPurchaseCompleted: handlePurchaseCompleted,
|
|
161
185
|
},
|