diff --git a/README.md b/README.md index a3fdfc3c..49428cbe 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,34 @@ -# Django-Ecommerce +# Django E-commerce. -Ecommerce website built with Django 2.2.3, Python 3.7.3, and AWS +

+ + + + + + + + +

-![image](https://user-images.githubusercontent.com/29988949/65267147-499fc580-dac9-11e9-90e8-eccbc93c7c3a.png) -`Product Slide` +
+ +Ecommerce website built with Django 2.2.3, Python 3.7.3. +Other features include: +- integrated with Stripe payment +- depolyed on AWS (still working on it) + +## About this Project: -![image](https://user-images.githubusercontent.com/29988949/65999313-ff67fe00-e451-11e9-9ed9-fc7bce704f17.png) +The repository is a start point for most of my professional projects; for this, I'm using as a part of my portfolio, feel free to use wherever you want. I'll be happy if you provide any feedback or code improvements or suggestions. + +`Product Slide` + `Shop Page` + + ![image](https://user-images.githubusercontent.com/29988949/66098968-923f9000-e559-11e9-8691-cd5c2b181ca1.png) `Product Detail Page` @@ -26,18 +46,19 @@ Ecommerce website built with Django 2.2.3, Python 3.7.3, and AWS `Order Success Page` ![image](https://user-images.githubusercontent.com/29988949/66291657-3e091880-e897-11e9-830b-6cf44e72a995.png) -# Installation +## Installation -`pip install django` - -`virtualenv env` - -# For Mac/ Linux +``` +$ pip install django` +$ virtualenv env` +``` +### For Mac/ Linux +``` `source env/bin/activate` - -# For Window - +``` +### For Window +``` `env\scripts\activate` `pip install -r requirements.txt` @@ -47,19 +68,144 @@ Ecommerce website built with Django 2.2.3, Python 3.7.3, and AWS `python manage.py migrate` `python manage.py runserver` +``` +## For Admin Login -# For Admin Login - -```python +``` python manage.py createsuperuser Username : admin Password : 12345678 ``` -# Demo +## Potential Error and solutions +### +django python tried to input http instead of https, but still have the following error: [13/Oct/2023 18:45:36] code 400, message Bad request version ('u|q&L¹°zUÀ\x00"\x13\x01\x13\x03\x13\x02À+À/̨̩À,À0À') +[13/Oct/2023 18:45:36] You're accessing the development server over HTTPS, but it only supports HTTP. + +This error indicates that there's an attempt to access the Django development server over HTTPS, but it only supports HTTP. This might be due to a few reasons: +1. **Clear browser cache**: Clear the cache of your browser and try again. Sometimes, the browser remembers that it should access a certain URL via HTTPS and tries to do so every time. + -http://djangoecommerce.pythonanywhere.com # HTML Template https://colorlib.com/etc/fashe/index.html + + +## Some technical information: + +- Django - 3.1.1 +- Django Allauth - 0.42.0 +- Django Crispy Forms - 1.9.2 +- Django Environ - 0.4.5 +- Stripe - 2.51.0 + + +## To Install: + +Cloning the Repository: + +``` +$ git clone https://github.com/fl4viooliveira/django_ecommerce.git + +$ cd django_ecommerce + +``` + +Installing the environment control: + +``` +$ pip install virtualenv + +$ virtualenv env + +``` + +Activating the environment: + +on Windows: +``` +env\Scripts\activate + +``` +on Mac OS / Linux: +``` +$ source env/bin/activate + +``` + +Installing dependencies: + +``` +$ pip install -r requirements.txt + +``` + +Create a .env file on ecom folder (/ecom/.env) setting all requirements without using space after "=". + +Copy and paste on our .env file: + +``` +DEBUG= +SECRET_KEY= +DEFAULT_FROM_EMAIL= +NOTIFY_EMAIL= +PAYPAL_SANDBOX_CLIENT_ID= +PAYPAL_SANDBOX_SECRET_KEY= +PAYPAL_LIVE_CLIENT_ID= +PAYPAL_LIVE_SECRET_KEY= +STRIPE_PUBLIC_KEY= +STRIPE_SECRET_KEY= +STRIPE_WEBHOOK_SECRET= + +``` + +Last commands to start: + +``` +$ python manage.py makemigrations + +$ python manage.py migrate + +``` +Create a super user: + +``` +$ python manage.py createsuperuser admin-name + +``` + +Finishing running server: + +``` +$ python manage.py runserver + +``` + +## Other related topics and solutions +### stripe integration +When testing your e-commerce website, you certainly wouldn't want to make actual payments for each transaction. Thankfully, Stripe provides a testing environment with a set of test API keys that you can use. Here's a general process on how to test Stripe payment functionality: + + +1. **Get your test API keys**: Go to the Stripe Dashboard and switch the view from "Live" to "Test". You will find publishable and secret API keys for testing. Use these keys in your test environment. + +2. **Use test card numbers**: Stripe provides a variety of [test card numbers](https://stripe.com/docs/testing#cards) that you can use to simulate different types of behavior. For example, the card number `4242 4242 4242 4242` simulates a successful payment, while other numbers can simulate different types of failures. + +3. **Simulate different scenarios**: In addition to successful payments and payment failures, you can also simulate other scenarios, like refunds, disputes, and subscription changes. Check the [Stripe testing documentation](https://stripe.com/docs/testing) for more details. + +4. **Use Stripe's webhook testing**: If your application uses webhooks, you can use Stripe's webhook testing feature to send sample events to your server. + +5. **Inspect and monitor**: Use the Stripe Dashboard to view and monitor your test transactions. You can check the details of each transaction, including the associated requests and responses. + +Remember to make sure that you only use your test API keys and test card numbers in your test environment, and never in your live environment. Also, make sure to thoroughly test all aspects of your payment functionality, including edge cases and failure scenarios, to ensure that your application handles all possible situations correctly. + +### Chrome and other browser show error and changing your http to https +Clear Browsing Data: Sometimes, Chrome stores settings or cookies that force redirection to HTTPS. Clearing them might solve the issue. + +## License + + + NPM +   + +This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/fl4viooliveira/django_ecommerce/blob/master/LICENSE) file for details. diff --git a/core/models.py b/core/models.py index b6451884..bb2fdc2b 100644 --- a/core/models.py +++ b/core/models.py @@ -25,6 +25,7 @@ class Slide(models.Model): + id = models.AutoField(primary_key=True) caption1 = models.CharField(max_length=100) caption2 = models.CharField(max_length=100) link = models.CharField(max_length=100) @@ -35,6 +36,7 @@ def __str__(self): return "{} - {}".format(self.caption1, self.caption2) class Category(models.Model): + id = models.AutoField(primary_key=True) title = models.CharField(max_length=100) slug = models.SlugField() description = models.TextField() @@ -51,6 +53,7 @@ def get_absolute_url(self): class Item(models.Model): + id = models.AutoField(primary_key=True) title = models.CharField(max_length=100) price = models.FloatField() discount_price = models.FloatField(blank=True, null=True) @@ -83,6 +86,7 @@ def get_remove_from_cart_url(self): class OrderItem(models.Model): + id = models.AutoField(primary_key=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) ordered = models.BooleanField(default=False) @@ -108,6 +112,7 @@ def get_final_price(self): class Order(models.Model): + id = models.AutoField(primary_key=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) ref_code = models.CharField(max_length=20) @@ -151,6 +156,7 @@ def get_total(self): class BillingAddress(models.Model): + id = models.AutoField(primary_key=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) street_address = models.CharField(max_length=100) @@ -168,6 +174,7 @@ class Meta: class Payment(models.Model): + id = models.AutoField(primary_key=True) stripe_charge_id = models.CharField(max_length=50) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, blank=True, null=True) @@ -179,6 +186,7 @@ def __str__(self): class Coupon(models.Model): + id = models.AutoField(primary_key=True) code = models.CharField(max_length=15) amount = models.FloatField() @@ -187,6 +195,7 @@ def __str__(self): class Refund(models.Model): + id = models.AutoField(primary_key=True) order = models.ForeignKey(Order, on_delete=models.CASCADE) reason = models.TextField() accepted = models.BooleanField(default=False) diff --git a/core/views.py b/core/views.py index e335e394..71ced303 100644 --- a/core/views.py +++ b/core/views.py @@ -10,7 +10,7 @@ from .forms import CheckoutForm, CouponForm, RefundForm from .models import Item, OrderItem, Order, BillingAddress, Payment, Coupon, Refund, Category from django.http import HttpResponseRedirect -from django.shortcuts import render_to_response +from django.shortcuts import render # Create your views here. import random diff --git a/demo/settings.py b/demo/settings.py index 7210b11f..9ff5ef3f 100644 --- a/demo/settings.py +++ b/demo/settings.py @@ -21,7 +21,8 @@ 'allauth.socialaccount.providers.google', 'crispy_forms', 'django_countries', - 'core' + 'core', + 'crispy_bootstrap4' ] MIDDLEWARE = [ diff --git a/requirements.txt b/requirements.txt index 9a87dec2..1be32127 100644 Binary files a/requirements.txt and b/requirements.txt differ