This is an API developed as a recruitment exercise. It serves as an internal API that recieves subscription requestes and processes them through an external payment gateway. Once the payment is succesfull, the subscrption & customer can be created. The API renders messages that can be used to build a frontend of the subsription system.
ruby 2.5.3p
Rails 5.2.2
The default rails database - Sqlite, to avoid any complications while cloning.
Additional gems used:
-
gem 'dotenv-rails' to encrypt the API token
-
gem 'attr_encrypted' to encrypt the customers tokens
-
gems: 'rspec-rails', 'factory_bot_rails','shoulda-matchers', 'faker', 'database_cleaner' for testing.
-
Clone respected git repository
-
Install all dependencies
-
bundle install
-
Create db and migrate schema
-
Run db seeds for the plans to be present in the db
-
set your API key (token) in the .env file (please see .env-example).
-
run the server
-
send JSON request
- example request with curl:
curl -X POST
-H "Content-Type: application/json"
-d '{"subscription_request": {"name": "test", "address": "TestAdress", "zipcode": "10045", "card_num": "4242424242424242", "expiration": "2021-03-03 00:58:14 +0100", "cvv": "123", "billing_zip": "10045", "plan_id": "4"}}'
localhost:3000/subscription_requests
- You will get a response with JSON informing whether the request was succesful & the subscripion was created or an error explaining what went wrong on the way.
For better security, the customers tokens recieved from the payment gateway are encrypted before saving in db. Credit Card numbers are not stored and they are filtered from showing in the logs as well.
-
Requests specs
-
Moving the creation of a subscription to a Service Object
-
Allowing multiple subscriptions for one user
-
Add transaction to avoid charging while not making subscription