/plan-picker-backend

A Backend Implementation for a Streaming Service Subscription Picker PoC App using the Stripe API

Primary LanguageJavaScript


Video Streaming Subscription Service


🚀 Getting Started

  1. Clone the repository from https://github.com/ajaytitus1386/richpanel-task-backend using your preferred method.
  2. Next, navigate to the root of the project and install the dependencies:
npm install
  1. Then, run the server on port 4000:
npm start

Or better yet just use the deployed API at https://richpanel-task-backend.herokuapp.com/

Also check out the frontend web app at https://github.com/ajaytitus1386/richpanel-task-frontend

🔍 Salient Features

  • Node.JS with Express and MongoDB for database management
  • Use a combination of a MongoDB Atlas Cluster and a Stripe API Account to manage subscriptions
  • Handles authentication using JSON Web Token

✈️ Routes

🔑 /user

/signup

  • Method: POST
  • Description: Register a new user in the database, encrypts the password before saving the document and then signs a JSON Web Token
  • Body Data: Username, email and password
  • Response: Returns a valid JWT

/login

  • Method: POST
  • Description: Locates a stored user in the database by its email and matches it by the hashed password and signs a JWT
  • Body Data: Email and password
  • Response: Returns a valid JWT

/me

  • Method: GET
  • Description: Verifies a recieved JWT
  • Headers Token: token : JWT
  • Response: Returns a user model

📖 /plans

/fetch

  • Method: GET
  • Description: Fetches all plans in the database
  • Response: Returns a list of Plans

/fetch/:id

  • Method: GET
  • Description: Fetches a specific plan by its ID in the database
  • Response: Returns one Plan

💵 /subscription

/create

  • Method: POST
  • Description: Adds a new subscription for a given user to a given plan
  • Body Data: See subscription model

/fetch

  • Method: GET
  • Description: Adds a new subscription for a given user to a given plan
  • Query Param: User ID in request query
  • Response: Returns a single subscription

/cancel/:id

  • Method: PATCH
  • Description: Updates the isActive field of specified subscription to FALSE

💳 /stripe

/create

  • Method: POST
  • Description: Creates a new customer and subscription payment
  • Body Data: Email, Payment method id, Price ID (of product via STRIPE API)
  • Response: Returns a subscription ID and a Client Secret to complete the subscription payment on frontend

/cancel

  • Method: POST
  • Description: Cancels an Active subscription via the Stripe API
  • Body Data: Subscription ID