A Simple Stripe integration using Node.js Express.
This example includes a deployment workflow that runs a test on each commit to check that the Stripe API is associated with a Stripe Sandbox environment named "dev-sandbox".
Read more about Stripe sandboxes in this Stripe.dev blog post.
Before running this application, make sure you have the following:
- Node.js installed on your machine
- Stripe API key
The following steps show you how to find a sandbox key:
-
Visit the Stripe Sandbox Dashboard to view a complete list of all the sandboxes in your account, or choose the account dropdown from the top left corner of the dashboard.
-
Choose the sandbox you wish to gain programmatic access to, and then select Manage API keys from the sandbox welcome page.
-
From the API Keys dashboard, you can reveal, revoke, and create API keys. Check the documentation to learn how to manage API keys. To see the API key for your Sandbox environment, choose Reveal test Key.
-
Clone the repository:
git clone https://github.com/benjasl-stripe/stripe-sandbox-test.git
-
Install the dependencies:
cd stripe-sandbox-test npm install
-
Set up environment variables:
-
Create a
.env
file in the root directory of the project. -
Add the following variables to the
.env
file:PORT=3000 STRIPE_API_KEY=your-stripe-api-key
-
-
Start the server:
npm start
Send a POST request to /create-payment-intent
with the following JSON payload:
curl -X POST http://localhost:3000/create-payment-intent \
-H "Content-Type: application/json" \
-d '{"amount": 1000, "currency": "usd"}'
When using GitHub Actions for CI/CD, manage sensitive data securely using GitHub Secrets:
- Go to your GitHub repository.
- Choose Settings from the toolbar.
- On the left sidebar, navigate to Secrets and variables and choose Actions, then select New repository secret.
- Add your secrets one at a time.
GitHub Actions allows you to automate your workflows and CI/CD processes. This workflow automates the process of testing the application whenever changes are pushed to the main branch. It checks out the latest code, sets up the necessary environment, installs any required dependencies, and runs tests that interact with Stripe to verify that the code is executing in the correct sandbox. This helps ensure the integrity and functionality of the application in a continuous and efficient manner, while maintaining secure practices in handling sensitive credentials like API keys: