Build authenticated and paywall pages with Stripe and Xata

This page summarizes the projects mentioned and recommended in the original post on dev.to

SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
surveyjs.io
featured
InfluxDB - Power Real-Time Data Analytics at Scale
Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
www.influxdata.com
featured
  • protected-and-paid-stripe-xata

    Building Protected and Paywall Pages with Astro and Stripe

  • GitHub Repo

  • pgzx

    Create PostgreSQL extensions using Zig.

  • A Xata account

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • stripe-node

    Node.js library for the Stripe API.

  • // File: src/pages/api/stripe/webhook.ts import Stripe from 'stripe'; import { getXataClient } from '@/xata'; import type { APIContext } from 'astro'; // Process rawBody from the request Object async function getRawBody(request: Request) { let chunks = []; let done = false; const reader = request.body.getReader(); while (!done) { const { value, done: isDone } = await reader.read(); if (value) { chunks.push(value); } done = isDone; } const bodyData = new Uint8Array(chunks.reduce((acc, chunk) => acc + chunk.length, 0)); let offset = 0; for (const chunk of chunks) { bodyData.set(chunk, offset); offset += chunk.length; } return Buffer.from(bodyData); } // Stripe API Reference // https://stripe.com/docs/webhooks#webhook-endpoint-def export async function POST({ request }: APIContext) { try { const STRIPE_SECRET_KEY = import.meta.env.STRIPE_SECRET_KEY; const STRIPE_WEBHOOK_SIG = import.meta.env.STRIPE_WEBHOOK_SIG; if (!STRIPE_SECRET_KEY || !STRIPE_WEBHOOK_SIG) return new Response(null, { status: 500 }); const stripe = new Stripe(STRIPE_SECRET_KEY, { apiVersion: '2023-10-16' }); const rawBody = await getRawBody(request); let event = JSON.parse(rawBody.toString()); const sig = request.headers.get('stripe-signature'); try { event = stripe.webhooks.constructEvent(rawBody, sig, STRIPE_WEBHOOK_SIG); } catch (err) { console.log(err.message); return new Response(`Webhook Error: ${err.message}`, { status: 400 }); } if (event.type === 'checkout.session.completed' || event.type === 'payment_intent.succeeded') { const email = event.data.object?.customer_details?.email; if (email) { const xata = getXataClient(); const existingRecord = await xata.db.user.filter({ email }).getFirst(); if (existingRecord) { await xata.db.user.update(existingRecord.id, { paid: true }); } else { await xata.db.user.create({ email, paid: true }); } return new Response('marked the user as paid', { status: 200 }); } return new Response('no email of the user is found', { status: 200 }); } return new Response(JSON.stringify(event), { status: 404 }); } catch (e) { return new Response(e.message || e.toString(), { status: 500 }); } }

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Building a Managed Postgres Service in Rust

    5 projects | news.ycombinator.com | 8 Apr 2024
  • Jonathan Katz: Thoughts on PostgreSQL in 2024

    3 projects | news.ycombinator.com | 2 Jan 2024
  • GitHub - NAlexPear/pg_branch: Experimental Postgres extension for quickly branching databases through file system snapshots

    1 project | /r/PostgreSQL | 19 Nov 2023
  • We Have to Talk About Flask

    4 projects | news.ycombinator.com | 19 Oct 2023
  • Pg_branch: Pre-alpha Postgres extension brings Neon-like branching

    1 project | /r/hypeurls | 3 Oct 2023