@umituz/react-native-subscription 2.35.12 → 2.35.13

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.35.12",
3
+ "version": "2.35.13",
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",
@@ -4,7 +4,6 @@ import { useSubscriptionPackages } from "../../subscription/infrastructure/hooks
4
4
  import { useRevenueCatTrialEligibility } from "../../subscription/infrastructure/hooks/useRevenueCatTrialEligibility";
5
5
  import { createCreditAmountsFromPackages } from "../../../utils/creditMapper";
6
6
  import { PaywallModal } from "./PaywallModal";
7
- import { usePaywallActions } from "../hooks/usePaywallActions";
8
7
  import { useAuthAwarePurchase } from "../../subscription/presentation/useAuthAwarePurchase";
9
8
  import { useTrialEligibilityCheck } from "../hooks/useTrialEligibilityCheck";
10
9
  import type { PaywallContainerProps } from "./PaywallContainer.types";
@@ -36,20 +35,9 @@ export const PaywallContainer: React.FC<PaywallContainerProps> = (props) => {
36
35
 
37
36
  const { data: packages = [], isLoading } = useSubscriptionPackages();
38
37
  const { eligibilityMap, checkEligibility } = useRevenueCatTrialEligibility();
39
-
40
- const { handlePurchase: performPurchase, handleRestore: performRestore } = useAuthAwarePurchase({
41
- source: purchaseSource
42
- });
43
38
 
44
- const { handlePurchase, handleRestore } = usePaywallActions({
45
- packages,
46
- onPurchase: performPurchase,
47
- onRestore: performRestore,
48
- source: purchaseSource,
49
- onPurchaseSuccess,
50
- onPurchaseError,
51
- onAuthRequired,
52
- onClose: handleClose,
39
+ const { handlePurchase: performPurchase, handleRestore: performRestore } = useAuthAwarePurchase({
40
+ source: purchaseSource
53
41
  });
54
42
 
55
43
  const trialEligibility = useTrialEligibilityCheck({
@@ -60,7 +48,6 @@ export const PaywallContainer: React.FC<PaywallContainerProps> = (props) => {
60
48
  trialConfig,
61
49
  });
62
50
 
63
- // Compute credit amounts from packageAllocations if not provided directly
64
51
  const creditAmounts = useMemo(() => {
65
52
  if (providedCreditAmounts) return providedCreditAmounts;
66
53
  if (!packageAllocations || packages.length === 0) return undefined;
@@ -81,10 +68,14 @@ export const PaywallContainer: React.FC<PaywallContainerProps> = (props) => {
81
68
  bestValueIdentifier={bestValueIdentifier}
82
69
  creditAmounts={creditAmounts}
83
70
  creditsLabel={creditsLabel}
84
- onPurchase={handlePurchase}
85
- onRestore={handleRestore}
71
+ onPurchase={performPurchase}
72
+ onRestore={performRestore}
86
73
  trialEligibility={trialEligibility}
87
74
  trialSubtitleText={trialConfig?.enabled ? trialConfig.trialText : undefined}
75
+ onPurchaseSuccess={onPurchaseSuccess}
76
+ onPurchaseError={onPurchaseError}
77
+ onAuthRequired={onAuthRequired}
78
+ source={purchaseSource}
88
79
  />
89
80
  );
90
81
  };
@@ -11,10 +11,19 @@ import { usePaywallActions } from "../hooks/usePaywallActions";
11
11
  import { PaywallModalProps } from "./PaywallModal.types";
12
12
 
13
13
  export const PaywallModal: React.FC<PaywallModalProps> = React.memo((props) => {
14
- const { visible, onClose, translations, packages = [], features = [], legalUrls = {}, bestValueIdentifier, creditAmounts, creditsLabel, heroImage, onPurchase, onRestore, trialEligibility = {}, trialSubtitleText } = props;
14
+ const { visible, onClose, translations, packages = [], features = [], legalUrls = {}, bestValueIdentifier, creditAmounts, creditsLabel, heroImage, onPurchase, onRestore, trialEligibility = {}, trialSubtitleText, onPurchaseSuccess, onPurchaseError, onAuthRequired, source } = props;
15
15
  const tokens = useAppDesignTokens();
16
16
  const insets = useSafeAreaInsets();
17
- const { selectedPlanId, setSelectedPlanId, isProcessing, handlePurchase, handleRestore, resetState } = usePaywallActions({ packages, onPurchase, onRestore });
17
+ const { selectedPlanId, setSelectedPlanId, isProcessing, handlePurchase, handleRestore, resetState } = usePaywallActions({
18
+ packages,
19
+ onPurchase,
20
+ onRestore,
21
+ source,
22
+ onPurchaseSuccess,
23
+ onPurchaseError,
24
+ onAuthRequired,
25
+ onClose
26
+ });
18
27
 
19
28
  useEffect(() => {
20
29
  if (!visible) resetState();
@@ -1,6 +1,7 @@
1
1
  import type { ImageSourcePropType } from "react-native";
2
2
  import type { PurchasesPackage } from "react-native-purchases";
3
3
  import type { SubscriptionFeature, PaywallTranslations, PaywallLegalUrls } from "../entities/types";
4
+ import type { PurchaseSource } from "../../subscription/core/SubscriptionConstants";
4
5
 
5
6
  export interface TrialEligibilityInfo {
6
7
  eligible: boolean;
@@ -22,4 +23,8 @@ export interface PaywallModalProps {
22
23
  onRestore?: () => Promise<void | boolean>;
23
24
  trialEligibility?: Record<string, TrialEligibilityInfo>;
24
25
  trialSubtitleText?: string;
26
+ onPurchaseSuccess?: () => void;
27
+ onPurchaseError?: (error: Error | string) => void;
28
+ onAuthRequired?: () => void;
29
+ source?: PurchaseSource;
25
30
  }
@@ -24,14 +24,7 @@ export class PackageHandler {
24
24
  }
25
25
 
26
26
  async purchase(pkg: PurchasesPackage, userId: string): Promise<boolean> {
27
- console.log('🔵 [PackageHandler] purchase called', {
28
- productId: pkg.product.identifier,
29
- userId
30
- });
31
-
32
27
  const result = await executePurchase(this.service, pkg, userId);
33
- console.log('✅ [PackageHandler] purchase completed', { result });
34
-
35
28
  return result;
36
29
  }
37
30
 
@@ -6,20 +6,10 @@ export async function executePurchase(
6
6
  pkg: PurchasesPackage,
7
7
  userId: string
8
8
  ): Promise<boolean> {
9
- console.log('🔵 [executePurchase] Starting', {
10
- productId: pkg.product.identifier,
11
- userId,
12
- isInitialized: service.isInitialized()
13
- });
14
-
15
9
  if (!service.isInitialized()) {
16
- console.error('❌ [executePurchase] Service not initialized!');
17
10
  throw new Error("Service not initialized");
18
11
  }
19
12
 
20
- console.log('🚀 [executePurchase] Calling service.purchasePackage');
21
13
  const result = await service.purchasePackage(pkg, userId);
22
- console.log('✅ [executePurchase] Completed', { success: result.success });
23
-
24
14
  return result.success;
25
15
  }
@@ -87,19 +87,9 @@ class SubscriptionManagerImpl {
87
87
  }
88
88
 
89
89
  async purchasePackage(pkg: PurchasesPackage): Promise<boolean> {
90
- console.log('🔵 [SubscriptionManager] purchasePackage called', {
91
- productId: pkg.product.identifier,
92
- isConfigured: !!this.managerConfig,
93
- hasPackageHandler: !!this.packageHandler
94
- });
95
-
96
90
  this.ensureConfigured();
97
91
  this.ensurePackageHandlerInitialized();
98
-
99
- console.log('🚀 [SubscriptionManager] Calling purchasePackageOperation');
100
92
  const result = await purchasePackageOperation(pkg, this.managerConfig, this.state, this.packageHandler!);
101
- console.log('✅ [SubscriptionManager] purchasePackageOperation completed', { result });
102
-
103
93
  return result;
104
94
  }
105
95
 
@@ -22,17 +22,9 @@ export const purchasePackageOperation = async (
22
22
  state: SubscriptionInternalState,
23
23
  packageHandler: PackageHandler
24
24
  ): Promise<boolean> => {
25
- console.log('🔵 [purchasePackageOperation] Starting', {
26
- productId: pkg.product.identifier
27
- });
28
-
29
25
  ensureConfigured(managerConfig);
30
26
  const userId = getCurrentUserIdOrThrow(state);
31
-
32
- console.log('🚀 [purchasePackageOperation] Calling packageHandler.purchase', { userId });
33
27
  const result = await packageHandler.purchase(pkg, userId);
34
- console.log('✅ [purchasePackageOperation] Completed', { result });
35
-
36
28
  return result;
37
29
  };
38
30
 
@@ -16,38 +16,23 @@ export async function handlePurchase(
16
16
  pkg: PurchasesPackage,
17
17
  userId: string
18
18
  ): Promise<PurchaseResult> {
19
- console.log('🔵 [PurchaseHandler] handlePurchase called', {
20
- productId: pkg.product.identifier,
21
- userId,
22
- isInitialized: deps.isInitialized()
23
- });
24
-
25
19
  validatePurchaseReady(deps.isInitialized());
26
20
 
27
21
  const consumableIds = deps.config.consumableProductIdentifiers || [];
28
22
  const isConsumable = isConsumableProduct(pkg, consumableIds);
29
23
 
30
- console.log('📦 [PurchaseHandler] Product type', { isConsumable });
31
-
32
24
  try {
33
- console.log('🚀 [PurchaseHandler] Calling executePurchase');
34
25
  const result = await executePurchase(deps.config, userId, pkg, isConsumable);
35
- console.log('✅ [PurchaseHandler] executePurchase completed', { success: result.success });
36
26
  return result;
37
27
  } catch (error) {
38
- console.error('❌ [PurchaseHandler] Purchase failed', { error });
39
-
40
28
  if (isUserCancelledError(error)) {
41
- console.log('⚠️ [PurchaseHandler] User cancelled');
42
29
  return { success: false, isPremium: false, productId: pkg.product.identifier };
43
30
  }
44
31
 
45
32
  if (isAlreadyPurchasedError(error)) {
46
- console.log('⚠️ [PurchaseHandler] Already purchased');
47
33
  return await handleAlreadyPurchasedError(deps, userId, pkg, error);
48
34
  }
49
35
 
50
- console.error('❌ [PurchaseHandler] Unhandled error');
51
36
  return handlePurchaseError(error, pkg, userId);
52
37
  }
53
38
  }
@@ -60,15 +60,7 @@ export class RevenueCatService implements IRevenueCatService {
60
60
  }
61
61
 
62
62
  async purchasePackage(pkg: PurchasesPackage, userId: string): Promise<PurchaseResult> {
63
- console.log('🔵 [RevenueCatService] purchasePackage called', {
64
- productId: pkg.product.identifier,
65
- userId,
66
- isInitialized: this.isInitialized()
67
- });
68
-
69
63
  const result = await handlePurchase(this.getSDKParams(), pkg, userId);
70
- console.log('✅ [RevenueCatService] purchasePackage completed', { success: result.success });
71
-
72
64
  return result;
73
65
  }
74
66
 
@@ -77,26 +77,15 @@ export async function executePurchase(
77
77
  pkg: PurchasesPackage,
78
78
  isConsumable: boolean
79
79
  ): Promise<PurchaseResult> {
80
- console.log('🔵 [PurchaseExecutor] executePurchase called', {
81
- productId: pkg.product.identifier,
82
- userId,
83
- isConsumable,
84
- packageType: pkg.packageType
85
- });
86
-
87
- console.log('🚀 [PurchaseExecutor] Calling Purchases.purchasePackage (RevenueCat SDK)');
88
80
  const { customerInfo } = await Purchases.purchasePackage(pkg);
89
- console.log('✅ [PurchaseExecutor] Purchases.purchasePackage completed');
90
81
 
91
82
  const productId = pkg.product.identifier;
92
83
  const packageType = pkg.packageType ?? null;
93
84
 
94
85
  if (isConsumable) {
95
- console.log('💰 [PurchaseExecutor] Processing as consumable purchase');
96
86
  return executeConsumablePurchase(config, userId, productId, customerInfo, packageType);
97
87
  }
98
88
 
99
- console.log('📅 [PurchaseExecutor] Processing as subscription purchase');
100
89
  return executeSubscriptionPurchase(
101
90
  config,
102
91
  userId,