diff --git a/src/routes/payment/+server.ts b/src/routes/payment/+server.ts index 2d91d188..4710cc71 100644 --- a/src/routes/payment/+server.ts +++ b/src/routes/payment/+server.ts @@ -37,12 +37,30 @@ function isValidSignature(payload, signatureHeader) { * @param {boolean} refunded - Whether the payment was refunded. * @returns {string} - "Pro" if conditions match, otherwise "Free". */ -function determineTier(status, refunded) { - // List of statuses that qualify for the "Pro" tier if not refunded - const proStatuses = new Set(["paid", "active", "cancelled", "on_trial"]); - return !refunded && proStatuses.has(status) ? "Pro" : "Free"; +function determineTier(productName, status, refunded) { + // Define statuses that qualify for the "Pro" tier if not refunded. + const condition = new Set(["paid", "active", "cancelled", "on_trial"]); + // First, ensure the product is not refunded and the status qualifies. + if (refunded || !condition.has(status)) { + return "Free"; + } + + // At this point, refunded is false and the status qualifies. + // Check productName for tier-specific keywords. + if (productName) { + if (productName.includes("Plus")) { + return "Plus"; + } + if (productName.includes("Pro") || productName.includes("Life Time")) { + return "Pro"; + } + } + + // Fallback: if no product name conditions are met, default to "Pro" (per the original logic). + return "Pro"; } + export const POST = async ({ request, locals }) => { try { const bodyText = await request.text(); @@ -89,8 +107,10 @@ export const POST = async ({ request, locals }) => { ); } - const tier = determineTier(status, refunded); - + + const tier = determineTier(payload?.data?.attributes?.product_name, status, refunded); + //console.log(tier, payload?.data?.attributes?.product_name) + // Update the user and log the payment try { diff --git a/src/routes/profile/+page.svelte b/src/routes/profile/+page.svelte index 16d83061..c58f564c 100644 --- a/src/routes/profile/+page.svelte +++ b/src/routes/profile/+page.svelte @@ -126,52 +126,6 @@ }; }; - const submitChangePlan = () => { - return async ({ result, update }) => { - switch (result.type) { - case "success": - toast.success("Changing to Annual Plan successfully!", { - style: - "border-radius: 5px; background: #fff; color: #000; border-color: #4B5563; font-size: 15px;", - }); - await update(); - break; - case "redirect": - toast.success("Changing to Annual Plan successfully!", { - style: - "border-radius: 5px; background: #fff; color: #000; border-color: #4B5563; font-size: 15px;", - }); - await update(); - break; - case "failure": - toast.error("Something went wrong.", { - style: - "border-radius: 5px; background: #fff; color: #000; border-color: #4B5563; font-size: 15px;", - }); - await update(); - break; - case "error": - toast.error(result.error.message, { - style: - "border-radius: 5px; background: #fff; color: #000; border-color: #4B5563; font-size: 15px;", - }); - break; - default: - await update(); - } - - setTimeout(() => { - if (result.type === "redirect") { - const anchor = document.createElement("a"); - anchor.href = "/profile"; - anchor.dataset.sveltekitReload = true; - document.body.appendChild(anchor); - anchor.dispatchEvent(new MouseEvent("click")); - } - }, 5000); - }; - }; - onMount(async () => { pwaInstalled = isPWAInstalled(); nottifPermGranted = await requestNotificationPermission(); @@ -526,23 +480,6 @@ > Cancel Subscription - {#if subscriptionData?.product_name?.includes("Monthly")} - - {/if} {:else if subscriptionData?.status_formatted === "Cancelled"}