emile 1 year ago
parent 833cb874db
commit 83e98bf3e2

BIN
.DS_Store vendored

Binary file not shown.

BIN
osinaweb/.DS_Store vendored

Binary file not shown.

@ -0,0 +1,23 @@
# Generated by Django 4.2.5 on 2024-04-23 17:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('billing', '0039_recurringcycle_cycle_price'),
]
operations = [
migrations.RenameField(
model_name='orderitem',
old_name='due_at',
new_name='end_at',
),
migrations.AddField(
model_name='orderitem',
name='terminated_at',
field=models.DateField(blank=True, null=True),
),
]

@ -58,10 +58,14 @@ class OrderItem(models.Model):
order = models.ForeignKey(Order, on_delete=models.CASCADE)
item = models.ForeignKey(Item, on_delete=models.CASCADE)
purchased_at = models.DateField(null=True, blank=True)
due_at = models.DateField(blank=True, null=True)
end_at = models.DateField(blank=True, null=True)
terminated_at = models.DateField(blank=True, null=True)
recurring_cycle = models.ForeignKey(RecurringCycle, on_delete=models.SET_NULL, null=True, blank=True)
@property
def get_total(self):
if self.recurring_cycle:
total = self.recurring_cycle.cycle_price
else:
total = self.item.amount
total = round(total, 2)
return total

@ -5,6 +5,9 @@ import requests
from .decorators import *
from billing.models import *
import base64
import json
import random
import string
# Create your views here.
@customer_login_required
@ -123,7 +126,7 @@ def basic_auth_header(username, password):
return f"Basic {encoded_credentials}"
import json
@customer_login_required
def initiate_checkout(request):
@ -143,11 +146,21 @@ def initiate_checkout(request):
cycle = RecurringCycle.objects.get(id = cycle_id)
price = cycle.cycle_price
existing_order = Order.objects.filter(customer=customer, status='None').first()
if existing_order:
existing_order.orderitem_set.all().delete()
order = existing_order
else:
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 = OrderItem.objects.create(order=order, item=item, end_at = datetime.now() + timedelta(days=(cycle.months * 30)))
order_item.save()
@ -211,6 +224,26 @@ def check_order_status(request, merchant_id, order_id):
due_date = order_item.purchased_at + timedelta(days=recurring_cycle)
order_item.due_at = due_date
order_item.save()
if order_item.item.type.name == 'OSIMENU':
api_url = 'https://osimenu.com/api/create-subscription/'
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=10))
api_data = {
'user': {
'username': request.user.email,
'email': request.user.email,
'password': random_string,
'first_name': request.user.first_name,
'last_name': request.user.last_name
},
'customer': {
'mobile_number': request.user.customerprofile.mobile_number
},
'subscription': {
'plan': order_item.item.title
}
}
response = requests.post(api_url, json=api_data)
print(response)
return redirect('orders')
error_message = 'Failed to retrieve order details: ' + response.text
return JsonResponse({'error': error_message}, status=500)
@ -223,11 +256,12 @@ def check_order_status(request, merchant_id, order_id):
def buy_free_osimenu(request):
api_url = 'https://osimenu.com/api/create-subscription/'
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=10))
api_data = {
'user': {
'username': request.user.email,
'email': request.user.email,
'password': 'OSITCOM2024',
'password': random_string,
'first_name': request.user.first_name,
'last_name': request.user.last_name
},
@ -259,11 +293,12 @@ def buy_free_osimenu(request):
def buy_free_osicard(request):
api_url = 'https://mybusinesscardpage.com/api/create-subscription/'
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=10))
api_data = {
'user': {
'username': request.user.email,
'email': request.user.email,
'password': 'OSITCOM2024',
'password': random_string,
'first_name': request.user.first_name,
'last_name': request.user.last_name
},

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save