@umituz/react-native-subscription 2.19.6 → 2.20.0
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.
|
|
3
|
+
"version": "2.20.0",
|
|
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",
|
|
@@ -61,20 +61,11 @@ export const initializeSubscription = async (config: SubscriptionInitConfig): Pr
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
await getCreditsRepository().initializeCredits(
|
|
67
|
-
userId,
|
|
68
|
-
renewalId,
|
|
69
|
-
productId,
|
|
70
|
-
undefined
|
|
71
|
-
);
|
|
72
|
-
onCreditsUpdated?.(userId);
|
|
73
|
-
} catch { /* Silent */ }
|
|
74
|
-
};
|
|
64
|
+
// Note: Renewal credits should be handled server-side via RevenueCat webhooks + Cloud Functions
|
|
65
|
+
// Client-side listener cannot reliably detect renewals vs new purchases
|
|
75
66
|
|
|
76
67
|
SubscriptionManager.configure({
|
|
77
|
-
config: { apiKey: key, testStoreKey, entitlementIdentifier: entitlementId, consumableProductIdentifiers: [creditPackages?.identifierPattern || "credit"],
|
|
68
|
+
config: { apiKey: key, testStoreKey, entitlementIdentifier: entitlementId, consumableProductIdentifiers: [creditPackages?.identifierPattern || "credit"], onPurchaseCompleted: onPurchase, onCreditsUpdated },
|
|
78
69
|
apiKey: key, getAnonymousUserId
|
|
79
70
|
});
|
|
80
71
|
|
|
@@ -34,12 +34,6 @@ export interface RevenueCatConfig {
|
|
|
34
34
|
isPremium: boolean,
|
|
35
35
|
customerInfo: CustomerInfo
|
|
36
36
|
) => Promise<void> | void;
|
|
37
|
-
/** Callback for credit renewal (subscription auto-renewal) */
|
|
38
|
-
onCreditRenewal?: (
|
|
39
|
-
userId: string,
|
|
40
|
-
productId: string,
|
|
41
|
-
renewalId: string
|
|
42
|
-
) => Promise<void> | void;
|
|
43
37
|
/** Callback after credits are successfully updated (for cache invalidation) */
|
|
44
38
|
onCreditsUpdated?: (userId: string) => void;
|
|
45
39
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Customer Info Listener Manager
|
|
3
3
|
* Handles RevenueCat customer info update listeners
|
|
4
|
+
* Only syncs premium status - renewal handling should be done server-side via webhooks
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
import Purchases, {
|
|
@@ -13,16 +14,9 @@ import { syncPremiumStatus } from "../utils/PremiumStatusSyncer";
|
|
|
13
14
|
export class CustomerInfoListenerManager {
|
|
14
15
|
private listener: CustomerInfoUpdateListener | null = null;
|
|
15
16
|
private currentUserId: string | null = null;
|
|
16
|
-
private entitlementIdentifier: string;
|
|
17
|
-
private lastPurchaseTime: number = 0;
|
|
18
|
-
private static readonly PURCHASE_DEBOUNCE_MS = 5000;
|
|
19
17
|
|
|
20
|
-
constructor(
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
notifyPurchaseCompleted(): void {
|
|
25
|
-
this.lastPurchaseTime = Date.now();
|
|
18
|
+
constructor(_entitlementIdentifier: string) {
|
|
19
|
+
// entitlementIdentifier kept for API compatibility
|
|
26
20
|
}
|
|
27
21
|
|
|
28
22
|
setUserId(userId: string): void {
|
|
@@ -33,6 +27,10 @@ export class CustomerInfoListenerManager {
|
|
|
33
27
|
this.currentUserId = null;
|
|
34
28
|
}
|
|
35
29
|
|
|
30
|
+
notifyPurchaseCompleted(): void {
|
|
31
|
+
// Reserved for future use if needed
|
|
32
|
+
}
|
|
33
|
+
|
|
36
34
|
setupListener(config: RevenueCatConfig): void {
|
|
37
35
|
this.removeListener();
|
|
38
36
|
|
|
@@ -41,40 +39,7 @@ export class CustomerInfoListenerManager {
|
|
|
41
39
|
return;
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
!!customerInfo.entitlements.active[this.entitlementIdentifier];
|
|
46
|
-
|
|
47
|
-
if (hasPremium && config.onCreditRenewal) {
|
|
48
|
-
const timeSincePurchase = Date.now() - this.lastPurchaseTime;
|
|
49
|
-
const isRecentPurchase = timeSincePurchase < CustomerInfoListenerManager.PURCHASE_DEBOUNCE_MS;
|
|
50
|
-
|
|
51
|
-
if (isRecentPurchase) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const premiumEntitlement =
|
|
56
|
-
customerInfo.entitlements.active[this.entitlementIdentifier];
|
|
57
|
-
|
|
58
|
-
if (premiumEntitlement && premiumEntitlement.expirationDate) {
|
|
59
|
-
const productId = premiumEntitlement.productIdentifier;
|
|
60
|
-
const renewalId = `renewal_${productId}_${premiumEntitlement.expirationDate}`;
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
await config.onCreditRenewal(
|
|
64
|
-
this.currentUserId,
|
|
65
|
-
productId,
|
|
66
|
-
renewalId
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
if (config.onCreditsUpdated && this.currentUserId) {
|
|
70
|
-
config.onCreditsUpdated(this.currentUserId);
|
|
71
|
-
}
|
|
72
|
-
} catch {
|
|
73
|
-
// Silent error handling
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
42
|
+
// Only sync premium status - renewal credits handled server-side via webhooks
|
|
78
43
|
syncPremiumStatus(config, this.currentUserId, customerInfo);
|
|
79
44
|
};
|
|
80
45
|
|