@umituz/react-native-subscription 2.11.24 â 2.11.26
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.11.
|
|
3
|
+
"version": "2.11.26",
|
|
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",
|
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
* Premium status from TanStack Query (credits)
|
|
4
4
|
* Subscription state from TanStack Query
|
|
5
5
|
* Generic implementation for 100+ apps with auth provider abstraction
|
|
6
|
+
*
|
|
7
|
+
* Note: Credit allocation is handled by CustomerInfo Listener (onCreditRenewal)
|
|
8
|
+
* configured in SubscriptionManager. Manual credit initialization removed to
|
|
9
|
+
* prevent duplicate allocation.
|
|
6
10
|
*/
|
|
7
11
|
|
|
8
12
|
import { useCallback } from "react";
|
|
9
13
|
import type { PurchasesPackage } from "react-native-purchases";
|
|
10
14
|
import type { UserCredits } from "../../domain/entities/Credits";
|
|
11
15
|
import { useCredits } from "./useCredits";
|
|
12
|
-
import { useInitializeCredits } from "./useDeductCredit";
|
|
13
16
|
import {
|
|
14
17
|
useSubscriptionPackages,
|
|
15
18
|
usePurchasePackage,
|
|
@@ -48,8 +51,6 @@ export const usePremiumWithConfig = (
|
|
|
48
51
|
enabled: enabled && !!userId,
|
|
49
52
|
});
|
|
50
53
|
|
|
51
|
-
const { initializeCredits } = useInitializeCredits({ userId });
|
|
52
|
-
|
|
53
54
|
const { data: packages = [], isLoading: packagesLoading } =
|
|
54
55
|
useSubscriptionPackages(userId);
|
|
55
56
|
const purchaseMutation = usePurchasePackage(userId);
|
|
@@ -66,21 +67,17 @@ export const usePremiumWithConfig = (
|
|
|
66
67
|
const handlePurchase = useCallback(
|
|
67
68
|
async (pkg: PurchasesPackage): Promise<boolean> => {
|
|
68
69
|
const success = await purchaseMutation.mutateAsync(pkg);
|
|
69
|
-
|
|
70
|
-
await initializeCredits({ productId: pkg.product.identifier });
|
|
71
|
-
}
|
|
70
|
+
// Credit allocation handled by CustomerInfo Listener (onCreditRenewal)
|
|
72
71
|
return success;
|
|
73
72
|
},
|
|
74
|
-
[purchaseMutation
|
|
73
|
+
[purchaseMutation],
|
|
75
74
|
);
|
|
76
75
|
|
|
77
76
|
const handleRestore = useCallback(async (): Promise<boolean> => {
|
|
78
77
|
const success = await restoreMutation.mutateAsync();
|
|
79
|
-
|
|
80
|
-
await initializeCredits();
|
|
81
|
-
}
|
|
78
|
+
// Credit allocation handled by CustomerInfo Listener (onCreditRenewal)
|
|
82
79
|
return success;
|
|
83
|
-
}, [restoreMutation
|
|
80
|
+
}, [restoreMutation]);
|
|
84
81
|
|
|
85
82
|
return {
|
|
86
83
|
isPremium,
|
|
@@ -31,16 +31,44 @@ export class CustomerInfoListenerManager {
|
|
|
31
31
|
setupListener(config: RevenueCatConfig): void {
|
|
32
32
|
this.removeListener();
|
|
33
33
|
|
|
34
|
+
if (__DEV__) {
|
|
35
|
+
console.log("[CustomerInfoListener] Setting up listener", {
|
|
36
|
+
userId: this.currentUserId,
|
|
37
|
+
entitlementId: this.entitlementIdentifier,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
addPackageBreadcrumb("subscription", "Setting up customer info listener", {
|
|
35
42
|
userId: this.currentUserId,
|
|
36
43
|
});
|
|
37
44
|
|
|
38
45
|
this.listener = async (customerInfo: CustomerInfo) => {
|
|
39
|
-
if (
|
|
46
|
+
if (__DEV__) {
|
|
47
|
+
console.log("[CustomerInfoListener] đ Listener fired!", {
|
|
48
|
+
userId: this.currentUserId,
|
|
49
|
+
hasActiveEntitlements: Object.keys(customerInfo.entitlements.active).length > 0,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!this.currentUserId) {
|
|
54
|
+
if (__DEV__) {
|
|
55
|
+
console.warn("[CustomerInfoListener] â No userId, skipping");
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
40
59
|
|
|
41
60
|
const hasPremium =
|
|
42
61
|
!!customerInfo.entitlements.active[this.entitlementIdentifier];
|
|
43
62
|
|
|
63
|
+
if (__DEV__) {
|
|
64
|
+
console.log("[CustomerInfoListener] Customer info updated", {
|
|
65
|
+
userId: this.currentUserId,
|
|
66
|
+
hasPremium,
|
|
67
|
+
entitlementIdentifier: this.entitlementIdentifier,
|
|
68
|
+
activeEntitlements: Object.keys(customerInfo.entitlements.active),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
44
72
|
addPackageBreadcrumb("subscription", "Customer info updated", {
|
|
45
73
|
userId: this.currentUserId,
|
|
46
74
|
hasPremium,
|
|
@@ -56,6 +84,15 @@ export class CustomerInfoListenerManager {
|
|
|
56
84
|
const productId = premiumEntitlement.productIdentifier;
|
|
57
85
|
const renewalId = `renewal_${productId}_${premiumEntitlement.expirationDate}`;
|
|
58
86
|
|
|
87
|
+
if (__DEV__) {
|
|
88
|
+
console.log("[CustomerInfoListener] đ° Processing credit renewal", {
|
|
89
|
+
userId: this.currentUserId,
|
|
90
|
+
productId,
|
|
91
|
+
renewalId,
|
|
92
|
+
expirationDate: premiumEntitlement.expirationDate,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
59
96
|
addPackageBreadcrumb(
|
|
60
97
|
"subscription",
|
|
61
98
|
"Processing credit renewal",
|
|
@@ -73,6 +110,13 @@ export class CustomerInfoListenerManager {
|
|
|
73
110
|
renewalId
|
|
74
111
|
);
|
|
75
112
|
|
|
113
|
+
if (__DEV__) {
|
|
114
|
+
console.log("[CustomerInfoListener] â
Credit renewal completed", {
|
|
115
|
+
userId: this.currentUserId,
|
|
116
|
+
productId,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
76
120
|
addPackageBreadcrumb(
|
|
77
121
|
"subscription",
|
|
78
122
|
"Credit renewal completed",
|
|
@@ -82,6 +126,14 @@ export class CustomerInfoListenerManager {
|
|
|
82
126
|
}
|
|
83
127
|
);
|
|
84
128
|
} catch (error) {
|
|
129
|
+
if (__DEV__) {
|
|
130
|
+
console.error("[CustomerInfoListener] â Credit renewal failed", {
|
|
131
|
+
userId: this.currentUserId,
|
|
132
|
+
productId,
|
|
133
|
+
error: error instanceof Error ? error.message : String(error),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
85
137
|
addPackageBreadcrumb(
|
|
86
138
|
"subscription",
|
|
87
139
|
"Credit renewal failed",
|
|
@@ -92,6 +144,20 @@ export class CustomerInfoListenerManager {
|
|
|
92
144
|
}
|
|
93
145
|
);
|
|
94
146
|
}
|
|
147
|
+
} else {
|
|
148
|
+
if (__DEV__) {
|
|
149
|
+
console.warn("[CustomerInfoListener] â ī¸ Premium but no entitlement/expiration", {
|
|
150
|
+
hasPremiumEntitlement: !!premiumEntitlement,
|
|
151
|
+
hasExpirationDate: !!(premiumEntitlement?.expirationDate),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
if (__DEV__) {
|
|
157
|
+
console.log("[CustomerInfoListener] âšī¸ Skipping credit renewal", {
|
|
158
|
+
hasPremium,
|
|
159
|
+
hasCallback: !!config.onCreditRenewal,
|
|
160
|
+
});
|
|
95
161
|
}
|
|
96
162
|
}
|
|
97
163
|
|