@umituz/react-native-subscription 2.13.13 → 2.13.15

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.13",
3
+ "version": "2.13.15",
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
@@ -325,6 +325,7 @@ export {
325
325
  getCreditAllocation,
326
326
  getImageCreditsForPackage,
327
327
  getTextCreditsForPackage,
328
+ createCreditAmountsFromPackages,
328
329
  CREDIT_ALLOCATIONS,
329
330
  type CreditAllocation,
330
331
  } from "./utils/creditMapper";
@@ -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
- const success = await purchaseMutation.mutateAsync(pkg);
92
- return success;
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
- const success = await restoreMutation.mutateAsync();
100
- return success;
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 { SubscriptionPackageType } from "./packageTypeDetector";
7
+ import { detectPackageType, type SubscriptionPackageType } from "./packageTypeDetector";
8
8
 
9
9
  export interface CreditAllocation {
10
10
  imageCredits: number;
@@ -81,3 +81,69 @@ 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
+ if (__DEV__) {
101
+ console.log("[CreditMapper] Input packages count:", packages?.length || 0);
102
+ }
103
+
104
+ if (!packages || packages.length === 0) {
105
+ if (__DEV__) {
106
+ console.log("[CreditMapper] No packages provided, returning empty object");
107
+ }
108
+ return result;
109
+ }
110
+
111
+ for (const pkg of packages) {
112
+ const identifier = pkg?.product?.identifier;
113
+
114
+ if (__DEV__) {
115
+ console.log("[CreditMapper] Processing package:", {
116
+ hasProduct: !!pkg?.product,
117
+ identifier,
118
+ });
119
+ }
120
+
121
+ if (!identifier) {
122
+ if (__DEV__) {
123
+ console.warn("[CreditMapper] Package missing product.identifier:", pkg);
124
+ }
125
+ continue;
126
+ }
127
+
128
+ const packageType = detectPackageType(identifier);
129
+ const credits = getImageCreditsForPackage(packageType);
130
+
131
+ if (__DEV__) {
132
+ console.log("[CreditMapper] Package mapping:", {
133
+ identifier,
134
+ packageType,
135
+ credits,
136
+ });
137
+ }
138
+
139
+ if (credits !== null) {
140
+ result[identifier] = credits;
141
+ }
142
+ }
143
+
144
+ if (__DEV__) {
145
+ console.log("[CreditMapper] Final credit amounts:", result);
146
+ }
147
+
148
+ return result;
149
+ }