diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..a89f255 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +set -o errexit + +pip install -r requirements.txt + +python manage.py collectstatic --noinput +python manage.py migrate \ No newline at end of file diff --git a/core/__pycache__/models.cpython-312.pyc b/core/__pycache__/models.cpython-312.pyc index d40980b..afd6090 100644 Binary files a/core/__pycache__/models.cpython-312.pyc and b/core/__pycache__/models.cpython-312.pyc differ diff --git a/core/__pycache__/urls.cpython-312.pyc b/core/__pycache__/urls.cpython-312.pyc index ce94e30..9ca580f 100644 Binary files a/core/__pycache__/urls.cpython-312.pyc and b/core/__pycache__/urls.cpython-312.pyc differ diff --git a/core/__pycache__/views.cpython-312.pyc b/core/__pycache__/views.cpython-312.pyc index 25f7a6f..f9791ee 100644 Binary files a/core/__pycache__/views.cpython-312.pyc and b/core/__pycache__/views.cpython-312.pyc differ diff --git a/core/migrations/0016_cartorder_razor_pay_order_id_and_more.py b/core/migrations/0016_cartorder_razor_pay_order_id_and_more.py new file mode 100644 index 0000000..7948764 --- /dev/null +++ b/core/migrations/0016_cartorder_razor_pay_order_id_and_more.py @@ -0,0 +1,36 @@ +# Generated by Django 5.0 on 2024-02-06 17:12 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0015_alter_product_description_and_more'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AddField( + model_name='cartorder', + name='razor_pay_order_id', + field=models.CharField(blank=True, max_length=100, null=True), + ), + migrations.AddField( + model_name='cartorder', + name='razor_pay_payment_id', + field=models.CharField(blank=True, max_length=100, null=True), + ), + migrations.AddField( + model_name='cartorder', + name='razor_pay_payment_signature', + field=models.CharField(blank=True, max_length=100, null=True), + ), + migrations.AlterField( + model_name='productreview', + name='user', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='review', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/core/migrations/__pycache__/0016_cartorder_razor_pay_order_id_and_more.cpython-312.pyc b/core/migrations/__pycache__/0016_cartorder_razor_pay_order_id_and_more.cpython-312.pyc new file mode 100644 index 0000000..dded007 Binary files /dev/null and b/core/migrations/__pycache__/0016_cartorder_razor_pay_order_id_and_more.cpython-312.pyc differ diff --git a/core/models.py b/core/models.py index 5de28c4..8e8e413 100644 --- a/core/models.py +++ b/core/models.py @@ -142,6 +142,9 @@ class CartOrder(models.Model): paid_track = models.BooleanField(default=False) order_date = models.DateTimeField(auto_now_add=True) product_status = models.CharField(choices=STATUS_CHOICES, max_length=30, default="processing") + razor_pay_order_id=models.CharField(max_length=100,null=True,blank=True) + razor_pay_payment_id=models.CharField(max_length=100,null=True,blank=True) + razor_pay_payment_signature=models.CharField(max_length=100,null=True,blank=True) class Meta: verbose_name_plural = "Cart Orders" diff --git a/core/urls.py b/core/urls.py index 05cbc1d..aabcf10 100644 --- a/core/urls.py +++ b/core/urls.py @@ -28,9 +28,7 @@ #add to cart path("add-to-cart/",views.add_to_cart,name="add-to-cart"), path("cart/",views.cart_view,name="cart"), - path("delete-cart/",views.delete_item_from_cart,name="delete-cart"), path("update-cart/",views.update_from_cart,name="update-cart"), - # checkout - path("checkout/",views.checkout_view,name="checkout"), + path("checkout/success/",views.success,name="success"), ] \ No newline at end of file diff --git a/core/views.py b/core/views.py index 4a8b21f..99a2de4 100644 --- a/core/views.py +++ b/core/views.py @@ -10,6 +10,8 @@ from django.http import JsonResponse from django.shortcuts import redirect from django.template.loader import render_to_string +import razorpay +from django.conf import settings @login_required(login_url='/user/sign-in') def index(request): @@ -196,27 +198,17 @@ def cart_view(request): if 'cart_data_obj' in request.session: for product_id,item in request.session['cart_data_obj'].items(): cart_total_amount+=int(item['qty'])*float(item['price']) - return render(request,"core/cart.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount}) + + client=razorpay.Client(auth=(settings.KEY,settings.SECRET)) + payment=client.order.create({'amount':cart_total_amount*100,'currency':'INR','payment_capture':1}) + cart_order, created = CartOrder.objects.get_or_create(user=request.user) + cart_order.price = cart_total_amount # Update the total price if necessary + cart_order.save() + + return render(request,"core/cart.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount,'payment':payment}) else: return render(request,"core/cart.html",{"cart_data":'','totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount}) -def delete_item_from_cart(request): - product_id=str(request.GET['id']) - if 'cart_data_obj' in request.session: - if product_id in request.session['cart_data_obj']: - cart_data=request.session['cart_data_obj'] - del request.session['cart_data_obj'][product_id] - request.session['cart_data_obj']=cart_data - - cart_total_amount=0 - if 'cart_data_obj' in request.session: - for product_id,item in request.session['cart_data_obj'].items(): - cart_total_amount+=int(item['qty'])*float(item['price']) - - context={"core/async/cart-list.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount}} - - return JsonResponse({"data":context,'totalcartitems':len(request.session['cart_data_obj'])}) - def update_from_cart(request): product_id=str(request.GET['id']) @@ -232,16 +224,27 @@ def update_from_cart(request): for product_id,item in request.session['cart_data_obj'].items(): cart_total_amount+=int(item['qty'])*float(item['price']) - context=render_to_string("core/async/cart-list.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount}) + client=razorpay.Client(auth=(settings.KEY,settings.SECRET)) + payment=client.order.create({'amount':cart_total_amount*100,'currency':'INR','payment_capture':1}) + cart_order, created = CartOrder.objects.get_or_create(user=request.user) + cart_order.price = cart_total_amount # Update the total price if necessary + cart_order.save() + + + context=render_to_string("core/async/cart-list.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount,'payment':payment}) return JsonResponse({"data":context,'totalcartitems':len(request.session['cart_data_obj'])}) -def checkout_view(request): +def success(request): cart_total_amount=0 if 'cart_data_obj' in request.session: for product_id,item in request.session['cart_data_obj'].items(): cart_total_amount+=int(item['qty'])*float(item['price']) - - - return render(request,"core/checkout.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount}) \ No newline at end of file + + order_id=request.GET.get('order_id') + cart=CartOrder.objects.get(razor_pay_order_id=order_id) + cart.paid_track=True + cart.save() + + return render(request,"core/success.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount}) \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 index d3d8077..b20cbdf 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/ecomprj/__pycache__/settings.cpython-312.pyc b/ecomprj/__pycache__/settings.cpython-312.pyc index b78ffb4..bebb9ee 100644 Binary files a/ecomprj/__pycache__/settings.cpython-312.pyc and b/ecomprj/__pycache__/settings.cpython-312.pyc differ diff --git a/ecomprj/__pycache__/urls.cpython-312.pyc b/ecomprj/__pycache__/urls.cpython-312.pyc index 20045f3..64545ec 100644 Binary files a/ecomprj/__pycache__/urls.cpython-312.pyc and b/ecomprj/__pycache__/urls.cpython-312.pyc differ diff --git a/ecomprj/settings.py b/ecomprj/settings.py index e03e011..9ef53af 100644 --- a/ecomprj/settings.py +++ b/ecomprj/settings.py @@ -26,7 +26,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = '[*]' +ALLOWED_HOSTS = ["anu6569.onrender.com",'127.0.0.1','localhost'] # Application definition @@ -58,6 +58,9 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + + # render.com middleware + 'whitenoise.middleware.WhiteNoiseMiddleware', ] ROOT_URLCONF = 'ecomprj.urls' @@ -85,12 +88,12 @@ # Database # https://docs.djangoproject.com/en/5.0/ref/settings/#databases -# DATABASES = { -# 'default': { -# 'ENGINE': 'django.db.backends.sqlite3', -# 'NAME': BASE_DIR / 'db.sqlite3', -# } -# } +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} # Password validation @@ -133,6 +136,10 @@ MEDIA_URL='/media/' MEDIA_ROOT=os.path.join(BASE_DIR,'media') + +# renderstorage +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' +# ...... # Default primary key field type # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field @@ -171,4 +178,7 @@ 'codesnippet' ]), } -} \ No newline at end of file +} + +KEY='rzp_test_LcYoGkJW1B1wMM' +SECRET='9u4i7XvFk9Oh1QnTJGXBD43V' \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5e9ff4a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,57 @@ +asgiref==3.7.2 +attrs==23.2.0 +beautifulsoup4==4.12.3 +branca==0.7.0 +bs4==0.0.2 +certifi==2021.5.30 +charset-normalizer==2.0.3 +click==8.1.7 +click-plugins==1.1.1 +cligj==0.7.2 +colorama==0.4.6 +Django==5.0 +django-ckeditor==6.7.0 +django-crispy-forms==2.1 +django-jazzmin==2.6.0 +django-js-asset==2.2.0 +django-paypal==2.0 +django-shortuuidfield==0.1.3 +django-taggit==5.0.1 +fiona==1.9.5 +folium==0.15.1 +geographiclib==2.0 +geopandas==0.14.2 +geopy==2.4.1 +gunicorn==21.2.0 +humanfriendly==9.2 +idna==3.2 +Jinja2==3.1.3 +joblib==1.3.2 +MarkupSafe==2.1.4 +networkx==3.2.1 +numpy==1.26.3 +osmnx==1.8.1 +packaging==23.2 +pandas==2.2.0 +Pillow==10.1.0 +pycryptodome==3.20.0 +pyproj==3.6.1 +pyreadline==2.1 +python-dateutil==2.8.2 +pytz==2021.1 +razorpay==1.4.1 +requests==2.31.0 +scikit-learn==1.4.0 +scipy==1.12.0 +setuptools==69.0.3 +shapely==2.0.2 +shortuuid==1.0.11 +six==1.16.0 +soupsieve==2.5 +sqlparse==0.4.4 +threadpoolctl==3.2.0 +tzdata==2023.3 +ulid-py==1.1.0 +urllib3==1.26.6 +whitenoise==6.6.0 +xyzservices==2023.10.1 diff --git a/static/assets/css/checkout.css b/static/assets/css/checkout.css index f594c38..8ad55bb 100644 --- a/static/assets/css/checkout.css +++ b/static/assets/css/checkout.css @@ -69,9 +69,6 @@ input:focus::-webkit-input-placeholder background-color: #ffffff; padding: 2vh; } -.checking-out .left img{ - width: 2rem; -} .checking-out .left .col-4{ padding-left: 0; } @@ -88,28 +85,7 @@ input:focus::-webkit-input-placeholder .checking-out .lower{ line-height: 2; } -.checking-out .btn{ - background-color: rgb(23, 4, 189); - border-color: rgb(23, 4, 189); - color: white; - width: 100%; - font-size: 0.7rem; - margin: 4vh 0 1.5vh 0; - padding: 1.5vh; - border-radius: 0; -} -.checking-out .btn:focus{ - box-shadow: none; - outline: none; - box-shadow: none; - color: white; - -webkit-box-shadow: none; - -webkit-user-select: none; - transition: none; -} -.checking-out .btn:hover{ - color: white; -} + .checking-out input[type=checkbox]{ width: unset; margin-bottom: unset; @@ -120,6 +96,3 @@ input:focus::-webkit-input-placeholder background-position-x: 95%; background-position-y: center; } -#cvv:hover{ - -} \ No newline at end of file diff --git a/static/assets/css/success.css b/static/assets/css/success.css new file mode 100644 index 0000000..724a94b --- /dev/null +++ b/static/assets/css/success.css @@ -0,0 +1,13 @@ +.invoice-page{ + margin-top: 60px; + text-align: center; +} +.a4-paper{ + background-color: #f4f6f9; + width: 21cm; + height: 29.7cm; + padding: 2em; +} +.invoice-item-price{ + font-size: 1.4em; +} \ No newline at end of file diff --git a/static/assets/js/action.js b/static/assets/js/action.js index 743e375..3babb2f 100644 --- a/static/assets/js/action.js +++ b/static/assets/js/action.js @@ -61,28 +61,6 @@ $(document).ready(function(){ }) }) - $(".close").on('click', function() { - let product_id=$(this).attr("data-product"); - let this_val=$(this); - console.log(product_id); - console.log(this_val); - $.ajax({ - url:'/update-cart', - data:{ - 'id':product_id, - }, - datatype:"json", - beforeSend:function(){ - this_val.hide() - }, - success:function(res){ - this_val.show() - $(".cart-items-count").text(res.totalcartitems) - $("#cart-list").html(res.data) - } - }) - }) - $(".update-cart").on('click', function() { let product_id=$(this).attr("data-product"); let this_val=$(this); diff --git a/templete/core/async/cart-list.html b/templete/core/async/cart-list.html index b6bce53..b816949 100644 --- a/templete/core/async/cart-list.html +++ b/templete/core/async/cart-list.html @@ -52,7 +52,6 @@
Your Cart
Quantity Subtotal Refresh - Action @@ -74,13 +73,12 @@
Your Cart
₹ {{ item.price }}
- +
₹ {% widthratio item.price 1 item.qty %} - {% endfor %} @@ -109,9 +107,9 @@
Your Cart

{% if cart_total_amount %} - + {% else %} - + {% endif %} @@ -119,3 +117,47 @@
Your Cart
+ + \ No newline at end of file diff --git a/templete/core/cart.html b/templete/core/cart.html index ee06a6b..b8d3f94 100644 --- a/templete/core/cart.html +++ b/templete/core/cart.html @@ -56,7 +56,6 @@
Your Cart
Quantity Subtotal Refresh - Action @@ -78,13 +77,12 @@
Your Cart
₹ {{ item.price }}
- +
₹ {% widthratio item.price 1 item.qty %} - {% endfor %} @@ -113,9 +111,9 @@
Your Cart

{% if cart_total_amount %} - + {% else %} - + {% endif %} @@ -124,4 +122,45 @@
Your Cart
+ + + {% endblock content %} \ No newline at end of file diff --git a/templete/core/checkout.html b/templete/core/checkout.html index 0c85789..7f0135f 100644 --- a/templete/core/checkout.html +++ b/templete/core/checkout.html @@ -28,10 +28,10 @@
checkout

-
+
- Payment + Payment
@@ -56,44 +56,48 @@
checkout
-
+
-
Order Summary
-

2 items

+
Order Summary
+

2 items

+
-
-
-
$ 26.99
-
Be Legandary Lipstick-Nude rose
-
Qty:1
-
+ {% for product_id, item in cart_data.items %} +
+
+
+ +
+
+
₹{{ item.price }}
+
{{ item.title }}
+
Qty:{{ item.qty }}
+
+
+

+ {% endfor %}
-
-
-
-
$ 19.99
-
Be Legandary Lipstick-Sheer Navy Cream
-
Qty:1
+ +
+
+
{{ request.session.cart_data_obj|length }} Items
+
₹ {{ cart_total_amount|floatformat }}
+

+
+
Shipping
+
₹ 0 (Free)
+

+
+
TOTAL PRICE
+
₹ {{ cart_total_amount|floatformat }}
-
-
-
-
Subtotal
-
$ 46.98
-
-
-
Delivery
-
Free
-
-
-
Total to pay
-
$ 46.98
-
- - -

Complimentary Shipping & Returns

+
+ {% if cart_total_amount %} + + {% else %} + + {% endif %} +
@@ -102,4 +106,5 @@
checkout
+ {% endblock content %} \ No newline at end of file diff --git a/templete/core/success.html b/templete/core/success.html new file mode 100644 index 0000000..bd690c7 --- /dev/null +++ b/templete/core/success.html @@ -0,0 +1,106 @@ +{% extends 'partials/base.html' %} +{% load static %} + +{% block content %} + +
+
+

+

Dashboard

+
+
+
+
+
+
+ +
+
+

INVOICE

+

ID-NUMBER:4564898

+
+
+
+
+ + +

+ + + + + + + + + + {% for product_id, item in cart_data.items %} + + + + + + + {% endfor %} + + + + + + + + + + + + + + + + + + + +
ProductPriceQuantitySubtotal
+ + ₹ {{ item.price }} +
+ {{ item.qty }} +
+
₹ {{ cart_total_amount }}
Subtotal₹ {{ cart_total_amount }}
Tax (0%)0
Shipping (Free)0
Grand Total₹ {{ cart_total_amount }}
+
+
+
+
+
+
+
+ + +{% endblock content %} \ No newline at end of file diff --git a/templete/partials/base.html b/templete/partials/base.html index 49a11dc..803d3e9 100644 --- a/templete/partials/base.html +++ b/templete/partials/base.html @@ -14,6 +14,7 @@ integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> + diff --git a/userauths/__pycache__/razorpay_integration.cpython-312.pyc b/userauths/__pycache__/razorpay_integration.cpython-312.pyc new file mode 100644 index 0000000..e9d4ed8 Binary files /dev/null and b/userauths/__pycache__/razorpay_integration.cpython-312.pyc differ diff --git a/userauths/__pycache__/urls.cpython-312.pyc b/userauths/__pycache__/urls.cpython-312.pyc index efc2108..ac28b57 100644 Binary files a/userauths/__pycache__/urls.cpython-312.pyc and b/userauths/__pycache__/urls.cpython-312.pyc differ diff --git a/userauths/__pycache__/views.cpython-312.pyc b/userauths/__pycache__/views.cpython-312.pyc index ba598b2..39691eb 100644 Binary files a/userauths/__pycache__/views.cpython-312.pyc and b/userauths/__pycache__/views.cpython-312.pyc differ