@umituz/react-native-subscription 2.14.54 → 2.14.55
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.14.
|
|
3
|
+
"version": "2.14.55",
|
|
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",
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PaywallContainer Component
|
|
3
|
+
* Package-driven paywall that encapsulates all logic
|
|
4
|
+
* Main app only needs to add this ONE component
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React, { useCallback } from "react";
|
|
8
|
+
import type { PurchasesPackage } from "react-native-purchases";
|
|
9
|
+
import { usePaywallVisibility } from "../../../presentation/hooks/usePaywallVisibility";
|
|
10
|
+
import { useSubscriptionPackages } from "../../../revenuecat/presentation/hooks/useSubscriptionPackages";
|
|
11
|
+
import { usePurchasePackage } from "../../../revenuecat/presentation/hooks/usePurchasePackage";
|
|
12
|
+
import { useRestorePurchase } from "../../../revenuecat/presentation/hooks/useRestorePurchase";
|
|
13
|
+
import { PaywallModal } from "./PaywallModal";
|
|
14
|
+
import type { PaywallContainerProps } from "./PaywallContainer.types";
|
|
15
|
+
|
|
16
|
+
declare const __DEV__: boolean;
|
|
17
|
+
|
|
18
|
+
export const PaywallContainer: React.FC<PaywallContainerProps> = ({
|
|
19
|
+
userId,
|
|
20
|
+
translations,
|
|
21
|
+
mode = "subscription",
|
|
22
|
+
legalUrls,
|
|
23
|
+
features,
|
|
24
|
+
heroImage,
|
|
25
|
+
bestValueIdentifier,
|
|
26
|
+
creditsLabel,
|
|
27
|
+
onPurchaseSuccess,
|
|
28
|
+
onPurchaseError,
|
|
29
|
+
}) => {
|
|
30
|
+
const { showPaywall, closePaywall } = usePaywallVisibility();
|
|
31
|
+
const { data: packages = [], isLoading } = useSubscriptionPackages(userId ?? undefined);
|
|
32
|
+
const { mutateAsync: purchasePackage } = usePurchasePackage(userId ?? undefined);
|
|
33
|
+
const { mutateAsync: restorePurchases } = useRestorePurchase(userId ?? undefined);
|
|
34
|
+
|
|
35
|
+
const handlePurchase = useCallback(
|
|
36
|
+
async (pkg: PurchasesPackage) => {
|
|
37
|
+
try {
|
|
38
|
+
if (__DEV__) {
|
|
39
|
+
console.log("[PaywallContainer] Purchase started:", pkg.identifier);
|
|
40
|
+
}
|
|
41
|
+
const result = await purchasePackage(pkg);
|
|
42
|
+
if (result.success) {
|
|
43
|
+
if (__DEV__) {
|
|
44
|
+
console.log("[PaywallContainer] Purchase successful");
|
|
45
|
+
}
|
|
46
|
+
onPurchaseSuccess?.();
|
|
47
|
+
closePaywall();
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
51
|
+
if (__DEV__) {
|
|
52
|
+
console.error("[PaywallContainer] Purchase failed:", message);
|
|
53
|
+
}
|
|
54
|
+
onPurchaseError?.(message);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[purchasePackage, closePaywall, onPurchaseSuccess, onPurchaseError],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const handleRestore = useCallback(async () => {
|
|
61
|
+
try {
|
|
62
|
+
if (__DEV__) {
|
|
63
|
+
console.log("[PaywallContainer] Restore started");
|
|
64
|
+
}
|
|
65
|
+
const result = await restorePurchases();
|
|
66
|
+
if (result.success) {
|
|
67
|
+
if (__DEV__) {
|
|
68
|
+
console.log("[PaywallContainer] Restore successful");
|
|
69
|
+
}
|
|
70
|
+
onPurchaseSuccess?.();
|
|
71
|
+
closePaywall();
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
75
|
+
if (__DEV__) {
|
|
76
|
+
console.error("[PaywallContainer] Restore failed:", message);
|
|
77
|
+
}
|
|
78
|
+
onPurchaseError?.(message);
|
|
79
|
+
}
|
|
80
|
+
}, [restorePurchases, closePaywall, onPurchaseSuccess, onPurchaseError]);
|
|
81
|
+
|
|
82
|
+
if (!showPaywall) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<PaywallModal
|
|
88
|
+
visible={showPaywall}
|
|
89
|
+
onClose={closePaywall}
|
|
90
|
+
mode={mode}
|
|
91
|
+
translations={translations}
|
|
92
|
+
subscriptionPackages={packages}
|
|
93
|
+
isLoading={isLoading}
|
|
94
|
+
legalUrls={legalUrls}
|
|
95
|
+
features={features ? [...features] : undefined}
|
|
96
|
+
heroImage={heroImage}
|
|
97
|
+
bestValueIdentifier={bestValueIdentifier}
|
|
98
|
+
creditsLabel={creditsLabel}
|
|
99
|
+
onSubscriptionPurchase={handlePurchase}
|
|
100
|
+
onRestore={handleRestore}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
PaywallContainer.displayName = "PaywallContainer";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PaywallContainer Types
|
|
3
|
+
* Minimal props for package-driven paywall rendering
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { PaywallMode, PaywallTranslations, PaywallLegalUrls, SubscriptionFeature } from "../entities";
|
|
7
|
+
import type { ImageSourcePropType } from "react-native";
|
|
8
|
+
|
|
9
|
+
export interface PaywallContainerProps {
|
|
10
|
+
/** User ID for subscription management */
|
|
11
|
+
readonly userId: string | null;
|
|
12
|
+
/** Paywall translations - no defaults, must be provided */
|
|
13
|
+
readonly translations: PaywallTranslations;
|
|
14
|
+
/** Paywall mode - subscription, credits, or hybrid */
|
|
15
|
+
readonly mode?: PaywallMode;
|
|
16
|
+
/** Legal URLs for privacy and terms */
|
|
17
|
+
readonly legalUrls?: PaywallLegalUrls;
|
|
18
|
+
/** Feature list to display */
|
|
19
|
+
readonly features?: readonly SubscriptionFeature[];
|
|
20
|
+
/** Hero image for paywall header */
|
|
21
|
+
readonly heroImage?: ImageSourcePropType;
|
|
22
|
+
/** Best value package identifier for badge */
|
|
23
|
+
readonly bestValueIdentifier?: string;
|
|
24
|
+
/** Credits label text */
|
|
25
|
+
readonly creditsLabel?: string;
|
|
26
|
+
/** Callback when purchase succeeds */
|
|
27
|
+
readonly onPurchaseSuccess?: () => void;
|
|
28
|
+
/** Callback when purchase fails */
|
|
29
|
+
readonly onPurchaseError?: (error: string) => void;
|
|
30
|
+
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* Paywall Components Index
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
export { PaywallContainer } from "./PaywallContainer";
|
|
6
|
+
export type { PaywallContainerProps } from "./PaywallContainer.types";
|
|
7
|
+
|
|
5
8
|
export { PaywallModal } from "./PaywallModal";
|
|
6
9
|
export type { PaywallModalProps } from "./PaywallModal";
|
|
7
10
|
|