@umituz/react-native-subscription 2.14.65 → 2.14.67

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.65",
3
+ "version": "2.14.67",
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",
@@ -12,6 +12,7 @@ import { usePurchasePackage } from "../../../revenuecat/presentation/hooks/usePu
12
12
  import { useRestorePurchase } from "../../../revenuecat/presentation/hooks/useRestorePurchase";
13
13
  import { SubscriptionManager } from "../../../revenuecat/infrastructure/managers/SubscriptionManager";
14
14
  import { filterPackagesByMode } from "../../../utils/packageFilter";
15
+ import { createCreditAmountsFromPackages } from "../../../utils/creditMapper";
15
16
  import { PaywallModal } from "./PaywallModal";
16
17
  import type { PaywallContainerProps } from "./PaywallContainer.types";
17
18
 
@@ -19,6 +20,7 @@ declare const __DEV__: boolean;
19
20
 
20
21
  export const PaywallContainer: React.FC<PaywallContainerProps> = ({
21
22
  userId,
23
+ isAnonymous = false,
22
24
  translations,
23
25
  mode = "subscription",
24
26
  legalUrls,
@@ -30,35 +32,53 @@ export const PaywallContainer: React.FC<PaywallContainerProps> = ({
30
32
  packageFilterConfig,
31
33
  onPurchaseSuccess,
32
34
  onPurchaseError,
35
+ onAuthRequired,
33
36
  }) => {
34
37
  const { showPaywall, closePaywall } = usePaywallVisibility();
35
38
  const { data: allPackages = [], isLoading, isFetching, status, error } = useSubscriptionPackages(userId ?? undefined);
36
39
  const { mutateAsync: purchasePackage } = usePurchasePackage(userId ?? undefined);
37
40
  const { mutateAsync: restorePurchases } = useRestorePurchase(userId ?? undefined);
38
41
 
39
- const filteredPackages = useMemo(() => {
40
- return filterPackagesByMode(allPackages, mode, packageFilterConfig);
41
- }, [allPackages, mode, packageFilterConfig]);
42
+ const { filteredPackages, computedCreditAmounts } = useMemo(() => {
43
+ const filtered = filterPackagesByMode(allPackages, mode, packageFilterConfig);
44
+ const computed = mode !== "subscription" && !creditAmounts
45
+ ? createCreditAmountsFromPackages(allPackages)
46
+ : creditAmounts;
47
+
48
+ return { filteredPackages: filtered, computedCreditAmounts: computed };
49
+ }, [allPackages, mode, packageFilterConfig, creditAmounts]);
42
50
 
43
51
  useEffect(() => {
44
52
  if (__DEV__ && showPaywall) {
45
53
  console.log("[PaywallContainer] Paywall opened:", {
46
54
  userId,
55
+ isAnonymous,
47
56
  mode,
48
57
  isConfigured: SubscriptionManager.isConfigured(),
49
58
  isInitialized: SubscriptionManager.isInitialized(),
50
59
  allPackagesCount: allPackages.length,
51
60
  filteredPackagesCount: filteredPackages.length,
61
+ computedCreditAmounts,
52
62
  isLoading,
53
63
  isFetching,
54
64
  status,
55
65
  error: error?.message ?? null,
56
66
  });
57
67
  }
58
- }, [showPaywall, userId, mode, allPackages.length, filteredPackages.length, isLoading, isFetching, status, error]);
68
+ }, [showPaywall, userId, isAnonymous, mode, allPackages.length, filteredPackages.length, isLoading, isFetching, status, error]);
59
69
 
60
70
  const handlePurchase = useCallback(
61
71
  async (pkg: PurchasesPackage) => {
72
+ // Auth gating: require authentication for anonymous users
73
+ if (isAnonymous) {
74
+ if (__DEV__) {
75
+ console.log("[PaywallContainer] Anonymous user, requiring auth before purchase");
76
+ }
77
+ closePaywall();
78
+ onAuthRequired?.();
79
+ return;
80
+ }
81
+
62
82
  try {
63
83
  if (__DEV__) {
64
84
  console.log("[PaywallContainer] Purchase started:", pkg.identifier);
@@ -79,7 +99,7 @@ export const PaywallContainer: React.FC<PaywallContainerProps> = ({
79
99
  onPurchaseError?.(message);
80
100
  }
81
101
  },
82
- [purchasePackage, closePaywall, onPurchaseSuccess, onPurchaseError]
102
+ [isAnonymous, purchasePackage, closePaywall, onPurchaseSuccess, onPurchaseError, onAuthRequired]
83
103
  );
84
104
 
85
105
  const handleRestore = useCallback(async () => {
@@ -120,7 +140,7 @@ export const PaywallContainer: React.FC<PaywallContainerProps> = ({
120
140
  heroImage={heroImage}
121
141
  bestValueIdentifier={bestValueIdentifier}
122
142
  creditsLabel={creditsLabel}
123
- creditAmounts={creditAmounts}
143
+ creditAmounts={computedCreditAmounts}
124
144
  onPurchase={handlePurchase}
125
145
  onRestore={handleRestore}
126
146
  />
@@ -10,6 +10,8 @@ import type { PackageFilterConfig } from "../../../utils/packageFilter";
10
10
  export interface PaywallContainerProps {
11
11
  /** User ID for subscription management */
12
12
  readonly userId: string | null;
13
+ /** Whether user is anonymous (requires auth before purchase) */
14
+ readonly isAnonymous?: boolean;
13
15
  /** Paywall translations - no defaults, must be provided */
14
16
  readonly translations: PaywallTranslations;
15
17
  /** Paywall mode - subscription, credits, or hybrid */
@@ -32,4 +34,7 @@ export interface PaywallContainerProps {
32
34
  readonly onPurchaseSuccess?: () => void;
33
35
  /** Callback when purchase fails */
34
36
  readonly onPurchaseError?: (error: string) => void;
37
+ /** Callback when auth is required (for anonymous users) */
38
+ readonly onAuthRequired?: () => void;
35
39
  }
40
+