Git Product home page Git Product logo

codingforentrepreneurs / ecommerce-2-api Goto Github PK

View Code? Open in Web Editor NEW
101.0 15.0 76.0 1.19 MB

eCommerce 2 API is a step-by-step guide to implementing an RESTful API into your eCommerce 2 project (https://github.com/codingforentrepreneurs/ecommerce-2) using the Django Rest Framework, Django Rest Framework JWT, Django CORS Headers, and more.

License: MIT License

Python 40.76% HTML 12.14% CSS 16.52% JavaScript 30.07% ApacheConf 0.51%

ecommerce-2-api's Introduction

eCommerce 2 API Tutorial Series

eCommerce 2 API is a step-by-step guide to implementing an RESTful API into your eCommerce 2 project using the Django Rest Framework, Django Rest Framework JWT, Django CORS Headers, and more.

The project we use is eCommerce 2. Created by Team CFE @ http://joincfe.com.

Project Overview

  1. Implement a RESTful API (wikipedia) to a pre-existing eCommerce project made in Django. (Souce Code | Video Series)

  2. Products & Categories

    • Create Serializers and API Views
    • Product variations API (pricing + name)
    • Implement product photos
  3. Querying & Filtering

    • Create a Search Function for the API
    • Enable a Django Filter for further filtering of Search Results (or List Results)
  4. User Specific

    • Cart, Checkout, & finalizing Orders
    • JWT (JSON Web Token) Authentication
    • View User-only Orders
  5. Required Packages

    • Everything in src/requirements.txt of the eCommerce 2 project
    • Django Rest Framework (for API)
    • Django Rest Framework JWT (for Auth)
    • Django CORS Headers (for cross-origin HTTP requests)

Interested in learning more?

Sign up on our YouTube channel

Become a member on Coding for Entrepreneurs

The tutorial code below is the final code from the end of each tutorial video. Each link below is tied directly to the tutorial's title. Please note that some videos will not have code reference code.

Tutorial Code

5 - Pip Intallations

6 - Model Serializers

7 - API List View

8 - API Retrieve View & URL

9 - Product & Variation Serializers

10 - Product List & Retrieve View

11 - Update & Create in the API

12 - Permissions

13 - Authentication

14 - Pagination

15 - Filtering the API

16 - Using a Base API View

17 - User Checkout Part 1

18 - User Checkout Part 2

19 - User Checkout Part 3

20 - Auth with JWT Tokens

21 - Testing JWT Tokens with Python Requests

22 - JWT Token Refresh

23 - Cart API View

24 - Cart Token

25 - Update Cart in API

26 - Testing Cart API with Python Requests

27 - Display Cart Items

28 - Token Mixin

29 - Checkout API View Part 1

30 - CartToken Mixin

31 - Refactor Cart API View

32 - Checkout API View Part 2

33 - Order Serializer

34 - Add User to Checkout

35 - User Address Create & List

36 - Checkout API View Part 3

37 - Checkout API View Part 4

38 - Custom Serializer for Checkout

39 - Serializer Validation

40 - API Test Function

41 - Order from Validated Data

42 - Finalize Order Serializer

43 - Finalize Order API View

44 - Get Client Token

API Test Index.html

45 - Payment Transactions

46 - Django CORS Headers.mp4

47 - Order List & Retrieve

49 - Final Edits

50 - Final Code

ecommerce-2-api's People

Contributors

codingforentrepreneurs avatar jmitchel3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ecommerce-2-api's Issues

handle item order without payment gateway

You have used the braintree for the payment so can you please help me to figure out how i can remove that to support cash on hand not from any payment gateway.

if not order.is_complete:
				order_total = order.order_total
				nonce = request_data.get("payment_method_nonce")
				if nonce:
					result = braintree.Transaction.sale({
					    "amount": order_total,
					    "payment_method_nonce": nonce,
					    "billing": {
						    "postal_code": "%s" %(order.billing_address.zipcode),

						 },
					    "options": {
					        "submit_for_settlement": True
					    }
					})
					success = result.is_success
					if success:
						#result.transaction.id to order
						order.mark_completed(order_id=result.transaction.id)
						#order.mark_completed(order_id="abc12344423")
						order.cart.is_complete()
						response["message"] = "Your order has been completed."
						response["final_order_id"] = order.order_id
						response["success"] = True
					else:
						#messages.success(request, "There was a problem with your order.")
						error_message = result.message
						#error_message = "Error"
						response["message"] = error_message
						response["success"] = False
			else:
				response["message"] = "Ordered has already been completed."
				response["success"] = False

Here success is derived as success = result.is_success and result depends on braintree. Also order.mark_completed() depends on the result of braintree.

Confusion between Cart and CartItem

I got confuse with the model carts because there are two tables used Cart and CartItem. Can you tell me their purposes with an example, please? Because if the model was something like this then i understand

class Cart(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, on_delete=models.CASCADE)
    timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
    updated = models.DateTimeField(auto_now_add=False, auto_now=True)

class CartItem(models.Model):
    cart = models.ForeignKey(Cart, on_delete=models.CASCADE)
    product = models.ForeignKey(Product, on_delete=models.CASCADE)
    quantity = models.PositiveIntegerField(default=1)
    # line_item_total also i could not understand.
    line_item_total = models.DecimalField(max_digits=10, decimal_places=2)

But you have used items twice both in Cart and Cart Items. In cart as M2M field and in CartItem as FK.

Sorry i could not understand. Can you please explain this?

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.