Skip to content

Commit

Permalink
Update cloudflare page functions
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilgeorgescu authored Oct 29, 2024
1 parent 06aa1f0 commit c5108ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions functions/api/purchase/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ export async function onRequestGet(context: EventContext): PagesFunction<Env> {
);

return new Response(
{
JSON.stringify({
heading,
name,
price,
updatedLectureSections,
},
}),
{
status: 200,
headers: {
Expand Down
28 changes: 15 additions & 13 deletions src/components/MembershipPricingHelper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,31 @@ 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}`);
}

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(
Expand Down

0 comments on commit c5108ac

Please sign in to comment.