cancel subscription on account deletion

This commit is contained in:
m5r 2021-10-01 20:07:00 +02:00
parent c5f135fdcc
commit 188c028667
6 changed files with 33 additions and 3 deletions

View 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;

View File

@ -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);

View File

@ -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);
},

View File

@ -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<Payload>("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<Payload>("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: {

View File

@ -53,7 +53,7 @@ export default function BillingHistory() {
{payment.amount} {payment.currency}
</td>
<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 className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
{typeof payment.receipt_url !== "undefined" ? (

View File

@ -10,7 +10,10 @@ export default function Plans() {
return (
<div className="mt-6 flex flex-row-reverse flex-wrap-reverse gap-x-4">
{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 (