@umituz/react-native-subscription 2.15.5 → 2.15.7
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.15.
|
|
3
|
+
"version": "2.15.7",
|
|
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",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
60
60
|
"@typescript-eslint/parser": "^8.50.1",
|
|
61
61
|
"@umituz/react-native-auth": "^3.4.26",
|
|
62
|
-
"@umituz/react-native-design-system": "^2.
|
|
62
|
+
"@umituz/react-native-design-system": "^2.8.5",
|
|
63
63
|
"@umituz/react-native-filesystem": "^2.1.21",
|
|
64
64
|
"@umituz/react-native-firebase": "*",
|
|
65
65
|
"@umituz/react-native-haptics": "^1.0.5",
|
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @see https://developer.apple.com/documentation/storekit/in-app_purchase/testing_in-app_purchases_with_sandbox
|
|
2
|
+
* Subscription Duration Configuration
|
|
3
|
+
* Production subscription durations by package type
|
|
6
4
|
*/
|
|
7
5
|
|
|
8
6
|
import type { SubscriptionPackageType } from '../../../utils/packageTypeDetector';
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
|
-
*
|
|
9
|
+
* Subscription durations in days
|
|
12
10
|
*/
|
|
13
|
-
export const
|
|
14
|
-
weekly: 3,
|
|
15
|
-
monthly: 5,
|
|
16
|
-
yearly: 60,
|
|
17
|
-
unknown: 5,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Production subscription durations in days
|
|
22
|
-
*/
|
|
23
|
-
export const PRODUCTION_DURATIONS: Record<SubscriptionPackageType, number> = {
|
|
11
|
+
export const SUBSCRIPTION_DURATIONS: Record<SubscriptionPackageType, number> = {
|
|
24
12
|
weekly: 7,
|
|
25
13
|
monthly: 30,
|
|
26
14
|
yearly: 365,
|
|
@@ -28,15 +16,8 @@ export const PRODUCTION_DURATIONS: Record<SubscriptionPackageType, number> = {
|
|
|
28
16
|
};
|
|
29
17
|
|
|
30
18
|
/**
|
|
31
|
-
* Get
|
|
19
|
+
* Get subscription duration in days for a package type
|
|
32
20
|
*/
|
|
33
21
|
export function getProductionDurationDays(packageType: SubscriptionPackageType): number {
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Get sandbox duration in minutes for a package type
|
|
39
|
-
*/
|
|
40
|
-
export function getSandboxDurationMinutes(packageType: SubscriptionPackageType): number {
|
|
41
|
-
return SANDBOX_DURATIONS[packageType] ?? SANDBOX_DURATIONS.unknown;
|
|
22
|
+
return SUBSCRIPTION_DURATIONS[packageType] ?? SUBSCRIPTION_DURATIONS.unknown;
|
|
42
23
|
}
|
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Expiration Date Calculator
|
|
3
|
-
*
|
|
3
|
+
* Handles RevenueCat expiration date edge case
|
|
4
|
+
*
|
|
5
|
+
* Problem: RevenueCat sometimes returns expiration date = purchase date
|
|
6
|
+
* Solution: If same day, add subscription period based on package type
|
|
4
7
|
*/
|
|
5
8
|
|
|
6
9
|
import type { RevenueCatEntitlement } from '../../domain/types/RevenueCatTypes';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
import { detectPackageType } from '../../../utils/packageTypeDetector';
|
|
11
|
+
import { addProductionPeriod } from './SandboxDurationConverter';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Check if two dates are on the same day
|
|
15
|
+
*/
|
|
16
|
+
function isSameDay(date1: Date, date2: Date): boolean {
|
|
17
|
+
return (
|
|
18
|
+
date1.getFullYear() === date2.getFullYear() &&
|
|
19
|
+
date1.getMonth() === date2.getMonth() &&
|
|
20
|
+
date1.getDate() === date2.getDate()
|
|
21
|
+
);
|
|
22
|
+
}
|
|
12
23
|
|
|
13
24
|
/**
|
|
14
|
-
* Get
|
|
25
|
+
* Get expiration date from entitlement
|
|
15
26
|
*
|
|
16
|
-
* Handles:
|
|
17
|
-
*
|
|
18
|
-
* 2. Past expiration: Adds subscription period if expiration is in the past
|
|
27
|
+
* Handles edge case: If expiration date equals purchase date (same day),
|
|
28
|
+
* calculates correct expiration by adding subscription period.
|
|
19
29
|
*/
|
|
20
30
|
export function getExpirationDate(
|
|
21
31
|
entitlement: RevenueCatEntitlement | null
|
|
@@ -24,14 +34,16 @@ export function getExpirationDate(
|
|
|
24
34
|
return null;
|
|
25
35
|
}
|
|
26
36
|
|
|
27
|
-
const
|
|
37
|
+
const expDate = new Date(entitlement.expirationDate);
|
|
38
|
+
const purchaseDate = entitlement.latestPurchaseDate
|
|
39
|
+
? new Date(entitlement.latestPurchaseDate)
|
|
40
|
+
: null;
|
|
28
41
|
|
|
29
|
-
if (
|
|
30
|
-
|
|
42
|
+
// Only adjust if expiration equals purchase date (same day bug)
|
|
43
|
+
if (purchaseDate && isSameDay(expDate, purchaseDate)) {
|
|
44
|
+
const packageType = detectPackageType(entitlement.productIdentifier);
|
|
45
|
+
return addProductionPeriod(purchaseDate, packageType).toISOString();
|
|
31
46
|
}
|
|
32
47
|
|
|
33
|
-
|
|
34
|
-
const adjustedDate = adjustPastExpiration(expDate, productIdentifier);
|
|
35
|
-
|
|
36
|
-
return adjustedDate.toISOString();
|
|
48
|
+
return entitlement.expirationDate;
|
|
37
49
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Subscription Duration Utilities
|
|
3
|
+
* Calculates subscription period based on package type
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import type { SubscriptionPackageType } from '../../../utils/packageTypeDetector';
|
|
7
7
|
import { getProductionDurationDays } from '../config/SandboxDurationConfig';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Add
|
|
10
|
+
* Add subscription period to a date based on package type
|
|
11
11
|
*/
|
|
12
12
|
export function addProductionPeriod(
|
|
13
13
|
date: Date,
|
|
@@ -18,51 +18,3 @@ export function addProductionPeriod(
|
|
|
18
18
|
newDate.setDate(newDate.getDate() + daysToAdd);
|
|
19
19
|
return newDate;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Check if sandbox conversion should be applied
|
|
24
|
-
* Only applies in DEV mode with sandbox flag
|
|
25
|
-
*/
|
|
26
|
-
export function shouldConvertSandbox(isSandbox: boolean): boolean {
|
|
27
|
-
return isSandbox && __DEV__;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Convert sandbox expiration to production-equivalent expiration
|
|
32
|
-
*
|
|
33
|
-
* In Apple Sandbox:
|
|
34
|
-
* - Weekly subscriptions expire in 3 minutes
|
|
35
|
-
* - Monthly subscriptions expire in 5 minutes
|
|
36
|
-
* - Yearly subscriptions expire in 1 hour
|
|
37
|
-
*
|
|
38
|
-
* For better testing UX, we calculate the production-equivalent expiration
|
|
39
|
-
* based on the purchase date + production duration.
|
|
40
|
-
*/
|
|
41
|
-
export function convertToProductionExpiration(
|
|
42
|
-
purchaseDate: string | null,
|
|
43
|
-
productIdentifier: string
|
|
44
|
-
): string {
|
|
45
|
-
const basePurchaseDate = purchaseDate ? new Date(purchaseDate) : new Date();
|
|
46
|
-
const packageType = detectPackageType(productIdentifier);
|
|
47
|
-
const productionExpiration = addProductionPeriod(basePurchaseDate, packageType);
|
|
48
|
-
|
|
49
|
-
return productionExpiration.toISOString();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Adjust expiration date if it's in the past
|
|
54
|
-
* Adds subscription period to prevent false expiration
|
|
55
|
-
*/
|
|
56
|
-
export function adjustPastExpiration(
|
|
57
|
-
expirationDate: Date,
|
|
58
|
-
productIdentifier: string
|
|
59
|
-
): Date {
|
|
60
|
-
const now = new Date();
|
|
61
|
-
|
|
62
|
-
if (expirationDate > now) {
|
|
63
|
-
return expirationDate;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const packageType = detectPackageType(productIdentifier);
|
|
67
|
-
return addProductionPeriod(expirationDate, packageType);
|
|
68
|
-
}
|