Skip to content

wdi-3-0/nile-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nile API

This is the back-end for Nile, an e-commerce site with secure payments via Stripe. Nile sells one-of-a-kind art made by various talented digital artists.

We safely handle customers' credit card information through Stripe's Checkout. Checkout creates a related token, that we use to make a charge request through Stripe.

See the front end in action here

See the front end repo here

Unfortunately, we're not able to accept payments, or make deliveries at this point. Please use a test credit card 4242 4242 4242 4242, and an expiration date some date in the future to simulate buying something.

Technologies used

  1. Express.js
  2. Node.js
  3. Stripe (Checkout)
  4. Passport
  5. Grunt
  6. Body-parser

Future issues

  1. We currently store the token generated by Stripe Checkout in our Mongodb, but this step could be eliminated.
  2. We would like to add virtuals to products, and cart schemas to directly calculate checkout totals in the back end rather than calculating in the front end.

Planning

ERD

Entity Relationship Diagram

We wrote the routes according to our understanding of how a user would navigate the site. A user would sign in, add items to the cart, check out and make payments via Stripe, then review their purchase history. For all of this flow to work, the user would need to have only one active cart.

Purchases are associated with users (a user has many purchases), and includes the items array, and a closed status. Closed purchases are categorized as purchases, and only allow get actions. Users can see their closed purchase history, but they won't be able to modify them in any way. Open purchases are categorized as cart - users can modify these carts to add and remove items.

Our biggest challenge was connecting Stripe payment API to our back-end, since the documentation assumed that Stripe would be used in apps that integrate the front and back end in the same file. We did a lot of searching through prior years' cohorts repositories, and Stripe's API documentation.

We added an event handler in the front end to trigger Stripe's Checkout (which creates a stripe token) when the user clicks check out. The event handler then makes an ajax request to our /charge route (in the stripe_routes.js file). Charge is tied to a stripe object, which includes a create charge method.

The next challenge was making sure that a user will have only one active cart at any time. Fortunately, express was flexible enough to customize according to our needs. We tweaked the get carts route to also create an empty, active cart if a user has no cart. We also wrote checkout to change the cart's status to closed, and create a new active, empty cart.

Routes

Route Verbe Description
/cart GET Find a cart associated with the current user. Create one if it doesn't exist.
/cart POST Create an active cart with an empty items array
/add-item/:id PATCH Push items into a cart's items array
/remove-item/:id DELETE Remove item from cart
/checkout PATCH Update a cart's status to inactive. Create a new active cart for the user
/products GET Get information for all products
/purchases GET Get information from past orders (closed carts)
/charge POST Receive token from Stripe checkout and create a stripe charge
/sign-up POST Create a user
/sign-in POST Sign in a user
/change-password PATCH Change user's password
/sign-out DELETE Sign user out

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •