cancel subscription on account deletion
This commit is contained in:
parent
c5f135fdcc
commit
188c028667
19
app/api/debug/cancel-subscription.ts
Normal file
19
app/api/debug/cancel-subscription.ts
Normal file
@ -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;
|
@ -54,6 +54,7 @@ export default function useDevice() {
|
|||||||
device.on("incoming", onDeviceIncoming);
|
device.on("incoming", onDeviceIncoming);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
// TODO: device.off is not a function
|
||||||
device.off("registered", onDeviceRegistered);
|
device.off("registered", onDeviceRegistered);
|
||||||
device.off("unregistered", onDeviceUnregistered);
|
device.off("unregistered", onDeviceUnregistered);
|
||||||
device.off("error", onDeviceError);
|
device.off("error", onDeviceError);
|
||||||
|
@ -86,6 +86,7 @@ export default function useMakeCall({ recipient, onHangUp }: Params) {
|
|||||||
device?.destroy();
|
device?.destroy();
|
||||||
onHangUp?.();
|
onHangUp?.();
|
||||||
router.replace(Routes.KeypadPage());
|
router.replace(Routes.KeypadPage());
|
||||||
|
// TODO: outgoingConnection.off is not a function
|
||||||
outgoingConnection?.off("cancel", endCall);
|
outgoingConnection?.off("cancel", endCall);
|
||||||
outgoingConnection?.off("disconnect", endCall);
|
outgoingConnection?.off("disconnect", endCall);
|
||||||
},
|
},
|
||||||
|
@ -2,6 +2,7 @@ import { Queue } from "quirrel/blitz";
|
|||||||
|
|
||||||
import db, { MembershipRole } from "../../../../db";
|
import db, { MembershipRole } from "../../../../db";
|
||||||
import appLogger from "../../../../integrations/logger";
|
import appLogger from "../../../../integrations/logger";
|
||||||
|
import { cancelPaddleSubscription } from "../../../../integrations/paddle";
|
||||||
|
|
||||||
const logger = appLogger.child({ queue: "delete-user-data" });
|
const logger = appLogger.child({ queue: "delete-user-data" });
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ const deleteUserData = Queue<Payload>("api/queue/delete-user-data", async ({ use
|
|||||||
memberships: {
|
memberships: {
|
||||||
include: {
|
include: {
|
||||||
organization: {
|
organization: {
|
||||||
include: { memberships: { include: { user: true } } },
|
include: { subscription: true },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -31,6 +32,11 @@ const deleteUserData = Queue<Payload>("api/queue/delete-user-data", async ({ use
|
|||||||
const organization = user.memberships[0]!.organization;
|
const organization = user.memberships[0]!.organization;
|
||||||
await db.organization.delete({ where: { id: organization.id } });
|
await db.organization.delete({ where: { id: organization.id } });
|
||||||
await db.user.delete({ where: { id: user.id } });
|
await db.user.delete({ where: { id: user.id } });
|
||||||
|
|
||||||
|
if (organization.subscription) {
|
||||||
|
await cancelPaddleSubscription({ subscriptionId: organization.subscription.paddleSubscriptionId });
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MembershipRole.USER: {
|
case MembershipRole.USER: {
|
||||||
|
@ -53,7 +53,7 @@ export default function BillingHistory() {
|
|||||||
{payment.amount} {payment.currency}
|
{payment.amount} {payment.currency}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||||
{payment.is_paid === 1 ? "Paid" : "Not paid yet"}
|
{payment.is_paid === 1 ? "Paid" : "Upcoming"}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||||
{typeof payment.receipt_url !== "undefined" ? (
|
{typeof payment.receipt_url !== "undefined" ? (
|
||||||
|
@ -10,7 +10,10 @@ export default function Plans() {
|
|||||||
return (
|
return (
|
||||||
<div className="mt-6 flex flex-row-reverse flex-wrap-reverse gap-x-4">
|
<div className="mt-6 flex flex-row-reverse flex-wrap-reverse gap-x-4">
|
||||||
{pricing.tiers.map((tier) => {
|
{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";
|
const cta = isCurrentTier ? "Current plan" : !!subscription ? `Switch to ${tier.title}` : "Subscribe";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user