@umituz/react-native-subscription 2.13.12 → 2.13.14
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.13.
|
|
3
|
+
"version": "2.13.14",
|
|
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",
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
import { useQuery } from "@tanstack/react-query";
|
|
9
9
|
import type { UserCredits, CreditType } from "../../domain/entities/Credits";
|
|
10
|
+
|
|
11
|
+
declare const __DEV__: boolean;
|
|
10
12
|
import {
|
|
11
13
|
getCreditsRepository,
|
|
12
14
|
getCreditsConfig,
|
|
@@ -64,6 +66,18 @@ export const useCredits = ({
|
|
|
64
66
|
const hasTextCredits = (credits?.textCredits ?? 0) > 0;
|
|
65
67
|
const hasImageCredits = (credits?.imageCredits ?? 0) > 0;
|
|
66
68
|
|
|
69
|
+
if (__DEV__) {
|
|
70
|
+
console.log("[useCredits] State", {
|
|
71
|
+
userId,
|
|
72
|
+
enabled,
|
|
73
|
+
isLoading,
|
|
74
|
+
imageCredits: credits?.imageCredits ?? 0,
|
|
75
|
+
textCredits: credits?.textCredits ?? 0,
|
|
76
|
+
hasImageCredits,
|
|
77
|
+
hasTextCredits,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
67
81
|
const textCreditsPercent = credits
|
|
68
82
|
? Math.round((credits.textCredits / config.textCreditLimit) * 100)
|
|
69
83
|
: 0;
|
|
@@ -84,6 +84,17 @@ export function useFeatureGate(
|
|
|
84
84
|
? credits?.imageCredits ?? 0
|
|
85
85
|
: credits?.textCredits ?? 0;
|
|
86
86
|
|
|
87
|
+
if (__DEV__) {
|
|
88
|
+
console.log("[useFeatureGate] Hook state", {
|
|
89
|
+
userId,
|
|
90
|
+
isAuthenticated,
|
|
91
|
+
creditType,
|
|
92
|
+
hasCredits,
|
|
93
|
+
creditBalance,
|
|
94
|
+
isLoading,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
87
98
|
const requireFeature = useCallback(
|
|
88
99
|
(action: () => void | Promise<void>) => {
|
|
89
100
|
if (__DEV__) {
|
|
@@ -85,19 +85,33 @@ export const usePremium = (userId?: string): UsePremiumResult => {
|
|
|
85
85
|
// Premium status = has credits
|
|
86
86
|
const isPremium = credits !== null;
|
|
87
87
|
|
|
88
|
-
// Purchase handler
|
|
88
|
+
// Purchase handler with proper error handling
|
|
89
89
|
const handlePurchase = useCallback(
|
|
90
90
|
async (pkg: PurchasesPackage): Promise<boolean> => {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
try {
|
|
92
|
+
const success = await purchaseMutation.mutateAsync(pkg);
|
|
93
|
+
return success;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (__DEV__) {
|
|
96
|
+
console.error('[usePremium] Purchase failed:', error);
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
93
100
|
},
|
|
94
101
|
[purchaseMutation],
|
|
95
102
|
);
|
|
96
103
|
|
|
97
|
-
// Restore handler
|
|
104
|
+
// Restore handler with proper error handling
|
|
98
105
|
const handleRestore = useCallback(async (): Promise<boolean> => {
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
try {
|
|
107
|
+
const success = await restoreMutation.mutateAsync();
|
|
108
|
+
return success;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (__DEV__) {
|
|
111
|
+
console.error('[usePremium] Restore failed:', error);
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
101
115
|
}, [restoreMutation]);
|
|
102
116
|
|
|
103
117
|
return {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Based on SUBSCRIPTION_GUIDE.md pricing strategy
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type
|
|
7
|
+
import { detectPackageType, type SubscriptionPackageType } from "./packageTypeDetector";
|
|
8
8
|
|
|
9
9
|
export interface CreditAllocation {
|
|
10
10
|
imageCredits: number;
|
|
@@ -81,3 +81,35 @@ export function getTextCreditsForPackage(
|
|
|
81
81
|
const allocation = getCreditAllocation(packageType);
|
|
82
82
|
return allocation?.textCredits ?? null;
|
|
83
83
|
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Create credit amounts mapping for PaywallModal from RevenueCat packages
|
|
87
|
+
* Maps product.identifier to credit amount
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const creditAmounts = createCreditAmountsFromPackages(packages);
|
|
92
|
+
* // { "futureus_weekly_2_99": 6, "futureus_monthly_9_99": 25, "futureus_yearly_79_99": 300 }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export function createCreditAmountsFromPackages(
|
|
96
|
+
packages: Array<{ product: { identifier: string } }>
|
|
97
|
+
): Record<string, number> {
|
|
98
|
+
const result: Record<string, number> = {};
|
|
99
|
+
|
|
100
|
+
for (const pkg of packages) {
|
|
101
|
+
const identifier = pkg.product.identifier;
|
|
102
|
+
const packageType = detectPackageType(identifier);
|
|
103
|
+
const credits = getImageCreditsForPackage(packageType);
|
|
104
|
+
|
|
105
|
+
if (credits !== null) {
|
|
106
|
+
result[identifier] = credits;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (__DEV__) {
|
|
111
|
+
console.log("[CreditMapper] Created credit amounts from packages:", result);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return result;
|
|
115
|
+
}
|