@umituz/react-native-subscription 2.19.6 → 2.20.1
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/infrastructure/services/SubscriptionInitializer.ts +1 -13
- package/src/revenuecat/domain/value-objects/RevenueCatConfig.ts +0 -6
- package/src/revenuecat/infrastructure/services/CustomerInfoListenerManager.ts +0 -45
- package/src/revenuecat/infrastructure/services/RevenueCatService.ts +2 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.1",
|
|
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,8 @@ export const initializeSubscription = async (config: SubscriptionInitConfig): Pr
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
const onRenewal = async (userId: string, productId: string, renewalId: string) => {
|
|
65
|
-
try {
|
|
66
|
-
await getCreditsRepository().initializeCredits(
|
|
67
|
-
userId,
|
|
68
|
-
renewalId,
|
|
69
|
-
productId,
|
|
70
|
-
undefined
|
|
71
|
-
);
|
|
72
|
-
onCreditsUpdated?.(userId);
|
|
73
|
-
} catch { /* Silent */ }
|
|
74
|
-
};
|
|
75
|
-
|
|
76
64
|
SubscriptionManager.configure({
|
|
77
|
-
config: { apiKey: key, testStoreKey, entitlementIdentifier: entitlementId, consumableProductIdentifiers: [creditPackages?.identifierPattern || "credit"],
|
|
65
|
+
config: { apiKey: key, testStoreKey, entitlementIdentifier: entitlementId, consumableProductIdentifiers: [creditPackages?.identifierPattern || "credit"], onPurchaseCompleted: onPurchase, onCreditsUpdated },
|
|
78
66
|
apiKey: key, getAnonymousUserId
|
|
79
67
|
});
|
|
80
68
|
|
|
@@ -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
|
}
|
|
@@ -13,17 +13,6 @@ import { syncPremiumStatus } from "../utils/PremiumStatusSyncer";
|
|
|
13
13
|
export class CustomerInfoListenerManager {
|
|
14
14
|
private listener: CustomerInfoUpdateListener | null = null;
|
|
15
15
|
private currentUserId: string | null = null;
|
|
16
|
-
private entitlementIdentifier: string;
|
|
17
|
-
private lastPurchaseTime: number = 0;
|
|
18
|
-
private static readonly PURCHASE_DEBOUNCE_MS = 5000;
|
|
19
|
-
|
|
20
|
-
constructor(entitlementIdentifier: string) {
|
|
21
|
-
this.entitlementIdentifier = entitlementIdentifier;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
notifyPurchaseCompleted(): void {
|
|
25
|
-
this.lastPurchaseTime = Date.now();
|
|
26
|
-
}
|
|
27
16
|
|
|
28
17
|
setUserId(userId: string): void {
|
|
29
18
|
this.currentUserId = userId;
|
|
@@ -41,40 +30,6 @@ export class CustomerInfoListenerManager {
|
|
|
41
30
|
return;
|
|
42
31
|
}
|
|
43
32
|
|
|
44
|
-
const hasPremium =
|
|
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
|
-
|
|
78
33
|
syncPremiumStatus(config, this.currentUserId, customerInfo);
|
|
79
34
|
};
|
|
80
35
|
|
|
@@ -30,9 +30,7 @@ export class RevenueCatService implements IRevenueCatService {
|
|
|
30
30
|
|
|
31
31
|
constructor(config: RevenueCatConfig) {
|
|
32
32
|
this.stateManager = new ServiceStateManager(config);
|
|
33
|
-
this.listenerManager = new CustomerInfoListenerManager(
|
|
34
|
-
config.entitlementIdentifier
|
|
35
|
-
);
|
|
33
|
+
this.listenerManager = new CustomerInfoListenerManager();
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
getRevenueCatKey(): string | null {
|
|
@@ -89,11 +87,7 @@ export class RevenueCatService implements IRevenueCatService {
|
|
|
89
87
|
pkg: PurchasesPackage,
|
|
90
88
|
userId: string
|
|
91
89
|
): Promise<PurchaseResult> {
|
|
92
|
-
|
|
93
|
-
if (result.success) {
|
|
94
|
-
this.listenerManager.notifyPurchaseCompleted();
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
90
|
+
return handlePurchase(this.getSDKParams(), pkg, userId);
|
|
97
91
|
}
|
|
98
92
|
|
|
99
93
|
async restorePurchases(userId: string): Promise<RestoreResult> {
|