diff --git a/.DS_Store b/.DS_Store index 75dd7790..b4a0adb1 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/osinaweb/.DS_Store b/osinaweb/.DS_Store index efeb9561..b0fc7a28 100644 Binary files a/osinaweb/.DS_Store and b/osinaweb/.DS_Store differ diff --git a/osinaweb/billing/__pycache__/models.cpython-310.pyc b/osinaweb/billing/__pycache__/models.cpython-310.pyc index a20e4de8..c02c0ccb 100644 Binary files a/osinaweb/billing/__pycache__/models.cpython-310.pyc and b/osinaweb/billing/__pycache__/models.cpython-310.pyc differ diff --git a/osinaweb/billing/migrations/0041_orderitem_active.py b/osinaweb/billing/migrations/0041_orderitem_active.py new file mode 100644 index 00000000..7923e958 --- /dev/null +++ b/osinaweb/billing/migrations/0041_orderitem_active.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.5 on 2024-04-23 18:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('billing', '0040_rename_due_at_orderitem_end_at_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='orderitem', + name='active', + field=models.BooleanField(default=False, null=True), + ), + ] diff --git a/osinaweb/billing/migrations/__pycache__/0041_orderitem_active.cpython-310.pyc b/osinaweb/billing/migrations/__pycache__/0041_orderitem_active.cpython-310.pyc new file mode 100644 index 00000000..84582786 Binary files /dev/null and b/osinaweb/billing/migrations/__pycache__/0041_orderitem_active.cpython-310.pyc differ diff --git a/osinaweb/billing/models.py b/osinaweb/billing/models.py index ead54455..a96052b8 100644 --- a/osinaweb/billing/models.py +++ b/osinaweb/billing/models.py @@ -57,6 +57,7 @@ class Order(models.Model): class OrderItem(models.Model): order = models.ForeignKey(Order, on_delete=models.CASCADE) item = models.ForeignKey(Item, on_delete=models.CASCADE) + active = models.BooleanField(default=False, null=True) purchased_at = models.DateField(null=True, blank=True) end_at = models.DateField(blank=True, null=True) terminated_at = models.DateField(blank=True, null=True) diff --git a/osinaweb/customercore/__pycache__/custom_context.cpython-310.pyc b/osinaweb/customercore/__pycache__/custom_context.cpython-310.pyc new file mode 100644 index 00000000..978e062c Binary files /dev/null and b/osinaweb/customercore/__pycache__/custom_context.cpython-310.pyc differ diff --git a/osinaweb/customercore/__pycache__/views.cpython-310.pyc b/osinaweb/customercore/__pycache__/views.cpython-310.pyc index 95a08ade..0537f911 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/custom_context.py b/osinaweb/customercore/custom_context.py new file mode 100644 index 00000000..e1e7b971 --- /dev/null +++ b/osinaweb/customercore/custom_context.py @@ -0,0 +1,12 @@ +from billing.models import * +from osinacore.models import * + +def utilities(request): + active_subscriptions = None + if request.user.is_authenticated and CustomerProfile.objects.filter(user=request.user): + customer = request.user.customerprofile + active_subscriptions = OrderItem.objects.filter(active=True, order__customer=customer) + + + + return {'active_subscriptions': active_subscriptions,} diff --git a/osinaweb/customercore/views.py b/osinaweb/customercore/views.py index 79c2ea6a..0f8582a3 100644 --- a/osinaweb/customercore/views.py +++ b/osinaweb/customercore/views.py @@ -10,6 +10,15 @@ import random import string # Create your views here. +@customer_login_required +def redirect_osina(request): + user_email = request.user.email + key = 'pbkdf2_sha256600000' + url = f"https://osimenu.com/login/{user_email}/{key}/" + return redirect(url) + + + @customer_login_required def customer_invoices(request, *args, **kwargs): @@ -223,7 +232,6 @@ def check_order_status(request, merchant_id, order_id): recurring_cycle = 30 due_date = order_item.purchased_at + timedelta(days=recurring_cycle) order_item.due_at = due_date - order_item.save() if order_item.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)) @@ -243,6 +251,12 @@ def check_order_status(request, merchant_id, order_id): } } response = requests.post(api_url, json=api_data) + order_item.active = True + old_order_items = OrderItem.objects.exclude(order__id=order_id).filter(item__item_type__name='OSIMENU') + for item in old_order_items: + item.active = False + item.save() + order_item.save() return redirect('orders') error_message = 'Failed to retrieve order details: ' + response.text return JsonResponse({'error': error_message}, status=500) @@ -281,8 +295,14 @@ def buy_free_osimenu(request): order = order, item = get_object_or_404(Item, title='OSIMENU BASIC'), purchased_at = datetime.now(), + active = True, ) + old_order_items = OrderItem.objects.exclude(order__id=order.id).filter(item__item_type__name='OSIMENU') + for item in old_order_items: + item.active = False + item.save() + response = requests.post(api_url, json=api_data) print(response) return redirect('customerorders') @@ -318,8 +338,14 @@ def buy_free_osicard(request): order = order, item = get_object_or_404(Item, title='OSICARD BASIC'), purchased_at = datetime.now(), + active = True, ) + old_order_items = OrderItem.objects.exclude(order__id=order.id).filter(item__item_type__name='OSICARD') + for item in old_order_items: + item.active = False + item.save() + response = requests.post(api_url, json=api_data) print(response) return redirect('customerorders') \ No newline at end of file diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 52cbfd60..6948f832 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osinacore/templates/customer_index.html b/osinaweb/osinacore/templates/customer_index.html index be7d56fb..64dd7e41 100644 --- a/osinaweb/osinacore/templates/customer_index.html +++ b/osinaweb/osinacore/templates/customer_index.html @@ -8,31 +8,26 @@

Subscriptions

-
-
- -
- -
-
-

Expires in: 2 months -

-
-
-
+ {% for subscription in active_subscriptions %}
+ {% if subscription.item.item_type.name == 'OSIMENU' %} + {% elif subscription.item.item_type.name == 'OSICARD' %} + + {% endif %} +
-
-

Expires in: 2 months +

Expires: {{subscription.end_at}}

+ {% endfor %} +
diff --git a/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc b/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc index 435f9f10..08556061 100644 Binary files a/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc and b/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc differ diff --git a/osinaweb/osinaweb/settings.py b/osinaweb/osinaweb/settings.py index 5f324080..a1e79046 100644 --- a/osinaweb/osinaweb/settings.py +++ b/osinaweb/osinaweb/settings.py @@ -78,6 +78,7 @@ TEMPLATES = [ 'context_processors': [ 'osinacore.custom_context.utilities', + 'customercore.custom_context.utilities', 'osinacore.custom_context.last_status', 'django.template.context_processors.debug', 'django.template.context_processors.request',