@umituz/react-native-subscription 2.19.5 → 2.20.0

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.5",
3
+ "version": "2.20.0",
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",
@@ -61,20 +61,11 @@ export const initializeSubscription = async (config: SubscriptionInitConfig): Pr
61
61
  }
62
62
  };
63
63
 
64
- const onRenewal = async (userId: string, productId: string, renewalId: string) => {
65
- try {
66
- await getCreditsRepository().initializeCredits(
67
- userId,
68
- renewalId,
69
- productId,
70
- undefined
71
- );
72
- onCreditsUpdated?.(userId);
73
- } catch { /* Silent */ }
74
- };
64
+ // Note: Renewal credits should be handled server-side via RevenueCat webhooks + Cloud Functions
65
+ // Client-side listener cannot reliably detect renewals vs new purchases
75
66
 
76
67
  SubscriptionManager.configure({
77
- config: { apiKey: key, testStoreKey, entitlementIdentifier: entitlementId, consumableProductIdentifiers: [creditPackages?.identifierPattern || "credit"], onCreditRenewal: onRenewal, onPurchaseCompleted: onPurchase, onCreditsUpdated },
68
+ config: { apiKey: key, testStoreKey, entitlementIdentifier: entitlementId, consumableProductIdentifiers: [creditPackages?.identifierPattern || "credit"], onPurchaseCompleted: onPurchase, onCreditsUpdated },
78
69
  apiKey: key, getAnonymousUserId
79
70
  });
80
71
 
@@ -34,12 +34,6 @@ export interface RevenueCatConfig {
34
34
  isPremium: boolean,
35
35
  customerInfo: CustomerInfo
36
36
  ) => Promise<void> | void;
37
- /** Callback for credit renewal (subscription auto-renewal) */
38
- onCreditRenewal?: (
39
- userId: string,
40
- productId: string,
41
- renewalId: string
42
- ) => Promise<void> | void;
43
37
  /** Callback after credits are successfully updated (for cache invalidation) */
44
38
  onCreditsUpdated?: (userId: string) => void;
45
39
  }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Customer Info Listener Manager
3
3
  * Handles RevenueCat customer info update listeners
4
+ * Only syncs premium status - renewal handling should be done server-side via webhooks
4
5
  */
5
6
 
6
7
  import Purchases, {
@@ -13,10 +14,9 @@ import { syncPremiumStatus } from "../utils/PremiumStatusSyncer";
13
14
  export class CustomerInfoListenerManager {
14
15
  private listener: CustomerInfoUpdateListener | null = null;
15
16
  private currentUserId: string | null = null;
16
- private entitlementIdentifier: string;
17
17
 
18
- constructor(entitlementIdentifier: string) {
19
- this.entitlementIdentifier = entitlementIdentifier;
18
+ constructor(_entitlementIdentifier: string) {
19
+ // entitlementIdentifier kept for API compatibility
20
20
  }
21
21
 
22
22
  setUserId(userId: string): void {
@@ -27,6 +27,10 @@ export class CustomerInfoListenerManager {
27
27
  this.currentUserId = null;
28
28
  }
29
29
 
30
+ notifyPurchaseCompleted(): void {
31
+ // Reserved for future use if needed
32
+ }
33
+
30
34
  setupListener(config: RevenueCatConfig): void {
31
35
  this.removeListener();
32
36
 
@@ -35,33 +39,7 @@ export class CustomerInfoListenerManager {
35
39
  return;
36
40
  }
37
41
 
38
- const hasPremium =
39
- !!customerInfo.entitlements.active[this.entitlementIdentifier];
40
-
41
- if (hasPremium && config.onCreditRenewal) {
42
- const premiumEntitlement =
43
- customerInfo.entitlements.active[this.entitlementIdentifier];
44
-
45
- if (premiumEntitlement && premiumEntitlement.expirationDate) {
46
- const productId = premiumEntitlement.productIdentifier;
47
- const renewalId = `renewal_${productId}_${premiumEntitlement.expirationDate}`;
48
-
49
- try {
50
- await config.onCreditRenewal(
51
- this.currentUserId,
52
- productId,
53
- renewalId
54
- );
55
-
56
- if (config.onCreditsUpdated && this.currentUserId) {
57
- config.onCreditsUpdated(this.currentUserId);
58
- }
59
- } catch {
60
- // Silent error handling
61
- }
62
- }
63
- }
64
-
42
+ // Only sync premium status - renewal credits handled server-side via webhooks
65
43
  syncPremiumStatus(config, this.currentUserId, customerInfo);
66
44
  };
67
45
 
@@ -89,7 +89,11 @@ export class RevenueCatService implements IRevenueCatService {
89
89
  pkg: PurchasesPackage,
90
90
  userId: string
91
91
  ): Promise<PurchaseResult> {
92
- return handlePurchase(this.getSDKParams(), pkg, userId);
92
+ const result = await handlePurchase(this.getSDKParams(), pkg, userId);
93
+ if (result.success) {
94
+ this.listenerManager.notifyPurchaseCompleted();
95
+ }
96
+ return result;
93
97
  }
94
98
 
95
99
  async restorePurchases(userId: string): Promise<RestoreResult> {