- Project Overview
- Demo Video
- Prerequisites
- Setup
- Development
- Testing with Postman
This project implements a two-way integration between a local customer catalog and Stripe, with near real-time synchronization using Kafka as a message queue.
- Docker and Docker Compose
- Python 3.11 or higher
- Ngrok (for exposing local API to Stripe webhook)
- Stripe account (for API key and webhook secret)
-
Clone the repository:
git clone https://github.com/harsh-kumar-patwa/SyncStream.git cd SyncStream -
Create a
.envfile in the project root and add your Stripe credentials:STRIPE_API_KEY=your_stripe_api_key_here STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret_here -
Build and start the Docker containers:
docker-compose up --buildThis will start Zookeeper, Kafka, and the main application.
-
Once the application is running, use Ngrok to expose your local API:
ngrok http 5000Note the HTTPS URL provided by Ngrok, you'll need this for setting up the Stripe webhook.
-
Set up a Stripe webhook:
- Go to the Stripe Dashboard > Developers > Webhooks
- Click "Add endpoint"
- Use the Ngrok HTTPS URL + "/webhook/stripe" as the endpoint URL
- Select the events you want to listen to (e.g., customer.created, customer.updated, customer.deleted)
-
The application should now be running and ready to handle two-way sync between your local customer catalog and Stripe.
To set up the development environment:
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate` -
Install the required packages:
pip install -r requirements.txt -
You can now run the application locally for development:
python main.py
When you make changes to your code and want to test them, follow these steps:
-
Stop the running containers:
docker-compose down -
Rebuild the containers:
docker-compose build -
Start the containers again:
docker-compose up
This process ensures that your changes are included in the Docker image and that you're testing with a fresh environment each time.
To test the API endpoints, you can use Postman. Here's how to set it up and test the main functionalities:
-
Base URL:
- If using Ngrok: Use the Ngrok URL (e.g.,
https://your-ngrok-url.ngrok.io) and add it to the environment variable and name it base_url
- If using Ngrok: Use the Ngrok URL (e.g.,
-
Endpoints to Test:
a. Create a Customer
- Method: POST
- URL:
{{base_url}}/customers - Body (raw JSON):
{ "name": "John Doe", "email": "john.doe@example.com" }
b. Get All Customers
- Method: GET
- URL:
{{base_url}}/customers
c. Get a Specific Customer
- Method: GET
- URL:
{{base_url}}/customers/{customer_id}
d. Update a Customer
- Method: PUT
- URL:
{{base_url}}/customers/{customer_id} - Body (raw JSON):
{ "name": "John Updated", "email": "john.updated@example.com" }
e. Delete a Customer
- Method: DELETE
- URL:
{{base_url}}/customers/{customer_id}
-
Testing Workflow:
- Create a new customer and note the returned ID
- Retrieve all customers to verify the new addition
- Get the specific customer using the ID
- Update the customer's information
- Verify the update by getting the customer again
- Delete the customer
- Confirm deletion by trying to get the customer (it would return customer doesn't exist error)
-
Verifying Stripe Sync:
- After each operation, check your Stripe dashboard to ensure the changes are reflected there as well
- You will have need to refresh the Stripe dashboard to see the updates
Remember to replace {customer_id} with actual IDs returned from your create or get all customers requests.