A simple and flexible wrapper for integrating Stripe's API into your Node.js application, providing functionalities like payment intent creation, subscription management, and more. This package is designed to help developers seamlessly interact with Stripe’s payment and subscription services using Node.js.
The stripe_api_integration_wrapper
is a Node.js-based wrapper around the Stripe API that facilitates easy integration for payment processing and subscription management. This project simplifies working with Stripe by encapsulating the API logic in reusable functions and making it easier to handle payments and subscriptions in a secure and scalable way.
- Payment Intent Creation: Allows you to create a payment intent with customizable amounts and currencies.
- Subscription Management: Handles the creation of subscriptions based on a customer ID and price ID.
- Error Handling: Includes basic error handling to ensure smooth integration.
- dotenv Support: Configuration of environment variables (e.g., Stripe API keys) using
dotenv
. - Express.js Integration: Works seamlessly with Express.js for easy API endpoint creation.
- Node.js: >= v14.x.x
- npm (Node Package Manager)
- Stripe account: You will need to create a Stripe account to use the API keys.
Follow these steps to install and set up the project:
-
Clone the repository:
git clone https://github.com/pawvan/stripe_api_integration_wrapper.git cd stripe_api_integration_wrapper
-
Install dependencies:
npm install
-
Create a
.env
file at the root of the project and add your Stripe API keys:STRIPE_SECRET_KEY=your-stripe-secret-key STRIPE_PUBLIC_KEY=your-stripe-public-key PORT=3000
You need to configure the following environment variables:
STRIPE_SECRET_KEY
: Your Stripe Secret Key (can be found in your Stripe dashboard).STRIPE_PUBLIC_KEY
: Your Stripe Public Key (can also be found in your Stripe dashboard).PORT
: Port on which the application will run (default is 3000).
This project is structured to work with Express.js. You can use the provided routes for creating payment intents and subscriptions.
-
Start the server:
npm start
-
API Endpoints:
-
Create Payment Intent:
- Endpoint:
POST /api/payments/create
- Body:
{ "amount": 1000, "currency": "usd" }
- Response: Returns the
clientSecret
of the created payment intent.
- Endpoint:
-
Create Subscription:
- Endpoint:
POST /api/subscription/create
- Body:
{ "customerId": "customer_id", "priceId": "price_id" }
- Response: Returns the subscription object.
- Endpoint:
-
Creates a payment intent with a specified amount and currency.
{
"amount": 1000,
"currency": "usd"
}
{
"clientSecret": "pi_1Ie2dHFpdhJkOgw77Wx..."
}
Creates a subscription for a customer based on a specified customer ID and price ID.
{
"customerId": "cus_JG9U9m4lr78fay",
"priceId": "price_1Ie2dHFpdhJkOgw77Wx..."
}
{
"id": "sub_1Ie2eHFpdhJkOgw77Wx...",
"customer": "cus_JG9U9m4lr78fay",
"items": [
{
"price": {
"id": "price_1Ie2dHFpdhJkOgw77Wx..."
}
}
]
}
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or feedback about this project, feel free to reach out: