### Install Dependencies and Run Dev Server (npm) Source: https://github.com/get-convex/convex-stripe-demo/blob/main/README.md Installs project dependencies using npm and starts the development server. This is a standard setup step for Node.js projects. ```bash npm install npm run dev ``` -------------------------------- ### Configure Stripe CLI Webhook Forwarding (bash) Source: https://github.com/get-convex/convex-stripe-demo/blob/main/README.md Configures the Stripe CLI to forward webhook events to your Convex HTTP Actions URL. This allows Stripe to send payment status updates to your backend. ```bash stripe listen --forward-to /stripe ``` -------------------------------- ### Set Stripe API Key Environment Variable (bash) Source: https://github.com/get-convex/convex-stripe-demo/blob/main/README.md Sets your Stripe secret API key as an environment variable for your Convex project. This key is used to authenticate requests made to the Stripe API. ```bash npx convex env set STRIPE_KEY ``` -------------------------------- ### Set Stripe Webhook Secret Environment Variable (bash) Source: https://github.com/get-convex/convex-stripe-demo/blob/main/README.md Sets the Stripe webhook signing secret as an environment variable for your Convex project. This secret is used to verify the authenticity of incoming webhooks from Stripe. ```bash npx convex env set STRIPE_WEBHOOKS_SECRET ``` -------------------------------- ### Define a Convex Mutation Function in TypeScript Source: https://github.com/get-convex/convex-stripe-demo/blob/main/convex/README.md This snippet illustrates how to define a mutation function in Convex using TypeScript. It includes argument validation and demonstrates inserting data into the database using `ctx.db.insert()` and retrieving it with `ctx.db.get()`. ```typescript import { mutation } from "./_generated/server"; import { v } from "convex/values"; export const myMutationFunction = mutation({ // Validators for arguments. args: { first: v.string(), second: v.string(), }, // Function implementation. hander: async (ctx, args) => { // Insert or modify documents in the database here. // Mutations can also read from the database like queries. // See https://docs.convex.dev/database/writing-data. const message = { body: args.first, author: args.second }; const id = await ctx.db.insert("messages", message); // Optionally, return a value from your mutation. return await ctx.db.get(id); }, }); ``` -------------------------------- ### Define a Convex Query Function in TypeScript Source: https://github.com/get-convex/convex-stripe-demo/blob/main/convex/README.md This snippet demonstrates how to define a query function in Convex using TypeScript. It includes argument validation using `v.number()` and `v.string()`, and shows how to read data from the database using `ctx.db.query()` and `collect()`. ```typescript import { query } from "./_generated/server"; import { v } from "convex/values"; export const myQueryFunction = query({ // Validators for arguments. args: { first: v.number(), second: v.string(), }, // Function implementation. hander: async (ctx, args) => { // Read the database as many times as you need here. // See https://docs.convex.dev/database/reading-data. const documents = await ctx.db.query("tablename").collect(); // Arguments passed from the client are properties of the args object. console.log(args.first, args.second); // Write arbitrary JavaScript here: filter, aggregate, build derived data, // remove non-public properties, or create new objects. return documents; }, }); ``` -------------------------------- ### Use a Convex Mutation Function in React Source: https://github.com/get-convex/convex-stripe-demo/blob/main/convex/README.md This snippet displays how to invoke a Convex mutation function from a React component using the `useMutation` hook. It shows how to trigger the mutation with arguments and handle its potential return value. ```typescript const mutation = useMutation(api.functions.myMutationFunction); function handleButtonPress() { // fire and forget, the most common way to use mutations mutation({ first: "Hello!", second: "me" }); // OR // use the result once the mutation has completed mutation({ first: "Hello!", second: "me" }).then((result) => console.log(result) ); } ``` -------------------------------- ### Use a Convex Query Function in React Source: https://github.com/get-convex/convex-stripe-demo/blob/main/convex/README.md This snippet shows how to call a Convex query function from a React component using the `useQuery` hook. It passes the necessary arguments to the query. ```typescript const data = useQuery(api.functions.myQueryFunction, { first: 10, second: "hello", }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.