Giter VIP home page Giter VIP logo

graasp-plugin-subscriptions's Introduction

graasp-plugin-subscriptions

This plugin enables users to subscribe to different plans according to their needs.

It uses Stripe to handle cards, payments and subscriptions. Only the necessary data should be sent to Stripe (ie. emails), and we store most of the data in our databases (ie. storage available).

This plugin allows the user to perform the following action:

  • Be subscribed to the default plan automatically
  • Add a new card to their account
  • Subscribe to a different plan
  • Get all plans or their current plan
  • Change the default card

List of test cards Stripe accepts, these cards can be added to the account via the frontend.

Stripe

Currently, this plugins needs to have Stripe configured. The following resources need to be created :

  • Products: products represents the plan (free, standard, premium)
  • Metadata: metadata allow to rank and filter (group, individual) the products
  • Prices: prices are linked to a product, every products must have the same currencies

The minimal information for a product are the following (more information could be moved to Graasp database):

  {
    "id": "prod_xxx",
    "name": "Free plan",
    "description": "2GB of storage",
    "metadata": [
      { "type": "INDIVIDUAL_PLAN" },
      { "level": 0 }
    ],
  }

Currently, the products have monthly prices. All products should have the same currencies as a customer can only pay in one currency. The price of a product should contain the following informations:

  {
    "id": "price_xxx",
    "product": "prod_xxx",
    "price": 3000, // price in cents (30.00 CHF)
    "currency": "CHF",
    "interval": "day | week | month | year",
  }

Currently, the subscriptions are automatically charged. When a customer changes their plan, the backend changes the price attached to the subscription in Stripe. When a subscription is updated the price is calculated using a proration from the time of change. The subscriptions contains the following data:

{
  "collection_method": "charge_automatically | send_invoice",
  "customer": "cus_xxx",
  "default_payment_method": "pm_xxx",
  "items": [
    { "id": "sub_xxx", "price": "price_xxx" }
  ]
}

Plans

Plans are stored on Graasp database, they allow the backend to easily access the plan data. For example, the upload limiter can easily access the storage value to ensure a user isn't breaking their quota. Currently the plan table contains the following columns:

Column Name Type Description
id UUIDv4 Unique identifier of the plan in the Graasp database
plan_id string Identifier in the Stripe database, can be set to anything for a custom plan (eg. unlimited)
storage bigint Allowed storage for this plan in GB, caller needs to do the conversion if necessary

Subscriptions

Subscriptions fill the following roles:

  • Link a Graasp user to the default plan when created
  • Link a Graasp user with their current plan
  • Link a Graasp user with their corresponding Stripe customer
  • Link a Graasp user with their corresponding Stripe subscription

Currently the member_plan table contains the following columns:

Column Name Type Description
id UUIDv4 Unique identifier of the subscription in the Graasp database
member_id UUIDv4 Id of the member
plan_id UUIDv4 Id of the current plan for the member
customer_id string / NULL Id of the customer in Stripe, only set if the member has added a card
subscription_id string / NULL Id of the subscription in Stripe, only set if the member has changed to a paid plan

graasp-plugin-subscriptions's People

Contributors

abdallah75 avatar julien-torrent avatar pyphilia avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graasp-plugin-subscriptions's Issues

Better handling when user don't have stripe account

Currently most of the operations with stripe are using the subscription Id to get the product.

Refactor the code to use the subscription stored in Graasp database
(getGraaspSubscription -> getGraaspPlan -> getStripeProduct)

Or move most of the plan data in the Graasp database, allowing the backend to directly fetch the data of the plan
(GetGraaspSubscription -> getGraaspPlan -> getStripePrices)

Improvments

More informations about the plans can be stored in our database.
Ex:
description, type (individual, group), level (used to rank plans)

Reduce the number of calls to stripe, if the member doesn't have a stripe customer don't make calls

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.