This is a Ruby on Rails application that implements Stripe subscriptions. It's containerized using Docker for easy setup and development.
- Docker and Docker Compose installed on your system
- Build the Docker image:
docker-compose build- Start the Rails server:
docker-compose up- Create the database (first time only):
docker-compose run web rails db:create- Run migrations:
docker-compose run web rails db:migrate- Access the Rails console:
docker-compose run web rails console- Rebuild the image (if changes are made to the Dockerfile or Gemfile):
docker-compose build- Create a .env file in the root directory and add the following keys with their Stripe values:
1. STRIPE_PUBLISHABLE_KEY = 'pk_test_XXX'
2. STRIPE_SECRET_KEY = 'sk_test_XXX'
3. STRIPE_WEBHOOK_SECRET = 'whsec_XXX'To run the unit tests, use the following command:
rspec
ngrok allows you to expose your local development server to the internet, which is useful for testing Stripe webhooks.
- MacOS:
brew install ngrok- Linux:
Use your distribution's package manager (e.g.,
aptfor Ubuntu) - Windows:
choco install ngrok-
Create an ngrok account and get your authtoken from the ngrok dashboard.
-
Connect your ngrok agent to your account:
ngrok config add-authtoken <AUTHTOKEN>- In a new terminal window, start ngrok:
ngrok http 3000- Copy the ngrok URL (e.g.,
https://6a55-2a02-908-1871-6ee0-1d8c-a83b-f83f-8ba9.ngrok-free.app).
-
Log in to your Stripe Dashboard and go to Developers > Webhooks.
-
Click "Add endpoint" and enter your ngrok URL followed by the webhook route (e.g.,
https://6a55-2a02-908-1871-6ee0-1d8c-a83b-f83f-8ba9.ngrok-free.app/webhooks/stripe).
Now you can test Stripe webhooks with your local development server.
ℹ️ Info: One test case does not pass the github CI/CD due to the absence of the env file.