From 46c5b97c36af0091004cf052f49326626d6607c2 Mon Sep 17 00:00:00 2001 From: emile Date: Wed, 10 Apr 2024 16:17:37 +0300 Subject: [PATCH] ss --- .DS_Store | Bin 8196 -> 8196 bytes osinaweb/.DS_Store | Bin 10244 -> 10244 bytes .../__pycache__/urls.cpython-310.pyc | Bin 691 -> 629 bytes .../__pycache__/views.cpython-310.pyc | Bin 3864 -> 4194 bytes osinaweb/customercore/templates/pricing.html | 12 +- osinaweb/customercore/urls.py | 2 - osinaweb/customercore/views.py | 29 ++-- osinaweb/db.sqlite3 | Bin 999424 -> 999424 bytes osinaweb/osinacore/.DS_Store | Bin 10244 -> 10244 bytes osinaweb/osinacore/api/urls.py | 2 +- osinaweb/osinacore/api/views.py | 19 --- .../static/js/customer_dashboard/payment.js | 132 +++++++++--------- 12 files changed, 91 insertions(+), 105 deletions(-) diff --git a/.DS_Store b/.DS_Store index 5e4ef4e683a4db60d44de3e4873f83ff670df789..f1fcd39383d1368a1d2dca395ee0ec39ac585243 100644 GIT binary patch delta 106 zcmZp1XmQx!A;@85VX32FWMnuwK(LurR6zVKWtpkv z5t%@CaAsBN~ diff --git a/osinaweb/.DS_Store b/osinaweb/.DS_Store index 0f91ee0058cec75f8197befd14a6cb876035eac5..2e84bc6a5caf7ca8dd613b9058c90f2bfc0bcbdf 100644 GIT binary patch delta 16 XcmZn(XbIR*D>8Y4pvUH;BKE=nIpGFG delta 25 gcmZn(XbIR*E5c!HX`!QFXkk^qc~IegBdghCN6ov g?5D{!c?o08WI?7L5dokY9tIvpK2|j1>XB@?w1B~lqv_*0p)I8y{t*m{}M z*`l~o1cMngg(gmWpisqGo|=@ApPyZ=+0|z2h_JTx_;u9AxhzoxLcWx_zfLkRbDv-E=_{};_g;;C9p8dUcJim{BpP%@3 z(rc#Ejsll;KX>=L%tP-O`uO45TQ{jgOkzDycF{%();4jHwF~PMag%kLq>1-H+3>*T zlOVDAWQ1hE77(qVv1>VZW)v}gww?a-nNRcJyd`XjY#a7`%05X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n<7XW+xBLvjrj+#@|#xPt)34@u8ULO3nF zCP9T>IG`)qvW5drsDadgn4N?&W~Yv`x|S4nz93r9C)#caYo~>OQd#-8($H>efK?Ct zWxP9zY?E!RR+V+*lZjMciaM-DQzK65NjFZdMmJ8PO~$`JGG?if>dl00%CbE{R^%o7 z7OBY3?R8R=NA~I2{7nvwr)G4g#TrSR8V%0s2}||3exIdQq_S&GkRLi1CTGxsG`G$Y zo>$Di{#k=7PEMgFv zlia;jy@shq4&k`DNYp0IZ2w7<&)fxaQU2|Y_um!fz&O-;maqmC>_Y+$nsfzRkzX@K zeqgDskl4c7Bg%mlR18(~gxPY&waj8)*r;s);m{*=!QI(J7aVk96bgwaoIUb?waSNa zG{Sk{C?nK8^P#xJr{s~hfh)Z2zwV~y2CJiPF+U@}_ABz4Khr;p-@?^q=ko}=?umA9 zR%<>#uM!s&yrn=L0Zwh^@pYcOX|&bocfIOh_7w3IIgcVepP-%OR^Z248Y>}tegv{`VKMv zbn+u4ARZ|b>mmJ%FJbmS2bE$#$38r$ND{3@S`-M-1JWZ&4sxKQ?%AQmKZm)rn!mx? z?Wjgly;I+0srh^jyYnmT&PEj7t8&(0&HJnm)p`f2TRdvuDj8JcZbPxV-FAD2pTW5@ zRcm_c-r|wk$RF=)v7w-^s;pA1Ml*?0{4HfAYl*5+zn39|$kK3oIP=;DPS|GrAqHbz z6$P|F`7)APNp`}UWI_HIR;*O-cALP**kLkA6w2P @@ -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.sql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x{sRYPLaYD) delta 876 zcmah|OKcNY6rDHk&3MM+dCxYWerOU)kU$ljjA!gPV-fKQA_n9(fv_Np8Ygm$iDO$N z4joq@2Nbd^foU}oi^$?5R;2?jJPD~HyQ*OU3&a8`QiR&3AVgB-(@G6e2dR}Rv0!oT z;#}$6d(PFZR5~h^j;YPE!7$8w0PT)|2%zm|^fU`3KL}(h2uo@e|jYtHSqjVT9QQFjMo* zOoLC)Z5an#;{4G)1IAD)lPwkU!-d>HsLdEIwzs9DTJBUft&f}xjaV;y;@t!BR9CFG zzdRN{kVwUQb3OaM9Lkl7T6#}z-{|3D`sksdV@BslD0#TIFI(~lls_);C~RIcuhEjWG@X`Q$su^F;JekL}>-O^P; z?a!rNFGY%Hk(ozew*b_%b-ruXH@jBkYrV102#4AA@E;DZv}#s6x#s<^}2U&VV_;f%9O zjNjH&8ZBqFvC`?`@?as88B_Da`H|3ING}bY)JJv0V8$C^g0+_Xj*xg0|J@E-`JIkG eoOA@9a&+f!_@OQfPKa;+>30V|(TxG}s^K4T_ZG+i diff --git a/osinaweb/osinacore/.DS_Store b/osinaweb/osinacore/.DS_Store index 70c987c705ee33dace3a73ede7c03c1f1ed3bcf4..397a2ceba64f5e0e0510da6237cf0423f1aa8d69 100644 GIT binary patch delta 75 zcmZn(XbG6$aFU^hRb>Si8+1}1i9hD3$}hRn&fq758I7M3~+Mn;B{9|*ee0|m>1 ei}G^v^U@g@7#KHq3eDu%%&zc@WwVS3Gcy1pxfJ67 delta 37 tcmZn(XbG6$gHU^hRb@@5`^2Byu0!qa#rHay+TuJDUx^D|LqW&rv{4MzX~ 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; +}