====== Cart and Order Processing ======
===== Requirement =====
* The users should be able to enroll themselves for paid courses by purchasing them and making the payment through paypal or trust commerce gateways.
* To enable this, we should have a shopping cart functionality and the orders should be integrated with the payment processing that is already available.
===== Implementation =====
=== Shopping Cart ===
The cart is maintained per session. session[:cart_id] will have the id of the cart object in that session.
All the paid courses have an add_to_cart link, clicking on which a request is sent to carts_controller create action which adds the course to cart.
add_to_cart_link(item, link_text)
Adding course to cart will insert entries in cart_items table. Duplicate courses are not added to cart.
All the courses in cart preview will have a remove_from_cart link, clicking on which a request is sent to carts_controller destroy action which removes the course from cart.
remove_from_cart_link(item, link_text)
Note - Right now, only courses can be purchased. So, cart_items will save course_id. This can be made polymorphic if we need to purchase more types.
=== Order Processing ===
All the orders are processed in orders_controller. orders table saves the billing information and cart id where as the payment information is saved in payments table. Each payment belongs to an order.
== Payment Options Available ==
The buyer can pay with one of the following ways -
* **Credit card** (In this case the seller account can be either paypal account/trustcommerce account. This is already implemented as a part of payment integration).
* **Pay pal account** (In this case the seller should have a paypal express account. If we need this option we should only show it to the items of a seller who has registered with paypal express account. This requires the order processing flow to be modified so that the buyer is redirected to paypal and then back to our app. We also need to add one more gateway to existing gateways mentioned in the payment integration. This is not yet implemented).
===== Table Design =====
Table name - cart
This groups all cart items added in a single session.
^ Column_name ^type ^ Description ^
| id | integer | primary key |
| created_at| date_time |created date |
| updated_at| date_time|updated date |
Table name - cart_items
^ Column_name ^type ^ Description ^
| id | integer | primary key |
| course_id | integer | foreign key to the courses table. Course which is added to the cart |
| cart_id | integer |foreign key to the carts table. Cart for the current session |
| price | float | The price of the course. |
| created_at| date_time |created date |
| updated_at| date_time|updated date |
Table name - orders
^ Column_name ^type ^ Description ^
| id | integer | primary key |
| user_id | integer | foreign key to the users table. User who has placed this order |
| cart_id | integer |foreign key to the carts table. Cart whose items are ordered |
| account_name | text | |
| country | text | |
| address_1 | text | |
| address_2 | text | |
| town | text | |
| state | text | |
| zip | text | |
| phone_number | text | |
| created_at| date_time |created date |
| updated_at| date_time|updated date |
Note :
Based on the way we are going to handle the tax , the tables carts and orders might need to save the tax information.