From c5108acaaef5ce6a6de81ec455e85e60f03485dc Mon Sep 17 00:00:00 2001 From: Andrei Liviu Georgescu <146103342+andreilgeorgescu@users.noreply.github.com> Date: Tue, 29 Oct 2024 12:51:03 +0000 Subject: [PATCH] Update cloudflare page functions --- functions/api/purchase/[id].ts | 4 ++-- src/components/MembershipPricingHelper.jsx | 28 ++++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/functions/api/purchase/[id].ts b/functions/api/purchase/[id].ts index fa0f52d..0eba0ca 100644 --- a/functions/api/purchase/[id].ts +++ b/functions/api/purchase/[id].ts @@ -145,12 +145,12 @@ export async function onRequestGet(context: EventContext): PagesFunction { ); return new Response( - { + JSON.stringify({ heading, name, price, updatedLectureSections, - }, + }), { status: 200, headers: { diff --git a/src/components/MembershipPricingHelper.jsx b/src/components/MembershipPricingHelper.jsx index a74ab36..2c76ae6 100644 --- a/src/components/MembershipPricingHelper.jsx +++ b/src/components/MembershipPricingHelper.jsx @@ -47,18 +47,20 @@ export default function Example(props) { // setLoading(true); // setError(null); try { - const options = { - method: "GET", - headers: { - accept: "application/json", - apiKey: import.meta.env.PUBLIC_REACT_APP_API_KEY || "", - }, - }; + // const options = { + // method: "GET", + // headers: { + // accept: "application/json", + // apiKey: import.meta.env.PUBLIC_REACT_APP_API_KEY || "", + // }, + // }; - const response = await fetch( - `https://developers.teachable.com/v1/pricing_plans/${args.pricingPlanId}`, - options, - ); + // const response = await fetch( + // `https://developers.teachable.com/v1/pricing_plans/${args.pricingPlanId}`, + // options, + // ); + + const response = await fetch(`/api/purchase/${args.pricingPlanId}`); if (!response.ok) { throw new Error(`Network response was not ok: ${response.statusText}`); @@ -66,10 +68,10 @@ export default function Example(props) { const course = await response.json(); - if (course.pricing_plan.price <= 0) { + if (course.price <= 0) { args.func("Free"); } else { - args.func(`$${(course.pricing_plan.price / 100).toFixed(2)}`); + args.func(`$${(course.price / 100).toFixed(2)}`); } } catch (error) { // setError(