emile 1 year ago
parent bf778b805d
commit 46c5b97c36

BIN
.DS_Store vendored

Binary file not shown.

BIN
osinaweb/.DS_Store vendored

Binary file not shown.

@ -26,7 +26,7 @@
<div>
<button
class="w-fit px-9 py-2 bg-secondosiblue border border-secondosiblue text-white uppercase hover:bg-white hover:text-secondosiblue duration-300 displayPaymentModal">Get
class="w-fit px-9 py-2 bg-secondosiblue border border-secondosiblue text-white uppercase hover:bg-white hover:text-secondosiblue duration-300 displayPaymentModal" item-id="{{osimenu_basic.id}}">Get
Started</button>
</div>
@ -86,7 +86,7 @@
<div>
<button
class="w-fit px-9 py-2 bg-secondosiblue border border-secondosiblue text-white uppercase hover:bg-white hover:text-secondosiblue duration-300 displayPaymentModal">Get
class="w-fit px-9 py-2 bg-secondosiblue border border-secondosiblue text-white uppercase hover:bg-white hover:text-secondosiblue duration-300 displayPaymentModal" item-id="{{osimenu_standard.id}}">Get
Started</button>
</div>
@ -142,7 +142,7 @@
<div>
<button
class="w-fit px-9 py-2 bg-secondosiblue border border-secondosiblue text-white uppercase hover:bg-white hover:text-secondosiblue duration-300 displayPaymentModal">Get
class="w-fit px-9 py-2 bg-secondosiblue border border-secondosiblue text-white uppercase hover:bg-white hover:text-secondosiblue duration-300 displayPaymentModal" item-id="{{osimenu_premium.id}}">Get
Started</button>
</div>
@ -202,7 +202,7 @@
<div>
<button
class="w-fit px-9 py-2 bg-secondosiblue border border-secondosiblue text-white uppercase hover:bg-white hover:text-secondosiblue duration-300"
data-toggle="modal" data-target="#exampleModal">Get
data-toggle="modal" data-target="#exampleModal" item-id="{{osimenu_basic.id}}">Get
Started</button>
</div>
</div>
@ -266,7 +266,7 @@
<div>
<button
class="w-fit px-9 py-2 bg-secondosiblue border border-secondosiblue text-white uppercase hover:bg-white hover:text-secondosiblue duration-300"
data-toggle="modal" data-target="#exampleModal">Get
data-toggle="modal" data-target="#exampleModal" item-id="{{osimenu_standard.id}}">Get
Started</button>
</div>
</div>
@ -326,7 +326,7 @@
<div>
<button
class="w-fit px-9 py-2 bg-secondosiblue border border-secondosiblue text-white uppercase hover:bg-white hover:text-secondosiblue duration-300"
data-toggle="modal" data-target="#exampleModal">Get
data-toggle="modal" data-target="#exampleModal" item-id="{{osimenu_premium.id}}">Get
Started</button>
</div>
</div>

@ -9,7 +9,5 @@ urlpatterns = [
path('pricing/', views.pricing, name='pricing'),
path('initiate_checkout/', views.initiate_checkout, name='initiatecheckout'),
path('check-order-status/<str:merchant_id>/<str:order_id>/', views.check_order_status, name='check_order_status'),
path('webhooks/', views.webhook_handler, name='webhook_handlers'),
]

@ -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,10 +60,18 @@ 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',
'apiUsername': api_username,
@ -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)

Binary file not shown.

Binary file not shown.

@ -4,5 +4,5 @@ from . import views
urlpatterns = [
path('register/', views.register_customer, name='register_customer'),
path('authenticate/', views.authenticate_customer, name='authenticate_customer'),
]

@ -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'})

@ -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;
}

Loading…
Cancel
Save