@umituz/react-native-subscription 2.37.37 → 2.37.38
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.37.
|
|
3
|
+
"version": "2.37.38",
|
|
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",
|
|
@@ -7,6 +7,7 @@ import { getCreditDocumentOrDefault } from "./creditDocumentHelpers";
|
|
|
7
7
|
import { calculateNewCredits, buildCreditsData, shouldSkipStatusSyncWrite } from "./creditOperationUtils";
|
|
8
8
|
import { calculateCreditLimit } from "./CreditLimitCalculator";
|
|
9
9
|
import { generatePurchaseMetadata } from "./PurchaseMetadataGenerator";
|
|
10
|
+
import { PURCHASE_ID_PREFIXES } from "../core/CreditsConstants";
|
|
10
11
|
|
|
11
12
|
export async function initializeCreditsTransaction(
|
|
12
13
|
_db: Firestore,
|
|
@@ -21,6 +22,18 @@ export async function initializeCreditsTransaction(
|
|
|
21
22
|
|
|
22
23
|
return runTransaction(async (transaction: Transaction) => {
|
|
23
24
|
const creditsDoc = await transaction.get(creditsRef);
|
|
25
|
+
|
|
26
|
+
// Status sync must NEVER create new documents.
|
|
27
|
+
// Credits documents are only created by purchase/renewal flows.
|
|
28
|
+
const isStatusSync = purchaseId.startsWith(PURCHASE_ID_PREFIXES.STATUS_SYNC);
|
|
29
|
+
if (isStatusSync && !creditsDoc.exists()) {
|
|
30
|
+
return {
|
|
31
|
+
credits: 0,
|
|
32
|
+
alreadyProcessed: true,
|
|
33
|
+
finalData: null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
24
37
|
const existingData = getCreditDocumentOrDefault(creditsDoc, platform);
|
|
25
38
|
|
|
26
39
|
if (existingData.processedPurchases.includes(purchaseId)) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ICreditStrategy, type CreditAllocationParams } from "./ICreditStrategy";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Strategy for
|
|
5
|
-
*
|
|
4
|
+
* Strategy for status synchronization (app open, auth state changes).
|
|
5
|
+
* ONLY preserves existing credits. NEVER allocates new credits.
|
|
6
|
+
* New credits are ONLY allocated by purchase and renewal flows.
|
|
6
7
|
*/
|
|
7
8
|
export class SyncCreditStrategy implements ICreditStrategy {
|
|
8
9
|
canHandle(params: CreditAllocationParams): boolean {
|
|
@@ -10,18 +11,14 @@ export class SyncCreditStrategy implements ICreditStrategy {
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
execute(params: CreditAllocationParams): number {
|
|
14
|
+
// Status sync only preserves existing credits, never allocates new ones
|
|
13
15
|
const existingCredits = params.existingData?.credits;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (params.isSubscriptionActive && !hasExistingDocument) {
|
|
18
|
-
return params.creditLimit;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (hasExistingCredits && params.existingData) {
|
|
22
|
-
return params.existingData.credits;
|
|
16
|
+
if (typeof existingCredits === 'number' && existingCredits >= 0) {
|
|
17
|
+
return existingCredits;
|
|
23
18
|
}
|
|
24
19
|
|
|
25
|
-
return
|
|
20
|
+
// No existing credits = no document = return 0
|
|
21
|
+
// Credits are only allocated through purchase/renewal flows
|
|
22
|
+
return 0;
|
|
26
23
|
}
|
|
27
24
|
}
|