Giter Club home page Giter Club logo

ms12-23-payments's Introduction

MS12-23-Payments

Section 23 - Adding Payments

a b c

0. Continued from Section 17


1. Run

  • npm start listening on port 3000
  • Uses dotenv package for environment variables in .env file
  • Uses ejs templating engine

2. npm packages

  • bcryptjs: ^2.4.3
  • connect-flash: ^0.1.1
  • connect-mongodb-session: ^2.1.1
  • csurf: ^1.10.0
  • dotenv: ^7.0.0
  • ejs: ^2.6.1
  • express: ^4.16.4
  • express-session: ^1.16.1
  • express-validator: ^5.3.1
  • helmet: ^3.16.0
  • mongoose: ^5.5.5
  • multer: ^1.4.1
  • nodemailer: ^6.1.1
  • pdfkit: ^0.9.1
  • stripe: ^6.31.1

3. Database

  • Database: udemy on MongoDB Atlas
  • Collections: ms1214prods, ms1214users, ms1214orders, ms12sessions
    • Stores cart info as embedded document in ms1214users

4. Section 18 (Validation) Changes:

  • Uses express-validator package
  • Uses validation arrays in middleware directory
  • Uses oldInputs object in views to keep previously entered data
  • Uses valErrs array in views for conditional css classes
  • Sanitizes inputs with trim() and normalizeEmail() in validators

5. Section 19 (Error Handling) Changes:

  • Creates catch-all error-handling middleware app.use((err, req, res, next) => {}) with 500 error page
  • Changes all .catch(err => console.log(err)); blocks to .catch(err => next(err));

6. Section 20 (File Upload & Download) Changes:

  • Adds image file upload with multer package with enctype="multipart/form-data" for form
    • Saves uploaded images to /uploads/images directory
  • Generates invoice PDF files from orders with pdfkit package
    • Saves invoice PDFs to /downloads/invoices directory
  • Requests for previously generated invoices are piped from filesystem
  • Image files of deleted products are not removed from filesystem because they are needed to generate invoices for past orders that may include deleted products

7. Section 21 (Pagination) Changes:

  • Adds pagination to '/', '/products', and '/admin/products' routes

8. Section 22 (Async Requests) Changes:

  • Adds client-side JS to delete product by id and directly removing product from DOM (code included but not used)

9. Section 23 (Stripe Payments) Changes:

  • Adds payment functionality through Stripe
    • Creates a new checkout page with Pay with Card button from Stripe
    • Replaces create-order route with create-checkout route
      • create-checkout route is placed in app.js to avoid csrf token error
    • Creates order, submits payment data to Stripe, clears cart, displays orders page

10. Updates 5/2/2019

  • Add descending createdAt sort order to '/', '/products', and '/admin/products' routes
  • Add deleted field to Product model with default false
    • Only products with {deleted: false} are shown
    • Set to true when product is deleted by user
    • Product is not deleted from database so it can be used to generate invoices in the future
  • Throw an error when attempting to view/edit deleted product through URL

ms12-23-payments's People

Contributors

chilin89117 avatar

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.