@umituz/react-native-subscription 2.19.2 → 2.19.4

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.19.2",
3
+ "version": "2.19.4",
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",
@@ -113,22 +113,35 @@ export async function initializeCreditsTransaction(
113
113
  ? [...(existing?.purchaseHistory || []), purchaseMetadata].slice(-10)
114
114
  : existing?.purchaseHistory;
115
115
 
116
- const creditsData = {
116
+ // Build credits data, excluding undefined values (Firestore doesn't accept undefined)
117
+ const creditsData: Record<string, unknown> = {
117
118
  credits: newCredits,
118
- packageType: packageType !== "unknown" ? packageType : undefined,
119
119
  creditLimit,
120
- productId: productId || undefined,
121
- purchaseSource: metadata?.source,
122
- purchaseType: metadata?.type ? purchaseType : undefined,
123
- platform: productId ? platform : undefined,
124
- appVersion: productId ? appVersion : undefined,
125
120
  purchasedAt,
126
121
  lastUpdatedAt: now,
127
122
  lastPurchaseAt: now,
128
123
  processedPurchases,
129
- purchaseHistory,
130
124
  };
131
125
 
126
+ // Only add optional fields if they have values
127
+ if (packageType && packageType !== "unknown") {
128
+ creditsData.packageType = packageType;
129
+ }
130
+ if (productId) {
131
+ creditsData.productId = productId;
132
+ creditsData.platform = platform;
133
+ creditsData.appVersion = appVersion;
134
+ }
135
+ if (metadata?.source) {
136
+ creditsData.purchaseSource = metadata.source;
137
+ }
138
+ if (metadata?.type) {
139
+ creditsData.purchaseType = purchaseType;
140
+ }
141
+ if (purchaseHistory && purchaseHistory.length > 0) {
142
+ creditsData.purchaseHistory = purchaseHistory;
143
+ }
144
+
132
145
  transaction.set(creditsRef, creditsData, { merge: true });
133
146
 
134
147
  return { credits: newCredits };
@@ -40,15 +40,25 @@ export const initializeSubscription = async (config: SubscriptionInitConfig): Pr
40
40
  configureCreditsRepository({ ...credits, creditPackageAmounts: creditPackages?.amounts });
41
41
 
42
42
  const onPurchase = async (userId: string, productId: string, _customerInfo: unknown, source?: string) => {
43
+ if (__DEV__) {
44
+ console.log('[SubscriptionInitializer] onPurchase called:', { userId, productId, source });
45
+ }
43
46
  try {
44
- await getCreditsRepository().initializeCredits(
47
+ const result = await getCreditsRepository().initializeCredits(
45
48
  userId,
46
49
  `purchase_${productId}_${Date.now()}`,
47
50
  productId,
48
51
  source as any
49
52
  );
53
+ if (__DEV__) {
54
+ console.log('[SubscriptionInitializer] Credits initialized:', result);
55
+ }
50
56
  onCreditsUpdated?.(userId);
51
- } catch { /* Silent */ }
57
+ } catch (error) {
58
+ if (__DEV__) {
59
+ console.error('[SubscriptionInitializer] Credits init failed:', error);
60
+ }
61
+ }
52
62
  };
53
63
 
54
64
  const onRenewal = async (userId: string, productId: string, renewalId: string) => {
@@ -37,6 +37,8 @@ export async function syncPremiumStatus(
37
37
  }
38
38
  }
39
39
 
40
+ declare const __DEV__: boolean;
41
+
40
42
  export async function notifyPurchaseCompleted(
41
43
  config: RevenueCatConfig,
42
44
  userId: string,
@@ -44,14 +46,31 @@ export async function notifyPurchaseCompleted(
44
46
  customerInfo: CustomerInfo,
45
47
  source?: string
46
48
  ): Promise<void> {
49
+ if (__DEV__) {
50
+ console.log('[PremiumStatusSyncer] notifyPurchaseCompleted called:', {
51
+ userId,
52
+ productId,
53
+ source,
54
+ hasCallback: !!config.onPurchaseCompleted,
55
+ });
56
+ }
57
+
47
58
  if (!config.onPurchaseCompleted) {
59
+ if (__DEV__) {
60
+ console.warn('[PremiumStatusSyncer] No onPurchaseCompleted callback configured!');
61
+ }
48
62
  return;
49
63
  }
50
64
 
51
65
  try {
52
66
  await config.onPurchaseCompleted(userId, productId, customerInfo, source);
53
- } catch {
54
- // Silent error handling
67
+ if (__DEV__) {
68
+ console.log('[PremiumStatusSyncer] onPurchaseCompleted callback executed successfully');
69
+ }
70
+ } catch (error) {
71
+ if (__DEV__) {
72
+ console.error('[PremiumStatusSyncer] onPurchaseCompleted callback failed:', error);
73
+ }
55
74
  }
56
75
  }
57
76