@umituz/react-native-subscription 2.11.22 → 2.11.23

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.11.22",
3
+ "version": "2.11.23",
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",
@@ -35,6 +35,12 @@ export interface RevenueCatConfig {
35
35
  isPremium: boolean,
36
36
  customerInfo: CustomerInfo
37
37
  ) => Promise<void> | void;
38
+ /** Callback for credit renewal (subscription auto-renewal) */
39
+ onCreditRenewal?: (
40
+ userId: string,
41
+ productId: string,
42
+ renewalId: string
43
+ ) => Promise<void> | void;
38
44
  }
39
45
 
40
46
  export interface RevenueCatConfigRequired {
@@ -35,7 +35,7 @@ export class CustomerInfoListenerManager {
35
35
  userId: this.currentUserId,
36
36
  });
37
37
 
38
- this.listener = (customerInfo: CustomerInfo) => {
38
+ this.listener = async (customerInfo: CustomerInfo) => {
39
39
  if (!this.currentUserId) return;
40
40
 
41
41
  const hasPremium =
@@ -47,6 +47,54 @@ export class CustomerInfoListenerManager {
47
47
  entitlementIdentifier: this.entitlementIdentifier,
48
48
  });
49
49
 
50
+ // Handle credit renewal for subscription renewals
51
+ if (hasPremium && config.onCreditRenewal) {
52
+ const premiumEntitlement =
53
+ customerInfo.entitlements.active[this.entitlementIdentifier];
54
+
55
+ if (premiumEntitlement && premiumEntitlement.expirationDate) {
56
+ const productId = premiumEntitlement.productIdentifier;
57
+ const renewalId = `renewal_${productId}_${premiumEntitlement.expirationDate}`;
58
+
59
+ addPackageBreadcrumb(
60
+ "subscription",
61
+ "Processing credit renewal",
62
+ {
63
+ userId: this.currentUserId,
64
+ productId,
65
+ renewalId,
66
+ }
67
+ );
68
+
69
+ try {
70
+ await config.onCreditRenewal(
71
+ this.currentUserId,
72
+ productId,
73
+ renewalId
74
+ );
75
+
76
+ addPackageBreadcrumb(
77
+ "subscription",
78
+ "Credit renewal completed",
79
+ {
80
+ userId: this.currentUserId,
81
+ productId,
82
+ }
83
+ );
84
+ } catch (error) {
85
+ addPackageBreadcrumb(
86
+ "subscription",
87
+ "Credit renewal failed",
88
+ {
89
+ userId: this.currentUserId,
90
+ productId,
91
+ error: error instanceof Error ? error.message : String(error),
92
+ }
93
+ );
94
+ }
95
+ }
96
+ }
97
+
50
98
  syncPremiumStatus(config, this.currentUserId, customerInfo);
51
99
  };
52
100