diff --git a/.DS_Store b/.DS_Store index 5e4ef4e6..f1fcd393 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/osinaweb/.DS_Store b/osinaweb/.DS_Store index 0f91ee00..2e84bc6a 100644 Binary files a/osinaweb/.DS_Store and b/osinaweb/.DS_Store differ diff --git a/osinaweb/customercore/__pycache__/urls.cpython-310.pyc b/osinaweb/customercore/__pycache__/urls.cpython-310.pyc index 7a5d2abe..851d795d 100644 Binary files a/osinaweb/customercore/__pycache__/urls.cpython-310.pyc and b/osinaweb/customercore/__pycache__/urls.cpython-310.pyc differ diff --git a/osinaweb/customercore/__pycache__/views.cpython-310.pyc b/osinaweb/customercore/__pycache__/views.cpython-310.pyc index 1368fd28..c4d49f55 100644 Binary files a/osinaweb/customercore/__pycache__/views.cpython-310.pyc and b/osinaweb/customercore/__pycache__/views.cpython-310.pyc differ diff --git a/osinaweb/customercore/templates/pricing.html b/osinaweb/customercore/templates/pricing.html index 13bbc2b0..042d4f5c 100644 --- a/osinaweb/customercore/templates/pricing.html +++ b/osinaweb/customercore/templates/pricing.html @@ -26,7 +26,7 @@
@@ -86,7 +86,7 @@
@@ -142,7 +142,7 @@
@@ -202,7 +202,7 @@
@@ -266,7 +266,7 @@
@@ -326,7 +326,7 @@
diff --git a/osinaweb/customercore/urls.py b/osinaweb/customercore/urls.py index 8d6c6fa6..c5edd24b 100644 --- a/osinaweb/customercore/urls.py +++ b/osinaweb/customercore/urls.py @@ -9,7 +9,5 @@ urlpatterns = [ path('pricing/', views.pricing, name='pricing'), path('initiate_checkout/', views.initiate_checkout, name='initiatecheckout'), path('check-order-status///', views.check_order_status, name='check_order_status'), - path('webhooks/', views.webhook_handler, name='webhook_handlers'), - ] diff --git a/osinaweb/customercore/views.py b/osinaweb/customercore/views.py index 8185d868..2271d30c 100644 --- a/osinaweb/customercore/views.py +++ b/osinaweb/customercore/views.py @@ -4,7 +4,6 @@ from django.http import JsonResponse import requests from .decorators import * from billing.models import * -import uuid import base64 # Create your views here. @@ -30,9 +29,14 @@ def customer_products(request, *args, **kwargs): @customer_login_required def pricing(request, *args, **kwargs): + osimenu_basic = Item.objects.filter(title='OSIMENU BASIC').first() + osimenu_standard = Item.objects.filter(title='OSIMENU STANDARD').first() + osimenu_premium = Item.objects.filter(title='OSIMENU PREMIUM').first() context = { - + 'osimenu_basic': osimenu_basic, + 'osimenu_standard': osimenu_standard, + 'osimenu_premium': osimenu_premium, } return render(request, 'pricing.html', context) @@ -48,8 +52,6 @@ def basic_auth_header(username, password): return f"Basic {encoded_credentials}" - - @customer_login_required def initiate_checkout(request): api_username = 'merchant.TEST06127800' @@ -58,9 +60,17 @@ def initiate_checkout(request): merchant_name = 'Ositcom Sal' customer = request.user.customerprofile + + item_id = request.headers.get('X-Item-ID') + item = Item.objects.get(id=item_id) + order = Order.objects.create(status='None', customer=customer) order.save() order_id = order.order_id + + order_item = OrderItem.objects.create(order=order, item=item) + order_item.save() + payload = { 'apiOperation': 'INITIATE_CHECKOUT', @@ -115,6 +125,13 @@ def check_order_status(request, merchant_id, order_id): if order_details.get('result') == 'SUCCESS': order.status = 'Completed' order.save() + order_items = OrderItem.objects.filter(order=order) + for order_item in order_items: + order_item.purchased_at = datetime.now() + recurring_cycle = 30 + due_date = order_item.purchased_at + timedelta(days=recurring_cycle) + order_item.due_at = due_date + order_item.save() return JsonResponse(order_details) else: error_message = 'Failed to retrieve order details: ' + response.text @@ -125,8 +142,4 @@ def check_order_status(request, merchant_id, order_id): -def webhook_handler(request): - - project_type = ProjectType.objects.create(name='Hello') - return JsonResponse({'message': 'Webhook received and processed successfully'}, status=200) diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index d6535929..feda07ed 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osinacore/.DS_Store b/osinaweb/osinacore/.DS_Store index 70c987c7..397a2ceb 100644 Binary files a/osinaweb/osinacore/.DS_Store and b/osinaweb/osinacore/.DS_Store differ diff --git a/osinaweb/osinacore/api/urls.py b/osinaweb/osinacore/api/urls.py index 9ee8feac..a323a856 100644 --- a/osinaweb/osinacore/api/urls.py +++ b/osinaweb/osinacore/api/urls.py @@ -4,5 +4,5 @@ from . import views urlpatterns = [ path('register/', views.register_customer, name='register_customer'), - path('authenticate/', views.authenticate_customer, name='authenticate_customer'), + ] \ No newline at end of file diff --git a/osinaweb/osinacore/api/views.py b/osinaweb/osinacore/api/views.py index f25eaa76..220e5592 100644 --- a/osinaweb/osinacore/api/views.py +++ b/osinaweb/osinacore/api/views.py @@ -4,8 +4,6 @@ from rest_framework.decorators import api_view from rest_framework.response import Response from osinacore.models import * from .serializers import * -from django.contrib.auth import authenticate, login -from django.http import JsonResponse, HttpResponseRedirect @api_view(['POST']) @@ -29,20 +27,3 @@ def register_customer(request): else: return Response({'message': 'User and Customer data are required'}, status=status.HTTP_400_BAD_REQUEST) - - - - - -@api_view(['POST']) -def authenticate_customer(request): - if request.method == 'POST': - email = request.data.get('email') - - user = User.objects.filter(email=email).first() - - if user is not None: - redirect_url = f'https://newosina.osinode.com/login/{email}/' - return HttpResponseRedirect(redirect_url) - else: - return JsonResponse({'success': False, 'error': 'User does not exist'}) \ No newline at end of file diff --git a/osinaweb/static/js/customer_dashboard/payment.js b/osinaweb/static/js/customer_dashboard/payment.js index 3e15beb4..84671f30 100644 --- a/osinaweb/static/js/customer_dashboard/payment.js +++ b/osinaweb/static/js/customer_dashboard/payment.js @@ -1,80 +1,74 @@ -document.addEventListener("DOMContentLoaded", function () { +const displayPaymentModalButtons = document.querySelectorAll('.displayPaymentModal'); +const closeButton = document.querySelector('#closePaymentModalButton'); +const paymentModal = document.getElementById('paymentModal'); - Checkout.configure({ - session: { - id: 1, // Default session ID, will be replaced with actual session ID after initiation - } +displayPaymentModalButtons.forEach(function (button) { + button.addEventListener('click', function () { + const item_id = button.getAttribute('item-id'); + paymentModal.classList.remove('hidden'); + document.body.style.overflow = 'hidden'; + + initiateCheckout(item_id); }); +}); - - function initiateCheckout() { - const csrftoken = getCookie('csrftoken'); +function initiateCheckout(item_id) { + const csrftoken = getCookie('csrftoken'); + console.log(item_id); - console.log('CSRF Token:', csrftoken); + console.log('CSRF Token:', csrftoken); - fetch('/initiate_checkout/', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-CSRFToken': csrftoken - }, - body: JSON.stringify({}) - }) - .then(response => { - if (!response.ok) { - throw new Error('Network response was not ok'); - } - return response.json(); - }) - .then(data => { - // Handle success response - console.log("Session ID: " + data.session_id); - // Update Checkout session with the fetched session ID and show the embedded page - Checkout.configure({ - session: { - id: data.session_id, - } - }); - $('#paymentContent').empty(); - Checkout.showEmbeddedPage('#paymentContent', () => { $('#paymentModal').modal(); }); - }) - .catch(error => { - console.error('There was a problem with the fetch operation:', error); - }); - } + fetch('/initiate_checkout/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-CSRFToken': csrftoken, + 'X-Item-ID': item_id + }, - // Function to get CSRF token from cookie - function getCookie(name) { - let cookieValue = null; - if (document.cookie && document.cookie !== '') { - const cookies = document.cookie.split(';'); - for (let i = 0; i < cookies.length; i++) { - const cookie = cookies[i].trim(); - if (cookie.substring(0, name.length + 1) === (name + '=')) { - cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); - break; - } - } + body: JSON.stringify({ item_id: item_id }), + }) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); } - return cookieValue; - } - - const displayPaymentModalButton = document.querySelectorAll('.displayPaymentModal'); - const closeButton = document.querySelector('#closePaymentModalButton'); - const paymentModal = document.getElementById('paymentModal'); - - displayPaymentModalButton.forEach(function (button) { - button.addEventListener('click', function () { - paymentModal.classList.remove('hidden'); - document.body.style.overflow = 'hidden'; - - initiateCheckout(); + return response.json(); + }) + .then(data => { + // Handle success response + console.log("Session ID: " + data.session_id); + // Update Checkout session with the fetched session ID and show the embedded page + Checkout.configure({ + session: { + id: data.session_id, + } }); + $('#paymentContent').empty(); + Checkout.showEmbeddedPage('#paymentContent', () => { $('#paymentModal').modal(); }); + }) + .catch(error => { + console.error('There was a problem with the fetch operation:', error); }); +} - closeButton.addEventListener('click', function () { - paymentModal.classList.add('hidden'); - sessionStorage.clear(); - document.body.style.overflow = ''; - }); +closeButton.addEventListener('click', function () { + paymentModal.classList.add('hidden'); + sessionStorage.clear(); + document.body.style.overflow = ''; }); + + +function getCookie(name) { + let cookieValue = null; + if (document.cookie && document.cookie !== '') { + const cookies = document.cookie.split(';'); + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim(); + if (cookie.substring(0, name.length + 1) === (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; +}