@zuplo/zudoku-plugin-monetization 0.0.33 → 0.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +43 -23
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1094,6 +1094,17 @@ const useSubscriptions = (environmentName) => {
|
|
|
1094
1094
|
});
|
|
1095
1095
|
};
|
|
1096
1096
|
//#endregion
|
|
1097
|
+
//#region src/utils/billables.ts
|
|
1098
|
+
const getActivePhase = (sub) => {
|
|
1099
|
+
const now = Date.now();
|
|
1100
|
+
return sub.phases.filter((p) => new Date(p.activeFrom).getTime() <= now && (!p.activeTo || new Date(p.activeTo).getTime() >= now)).sort((a, b) => new Date(b.activeFrom).getTime() - new Date(a.activeFrom).getTime())[0];
|
|
1101
|
+
};
|
|
1102
|
+
const activePhaseHasBillables = (sub) => getActivePhase(sub)?.items.some((i) => i.price != null) ?? false;
|
|
1103
|
+
const hasFutureBillables = (sub) => {
|
|
1104
|
+
const now = Date.now();
|
|
1105
|
+
return sub.phases.filter((p) => new Date(p.activeFrom).getTime() > now).some((p) => p.items.some((i) => i.price != null));
|
|
1106
|
+
};
|
|
1107
|
+
//#endregion
|
|
1097
1108
|
//#region src/pages/subscriptions/ConfirmDeleteKeyAlert.tsx
|
|
1098
1109
|
const ConfirmDeleteKeyAlert = ({ children, onDelete }) => {
|
|
1099
1110
|
return /* @__PURE__ */ jsxs(AlertDialog, { children: [/* @__PURE__ */ jsx(AlertDialogTrigger, {
|
|
@@ -1386,19 +1397,22 @@ const ApiKeysList = ({ isPendingFirstPayment, apiKeys, deploymentName, consumerI
|
|
|
1386
1397
|
};
|
|
1387
1398
|
//#endregion
|
|
1388
1399
|
//#region src/pages/subscriptions/CancelSubscriptionDialog.tsx
|
|
1389
|
-
const CancelSubscriptionDialog = ({ open, onOpenChange, planName, subscriptionId, billingPeriodEnd }) => {
|
|
1400
|
+
const CancelSubscriptionDialog = ({ open, onOpenChange, planName, subscriptionId, billingPeriodEnd, hasCurrentBillables, hasFutureBillables }) => {
|
|
1390
1401
|
const [confirmationText, setConfirmationText] = useState("");
|
|
1391
1402
|
const isConfirmed = planName.startsWith(confirmationText);
|
|
1392
1403
|
const deploymentName = useDeploymentName();
|
|
1393
1404
|
const context = useZudoku();
|
|
1394
1405
|
const queryClient = useQueryClient();
|
|
1406
|
+
const cancelTiming = hasCurrentBillables ? "next_billing_cycle" : "immediate";
|
|
1407
|
+
const isImmediateCancel = !hasCurrentBillables;
|
|
1408
|
+
const isTrialCancel = isImmediateCancel && hasFutureBillables;
|
|
1395
1409
|
const cancelSubscriptionMutation = useMutation({
|
|
1396
1410
|
mutationKey: [`/v3/zudoku-metering/${deploymentName}/subscriptions/${subscriptionId}/cancel`],
|
|
1397
1411
|
meta: {
|
|
1398
1412
|
context,
|
|
1399
1413
|
request: {
|
|
1400
1414
|
method: "POST",
|
|
1401
|
-
body: JSON.stringify({ timing:
|
|
1415
|
+
body: JSON.stringify({ timing: cancelTiming })
|
|
1402
1416
|
}
|
|
1403
1417
|
},
|
|
1404
1418
|
onSuccess: async () => {
|
|
@@ -1418,28 +1432,32 @@ const CancelSubscriptionDialog = ({ open, onOpenChange, planName, subscriptionId
|
|
|
1418
1432
|
children: [
|
|
1419
1433
|
/* @__PURE__ */ jsxs(Alert, {
|
|
1420
1434
|
variant: "warning",
|
|
1421
|
-
children: [
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
]
|
|
1435
|
+
children: [/* @__PURE__ */ jsx(CalendarIcon, { className: "size-4" }), isTrialCancel ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(AlertTitle, { children: [
|
|
1436
|
+
"Cancel your trial of ",
|
|
1437
|
+
planName,
|
|
1438
|
+
"?"
|
|
1439
|
+
] }), /* @__PURE__ */ jsxs(AlertDescription, { children: [
|
|
1440
|
+
"Your subscription will end now and you won't be charged when the trial would have converted to ",
|
|
1441
|
+
planName,
|
|
1442
|
+
"."
|
|
1443
|
+
] })] }) : isImmediateCancel ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(AlertTitle, { children: [
|
|
1444
|
+
"Cancel your ",
|
|
1445
|
+
planName,
|
|
1446
|
+
" subscription?"
|
|
1447
|
+
] }), /* @__PURE__ */ jsx(AlertDescription, { children: "Your subscription will end immediately. You'll lose access to its entitlements right away." })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(AlertTitle, { children: "Your plan will be canceled at the end of your billing cycle." }), /* @__PURE__ */ jsxs(AlertDescription, { children: [
|
|
1448
|
+
"You'll retain access until ",
|
|
1449
|
+
formatDate$2(billingPeriodEnd),
|
|
1450
|
+
". After your billing period ends, this plan will not renew and you would need to subscribe again to continue."
|
|
1451
|
+
] })] })]
|
|
1430
1452
|
}),
|
|
1431
1453
|
/* @__PURE__ */ jsxs(Alert, {
|
|
1432
1454
|
variant: "info",
|
|
1433
|
-
children: [
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
formatDate$2(billingPeriodEnd),
|
|
1440
|
-
" to remove this cancellation from Manage subscription."
|
|
1441
|
-
] })
|
|
1442
|
-
]
|
|
1455
|
+
children: [/* @__PURE__ */ jsx(InfoIcon, { className: "size-4" }), isImmediateCancel ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(AlertTitle, { children: "You can subscribe again at any time" }), /* @__PURE__ */ jsx(AlertDescription, { children: "After canceling, you can return to the pricing page and start a new subscription whenever you're ready." })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(AlertTitle, { children: "You can still resume before then" }), /* @__PURE__ */ jsxs(AlertDescription, { children: [
|
|
1456
|
+
"If you change your mind you have until",
|
|
1457
|
+
" ",
|
|
1458
|
+
formatDate$2(billingPeriodEnd),
|
|
1459
|
+
" to remove this cancellation from Manage subscription."
|
|
1460
|
+
] })] })]
|
|
1443
1461
|
}),
|
|
1444
1462
|
/* @__PURE__ */ jsxs("div", {
|
|
1445
1463
|
className: "space-y-2",
|
|
@@ -2074,7 +2092,9 @@ const ManageSubscription = ({ subscription, planName }) => {
|
|
|
2074
2092
|
onOpenChange: setCancelDialogOpen,
|
|
2075
2093
|
planName,
|
|
2076
2094
|
subscriptionId: subscription.id,
|
|
2077
|
-
billingPeriodEnd
|
|
2095
|
+
billingPeriodEnd,
|
|
2096
|
+
hasCurrentBillables: activePhaseHasBillables(subscription),
|
|
2097
|
+
hasFutureBillables: hasFutureBillables(subscription)
|
|
2078
2098
|
}),
|
|
2079
2099
|
/* @__PURE__ */ jsx(RestoreSubscriptionDialog, {
|
|
2080
2100
|
open: restoreDialogOpen,
|
|
@@ -2579,7 +2599,7 @@ const ActiveSubscription = ({ subscription, deploymentName }) => {
|
|
|
2579
2599
|
meta: { context: zudoku }
|
|
2580
2600
|
});
|
|
2581
2601
|
const isPendingFirstPayment = usageQuery.data.paymentStatus.isFirstPayment === true && usageQuery.data.paymentStatus.status !== "paid" && usageQuery.data.paymentStatus.status !== "not_required";
|
|
2582
|
-
const activePhase = subscription
|
|
2602
|
+
const activePhase = getActivePhase(subscription);
|
|
2583
2603
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2584
2604
|
planSwitched && /* @__PURE__ */ jsxs(DismissibleAlert, {
|
|
2585
2605
|
variant: "info",
|