rsnext/examples/with-stripe-typescript
leung018 66597be8a7
Add .yarn/install-state.gz to .gitignore (#56637)
### Reason for making this change
https://yarnpkg.com/getting-started/qa#:~:text=yarn%2Finstall%2Dstate.,your%20workspaces%20all%20over%20again.
In the official documentation of `yarn`, it is stated that `.yarn/install-state.gz` is an optimization file that developer shouldn't ever have to commit. However, currently, when running `create-next-app`, `.yarn/install-state.gz` is being commited.

### Remaining work
I apologize for only modifying one template initially to initiate the discussion first.

If this change is agreed upon,  it should be synchronized with other `.gitignore` templates. Would it be possible to follow a similar approach as in https://github.com/vercel/next.js/pull/47241? I would appreciate any assistance in syncing this change.
2023-10-18 16:34:48 +00:00
..
app fix: typo in with-stripe-typescript example (#56274) 2023-10-02 16:47:23 +00:00
config Add Stripe TypeScript Example (#10482) 2020-02-10 22:24:38 -05:00
lib docs(with-stripe-typescript): Update README demo link (#53662) 2023-08-07 08:58:02 -05:00
public example: Improve Stripe examples (#53255) 2023-08-03 23:25:29 +00:00
utils example: Improve Stripe examples (#53255) 2023-08-03 23:25:29 +00:00
.env.local.example add payment description for with-stripe-typescript (#15888) 2020-08-05 02:04:20 -04:00
.gitignore Add .yarn/install-state.gz to .gitignore (#56637) 2023-10-18 16:34:48 +00:00
next-env.d.ts Remove incorrect entries for pnpm debug log (#47241) 2023-03-26 22:26:05 -07:00
next.config.js example: Improve Stripe examples (#53255) 2023-08-03 23:25:29 +00:00
package.json example: Improve Stripe examples (#53255) 2023-08-03 23:25:29 +00:00
README.md docs: Forms and mutations (#54314) 2023-08-25 14:31:11 -05:00
styles.css example: Improve Stripe examples (#53255) 2023-08-03 23:25:29 +00:00
tsconfig.json example: Improve Stripe examples (#53255) 2023-08-03 23:25:29 +00:00

Example using Stripe with TypeScript and react-stripe-js

This is a full-stack TypeScript example using:

Demo

The demo is running in test mode -- use 4242424242424242 as a test card number with any CVC + future expiration date.

Use the 4000002760003184 test card number to trigger a 3D Secure challenge flow.

Read more about testing on Stripe.

Checkout Donations Demo A gif of the Checkout payment page.
Elements Donations Demo A gif of the custom Elements checkout page.

Deploy your own

Once you have access to the environment variables you'll need from the Stripe Dashboard, deploy the example using Vercel:

Deploy to Vercel

Included functionality

How to use

Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:

npx create-next-app --example with-stripe-typescript with-stripe-typescript-app
yarn create next-app --example with-stripe-typescript with-stripe-typescript-app
pnpm create next-app --example with-stripe-typescript with-stripe-typescript-app

Required configuration

Copy the .env.local.example file into a file named .env.local in the root directory of this project:

cp .env.local.example .env.local

You will need a Stripe account (register) to run this sample. Go to the Stripe developer dashboard to find your API keys and replace them in the .env.local file.

NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=<replace-with-your-publishable-key>
STRIPE_SECRET_KEY=<replace-with-your-secret-key>

Now install the dependencies and start the development server.

npm install
npm run dev
# or
yarn
yarn dev

Forward webhooks to your local dev server

First install the CLI and link your Stripe account.

Next, start the webhook forwarding:

stripe listen --forward-to localhost:3000/api/webhooks

The CLI will print a webhook secret key to the console. Set STRIPE_WEBHOOK_SECRET to this value in your .env.local file.

Setting up a live webhook endpoint

After deploying, copy the deployment URL with the webhook path (https://your-url.vercel.app/api/webhooks) and create a live webhook endpoint in your Stripe dashboard.

Once created, you can click to reveal your webhook's signing secret. Copy the webhook secret (whsec_***) and add it as a new environment variable in your Vercel Dashboard:

  • Select your newly created project.
  • Navigate to the Settings tab.
  • In the general settings scroll to the "Environment Variables" section.

After adding an environment variable you will need to rebuild your project for it to become within your code. Within your project Dashboard, navigate to the "Deployments" tab, select the most recent deployment, click the overflow menu button (next to the "Visit" button) and select "Redeploy".

Deploy on Vercel

You can deploy this app to the cloud with Vercel (Documentation).

Deploy Your Local Project

To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and import to Vercel.

Important: When you import your project on Vercel, make sure to click on Environment Variables and set them to match your .env.local file.

Deploy from Our Template

Alternatively, you can deploy using our template by clicking on the Deploy button below.

Deploy to Vercel

Authors