Skip to content

Commit

Permalink
COD
Browse files Browse the repository at this point in the history
  • Loading branch information
amjedsaleel committed Nov 24, 2021
1 parent c605608 commit 407bebf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
5 changes: 3 additions & 2 deletions payment/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
urlpatterns = [
path('paypal/', views.paypal, name='paypal'),
path('razorpay-payment-verification/', views.razorpay_payment_verification, name='razorpay-payment-verification'),
path('failed/', views.failed, name='payment-failed')
path('failed/', views.failed, name='payment-failed'),
path('cash-on-delivery-confirmation/', views.cod_confirmation, name='cod-confirmation'),
path('cash-on-delivery/', views.cash_on_delivery, name='cash-on-delivery'),
]

40 changes: 39 additions & 1 deletion payment/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# Stated library
import threading
from datetime import datetime

# third party
import razorpay

# Django
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.http import JsonResponse
from django.conf import settings
from django.contrib import messages

# local Django
from .models import Payment
from accounts.verification import send_otp, verify_otp_number
from order.utils import make_order


# Create your views here.

client = razorpay.Client(auth=(settings.RAZOR_KEY_ID, settings.RAZOR_KEY_SECRET))
Expand Down Expand Up @@ -66,3 +73,34 @@ def razorpay_payment_verification(request):

def failed(request):
return render(request, 'payment/payment-failed.html')


def cod_confirmation(request):
t1 = threading.Thread(target=send_otp, args=(request.user.mobile, ))
t1.start()
messages.success(request, 'Enter otp to complete order')
return redirect('payments:cash-on-delivery')


def cash_on_delivery(request):

if request.method == 'POST':
otp = request.POST.get('otp')
verify = verify_otp_number(request.user.mobile, otp)

if verify:
# Saving payment details
payment = Payment.objects.create(
user=request.user,
payment_id=f'COD{datetime.now().strftime("%Y%m%d%H%M%S")}',
amount_paid=request.session['grand_total'],
payment_method='COD',
status=True
)
request.session['payment_id'] = payment.id
make_order(request)
return redirect('order:order-completed')

messages.error(request, 'Invalid OTP')
return redirect('payments:cash-on-delivery')
return render(request, 'accounts/verify-otp.html')
3 changes: 2 additions & 1 deletion templates/order/review-order.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ <h5 class="card-header">Review Products</h5>
<!-- PayPal Button Will Load -->
</div>
<div>
<a href="#" class="btn btn-outline-primary w-100" style="border-radius: 20px;">COD</a>
<a href="{% url 'payments:cod-confirmation' %}" class="btn btn-outline-primary w-100"
style="border-radius: 20px;">COD</a>
</div>
<div>
<a href="#" class="btn btn-primary w-100 mt-3" style="border-radius: 20px;"
Expand Down

0 comments on commit 407bebf

Please sign in to comment.