Skip to content

Commit

Permalink
fix: premium detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Dec 17, 2024
1 parent 8aad66d commit 7c59652
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
26 changes: 24 additions & 2 deletions components/screens/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,43 @@ const SubscriptionInfo = ({ dynamicStyles }) => {
const getSubscriptionStatus = async () => {
try {
const info = await Purchases.getCustomerInfo();
console.log("Customer info in Settings:", {
entitlements: info.entitlements,
activeEntitlements: info.entitlements.active,
allPurchasedProductIds: info.allPurchasedProductIdentifiers,
latestPurchaseDate: info.latestExpirationDate,
});

if (
info.entitlements.active !== undefined &&
Object.keys(info.entitlements.active).length > 0
) {
const plan = info.entitlements.active.pro?.productIdentifier.includes(
const activeEntitlement = info.entitlements.active.premium;
console.log("Active entitlement details:", {
identifier: activeEntitlement?.productIdentifier,
willRenew: activeEntitlement?.willRenew,
periodType: activeEntitlement?.periodType,
originalPurchaseDate: activeEntitlement?.originalPurchaseDate,
});

const plan = activeEntitlement?.productIdentifier?.includes(
"lifetime"
)
? "Lifetime Access"
: "Premium";
console.log("Determined plan:", plan);
setSubscriptionStatus(plan);
} else {
console.log("No active entitlements found in Settings");
setSubscriptionStatus("Free Plan");
}
} catch (error) {
console.error("Error fetching subscription status:", error);
console.error("Error fetching subscription status:", {
error,
message: error.message,
code: error.code,
details: error.details,
});
setSubscriptionStatus("Unknown");
} finally {
setLoading(false);
Expand Down
24 changes: 23 additions & 1 deletion components/screens/onboarding/Subscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,41 @@ export default function Subscription({

const handleSkip = async () => {
try {
console.log("Starting restore purchases...");
const info = await Purchases.restorePurchases();
console.log("Restore purchases response:", {
entitlements: info.entitlements,
activeEntitlements: info.entitlements.active,
allPurchasedProductIds: info.allPurchasedProductIdentifiers,
latestPurchaseDate: info.latestExpirationDate,
});

if (
info.entitlements.active !== undefined &&
Object.keys(info.entitlements.active).length > 0
) {
console.log("Found active entitlements:", info.entitlements.active);
const hasLifetime =
info.entitlements.active.premium?.productIdentifier?.includes(
"lifetime"
);
console.log("Has lifetime subscription:", hasLifetime);

if (setIsSubscribed) {
setIsSubscribed(true);
} else {
setHasCompletedOnboarding(true);
}
} else {
console.log("No active entitlements found");
}
} catch (error) {
console.error("Error restoring purchases:", error);
console.error("Error restoring purchases:", {
error,
message: error.message,
code: error.code,
details: error.details,
});
}
};

Expand Down

0 comments on commit 7c59652

Please sign in to comment.