diff --git a/app/api/debug/cancel-subscription.ts b/app/api/debug/cancel-subscription.ts new file mode 100644 index 0000000..e2f683d --- /dev/null +++ b/app/api/debug/cancel-subscription.ts @@ -0,0 +1,19 @@ +import type { BlitzApiHandler } from "blitz"; + +import { cancelPaddleSubscription } from "../../../integrations/paddle"; +import appLogger from "../../../integrations/logger"; + +const logger = appLogger.child({ route: "/api/debug/cancel-subscription" }); + +const cancelSubscriptionHandler: BlitzApiHandler = async (req, res) => { + const { subscriptionId } = req.body; + + logger.debug(`cancelling subscription for subscriptionId="${subscriptionId}"`); + const result = await cancelPaddleSubscription({ subscriptionId }); + logger.debug(`cancelled subscription for subscriptionId="${subscriptionId}"`); + logger.debug(result as object); + + res.status(200).end(); +}; + +export default cancelSubscriptionHandler; diff --git a/app/phone-calls/hooks/use-device.tsx b/app/phone-calls/hooks/use-device.tsx index 117010c..c69cfba 100644 --- a/app/phone-calls/hooks/use-device.tsx +++ b/app/phone-calls/hooks/use-device.tsx @@ -54,6 +54,7 @@ export default function useDevice() { device.on("incoming", onDeviceIncoming); return () => { + // TODO: device.off is not a function device.off("registered", onDeviceRegistered); device.off("unregistered", onDeviceUnregistered); device.off("error", onDeviceError); diff --git a/app/phone-calls/hooks/use-make-call.ts b/app/phone-calls/hooks/use-make-call.ts index b14a8b5..24e6deb 100644 --- a/app/phone-calls/hooks/use-make-call.ts +++ b/app/phone-calls/hooks/use-make-call.ts @@ -86,6 +86,7 @@ export default function useMakeCall({ recipient, onHangUp }: Params) { device?.destroy(); onHangUp?.(); router.replace(Routes.KeypadPage()); + // TODO: outgoingConnection.off is not a function outgoingConnection?.off("cancel", endCall); outgoingConnection?.off("disconnect", endCall); }, diff --git a/app/settings/api/queue/delete-user-data.ts b/app/settings/api/queue/delete-user-data.ts index 654be73..627d51e 100644 --- a/app/settings/api/queue/delete-user-data.ts +++ b/app/settings/api/queue/delete-user-data.ts @@ -2,6 +2,7 @@ import { Queue } from "quirrel/blitz"; import db, { MembershipRole } from "../../../../db"; import appLogger from "../../../../integrations/logger"; +import { cancelPaddleSubscription } from "../../../../integrations/paddle"; const logger = appLogger.child({ queue: "delete-user-data" }); @@ -16,7 +17,7 @@ const deleteUserData = Queue("api/queue/delete-user-data", async ({ use memberships: { include: { organization: { - include: { memberships: { include: { user: true } } }, + include: { subscription: true }, }, }, }, @@ -31,6 +32,11 @@ const deleteUserData = Queue("api/queue/delete-user-data", async ({ use const organization = user.memberships[0]!.organization; await db.organization.delete({ where: { id: organization.id } }); await db.user.delete({ where: { id: user.id } }); + + if (organization.subscription) { + await cancelPaddleSubscription({ subscriptionId: organization.subscription.paddleSubscriptionId }); + } + break; } case MembershipRole.USER: { diff --git a/app/settings/components/billing/billing-history.tsx b/app/settings/components/billing/billing-history.tsx index 1035195..65087fc 100644 --- a/app/settings/components/billing/billing-history.tsx +++ b/app/settings/components/billing/billing-history.tsx @@ -53,7 +53,7 @@ export default function BillingHistory() { {payment.amount} {payment.currency} - {payment.is_paid === 1 ? "Paid" : "Not paid yet"} + {payment.is_paid === 1 ? "Paid" : "Upcoming"} {typeof payment.receipt_url !== "undefined" ? ( diff --git a/app/settings/components/billing/plans.tsx b/app/settings/components/billing/plans.tsx index 4f80bea..b69be83 100644 --- a/app/settings/components/billing/plans.tsx +++ b/app/settings/components/billing/plans.tsx @@ -10,7 +10,10 @@ export default function Plans() { return (
{pricing.tiers.map((tier) => { - const isCurrentTier = subscription?.paddlePlanId === tier.planId; + const isCurrentTier = + !subscription?.paddlePlanId && tier.planId === "free" + ? true + : subscription?.paddlePlanId === tier.planId; const cta = isCurrentTier ? "Current plan" : !!subscription ? `Switch to ${tier.title}` : "Subscribe"; return (