This directory contains the main Node implementation of the payments server.
You’ll need the following:
- Node.js >= 8.x.
- Modern browser that supports ES6 (Chrome to see the Payment Request, and Safari to see Apple Pay).
- Stripe account to accept payments (sign up for free).
In your Stripe Dashboard, you can enable the payment methods you’d like to test with one click.
Some payment methods require receiving a real-time webhook notification to complete a charge. This demo is bundled with ngrok, which allows us to securely receive webhooks and serve the app locally via HTTPS, which is also required to complete transactions in the browser with Elements or the Payment Request API.
Copy the environment variables file from the root of the repository:
cp .env.example .env
Update .env
with your own Stripe API keys and any other configuration details. These environment variables are loaded and used in server/node/config.js
, where you can review and edit other options such as the app currency and your Stripe account country.
Install dependencies using npm:
npm install
This demo uses the Stripe API as a datastore for products and orders, but you can always choose to use your own datastore instead. When starting the app for the first time, the initial loading can take a couple of seconds as it will automatically set up the products within Stripe.
Run the app:
npm run start
Two public ngrok URLs will be provided when the app starts. The first URL should be used to setup webhooks in your Stripe Dashboard. For example:
https://<example>.ngrok.io/webhook
The second URL will serve our app via HTTPS. For example:
https://<example>.ngrok.io
Use this second URL in your browser to start the demo.
Don’t want to use ngrok? As long as you serve the app over HTTPS and that Stripe can reach the webhook endpoint via a public URL, all the payment flows will work.
Want to test a hosted version of this app with your own Stripe account? You can deploy an instance of this app on Heroku and set up your own API keys:
- Code: Romain Huet and Thorsten Schaeff