@zuplo/zudoku-plugin-monetization 0.0.17 → 0.0.19
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 +11 -12
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -81,8 +81,13 @@ const useDeploymentName = () => {
|
|
|
81
81
|
|
|
82
82
|
//#endregion
|
|
83
83
|
//#region src/hooks/usePlans.ts
|
|
84
|
-
const usePlans = (
|
|
85
|
-
|
|
84
|
+
const usePlans = () => {
|
|
85
|
+
const zudoku = useZudoku();
|
|
86
|
+
const auth = useAuth();
|
|
87
|
+
return useSuspenseQuery({
|
|
88
|
+
queryKey: [`/v3/zudoku-metering/${useDeploymentName()}/pricing-page`],
|
|
89
|
+
meta: { context: auth.isAuthenticated ? zudoku : void 0 }
|
|
90
|
+
});
|
|
86
91
|
};
|
|
87
92
|
|
|
88
93
|
//#endregion
|
|
@@ -271,7 +276,7 @@ const CheckoutConfirmPage = () => {
|
|
|
271
276
|
const zudoku = useZudoku();
|
|
272
277
|
const deploymentName = useDeploymentName();
|
|
273
278
|
const navigate = useNavigate();
|
|
274
|
-
const { data: plans } = usePlans(
|
|
279
|
+
const { data: plans } = usePlans();
|
|
275
280
|
const selectedPlan = plans?.items?.find((plan) => plan.id === planId);
|
|
276
281
|
if (!planId) throw new Error("Parameter `planId` missing");
|
|
277
282
|
const rateCards = selectedPlan?.phases.at(-1)?.rateCards;
|
|
@@ -478,23 +483,20 @@ const CheckoutPage = () => {
|
|
|
478
483
|
const auth = useAuth();
|
|
479
484
|
const { generateUrl } = useUrlUtils();
|
|
480
485
|
const deploymentName = useDeploymentName();
|
|
481
|
-
if (!auth.profile?.email) throw new Error("No email found for user. Make sure your Authentication Provider exposes the email address.");
|
|
482
486
|
if (!planId) throw new Error(`missing planId in URL`);
|
|
483
|
-
const email = auth.profile?.email;
|
|
484
487
|
const successUrl = new URL(generateUrl("/checkout-confirm"));
|
|
485
488
|
successUrl.searchParams.set("plan", planId);
|
|
486
489
|
const checkoutLink = useQuery({
|
|
487
490
|
queryKey: [
|
|
488
491
|
`/v3/zudoku-metering/${deploymentName}/stripe/checkout`,
|
|
489
492
|
planId,
|
|
490
|
-
|
|
493
|
+
auth.profile?.sub
|
|
491
494
|
],
|
|
492
495
|
meta: {
|
|
493
496
|
context: zudoku,
|
|
494
497
|
request: {
|
|
495
498
|
method: "POST",
|
|
496
499
|
body: JSON.stringify({
|
|
497
|
-
email,
|
|
498
500
|
planId,
|
|
499
501
|
successURL: successUrl.toString(),
|
|
500
502
|
cancelURL: generateUrl("/pricing")
|
|
@@ -654,10 +656,7 @@ const PricingPage = ({ subtitle = "See our pricing options and choose the one th
|
|
|
654
656
|
const zudoku = useZudoku();
|
|
655
657
|
const deploymentName = useDeploymentName();
|
|
656
658
|
const auth = useAuth();
|
|
657
|
-
const { data: pricingTable } =
|
|
658
|
-
queryKey: [`/v3/zudoku-metering/${deploymentName}/pricing-page`],
|
|
659
|
-
meta: { context: auth.isAuthenticated ? zudoku : void 0 }
|
|
660
|
-
});
|
|
659
|
+
const { data: pricingTable } = usePlans();
|
|
661
660
|
const { data: subscriptions = { items: [] } } = useQuery({
|
|
662
661
|
meta: { context: zudoku },
|
|
663
662
|
queryKey: [`/v3/zudoku-metering/${deploymentName}/subscriptions`],
|
|
@@ -1373,7 +1372,7 @@ const ConfirmSwitchAlert = ({ switchTo, onRequestClose }) => {
|
|
|
1373
1372
|
};
|
|
1374
1373
|
const SwitchPlanModal = ({ subscription, children }) => {
|
|
1375
1374
|
const [open, setOpen] = useState(false);
|
|
1376
|
-
const { data: plansData } = usePlans(
|
|
1375
|
+
const { data: plansData } = usePlans();
|
|
1377
1376
|
const [switchTo, setSwitchTo] = useState(null);
|
|
1378
1377
|
const currentPlan = plansData?.items.find((p) => p.id === subscription.plan.id);
|
|
1379
1378
|
const { upgrades, downgrades } = useMemo(() => {
|