A company can set up a monthly subscriptions. A user purchasing a subscription policy can enroll into all the products of the company.
If the price of the subscription changes then the user shall be notified.
A User will have an option to Un-subscribe at any time.
Table Name: subscriptions
| Column_name | type | Description |
|---|---|---|
| id | integer | primary key |
| company_id | integer | Company Id |
| price | decimal | monthly subscription price |
| duration | integer | duration of the subscription in days (defaults to 30 days) |
| created_at | date_time | date on which the subscription was created |
| updated_at | date_time | date on which the subscription was last modified. |
Table Name: user_subscriptions
| Column_name | type | Description |
|---|---|---|
| id | integer | primary key |
| subscription_id | integer | primary key of the subscription |
| user_id | integer | primary key of the users table |
| status | integer | Status of the subscription (active/cancelled) |
| start_date | date_time | Date from which the user purchased the subscription |
| end_date | date_time | Date when the subscription ends |
| next_renewal_date | date_time | Date when the subscription has to be renewed (end_date + 1) |
| created_at | date_time | date on which the subscription was created |
| updated_at | date_time | date on which this information was last modified. |
Table Name: orders (This table already exists. Just add following columns to orders table)
| Column_name | type | Description |
|---|---|---|
| sub_total | float | all item total |
| total | float | total value of the order |
| discount | integer | %discount availed on the order |
| shipping | float | shipping cost |
| tax | integer | % of tax applied on order |
Table Name: purchases (This table already exists. Just add following columns to purchases table)
| Column_name | type | Description |
|---|---|---|
| discount | integer | %discount availed on product |
| actual_price | float | The actual price of the product. This column is required because, if a user adds courses after buying a subscription, the course should be added here with price=0. The actual price of course will be recorded in this column. |
| duration | integer | The duration for which the subscription is valid. The value of this column will be applicable only if the purchasable_type=Subscription |
Table Name: user_billing_informations
| Column_name | type | Description |
|---|---|---|
| id | integer | primary key |
| user_id | integer | primary key of users table |
| first_name | string | user's first name |
| last_name | string | user's lastname |
| country | string | country |
| address_1 | text | address |
| address_2 | text | address |
| city | string | city |
| state | string | state |
| postal_code | string | postal code / zip code |
| created_at | date_time | date on which the record was created |
| updated_at | date_time | date on which this information was last modified. |
Only when pricing policy of the company is set to Subscription based.
When a user purchases a product, He shall be buying a subscription. The Cart Item will be referencing 'Subscription' as a product. Coupon codes can be redeemed against a subscription. Once the order is confirmed, then the product gets added to the users enrolment and the user_subscriptions table will updated. If there is no record for the user in the user_subscriptions table then a new one will be created. If record is already present, then end_date will be updated. The value of the end_date will be set to “Today + value of 'duration' field”. The value of next_renewal_date will be set to “end_date + 1 day”.
There will be a background job that will run once in a day. The job will look into the user_subscriptions table for the records that have next_renewal_date < Today and status=Active. For each of the matching records, a new order will be placed with the current price of the subscription. Once the order goes through successfully, the end_date and next_renewal_date columns of user_subscriptions table will be updated with new values.