diff --git a/home/templates/purchase/admin/admin_purchase.html b/home/templates/purchase/admin/admin_purchase.html deleted file mode 100644 index a1097c4..0000000 --- a/home/templates/purchase/admin/admin_purchase.html +++ /dev/null @@ -1,45 +0,0 @@ -{% extends "wagtailadmin/base.html" %} -{% load static i18n %} - -{% block titletag %} - {% trans "Product" %} {% if product %} — {{ product.name }}{% endif %} -{% endblock titletag %} - -{% block content %} - {% include "wagtailadmin/shared/header.html" with title="Products" icon="tag" %} -
- ← {% trans "Back" %} -

{% if product %}{% trans "Edit product" %}{% else %}{% trans "Add product" %}{% endif %}

- - {% if error %} -
{{ error }}
- {% endif %} - -
- {% csrf_token %} - - - - - - - - - - - - -

- {% trans "Stripe product" %}: {{ product.stripe_product_id|default:"—" }}
- {% trans "Stripe price" %}: {{ product.stripe_price_id|default:"—" }} -

- -
- - {% if product %} - - {% endif %} -
-
-
-{% endblock content %} diff --git a/home/templates/purchase/admin/admin_purchase_dashboard.html b/home/templates/purchase/admin/admin_purchase_dashboard.html deleted file mode 100644 index cc0e76a..0000000 --- a/home/templates/purchase/admin/admin_purchase_dashboard.html +++ /dev/null @@ -1,23 +0,0 @@ -{% extends "wagtailadmin/base.html" %} -{% load static i18n %} - -{% block titletag %} - {% trans "Products" %} -{% endblock titletag %} - -{% block content %} - {% include "wagtailadmin/shared/header.html" with title="Products" icon="tag" %} -

{% trans "Purchasable Products" %}

- {% trans "Add product" %} - -{% endblock content %} diff --git a/home/views.py b/home/views.py index 0ba3ffd..bd24302 100644 --- a/home/views.py +++ b/home/views.py @@ -43,60 +43,3 @@ def user_chat_send(request, user_id): if request.user.is_staff: return redirect("admin_chat", user_id=user_id) return redirect("user_chat") - - -# PurchasableProduct admin views -@login_required -def admin_purchase_dashboard(request): - products = PurchasableProduct.objects.all().order_by("-created_at") - return render( - request, "purchase/admin/admin_purchase_dashboard.html", {"products": products} - ) - - -@login_required -@require_http_methods(["GET", "POST"]) -def admin_purchase(request, product_id=None): - product = None - if product_id: - product = get_object_or_404(PurchasableProduct, id=product_id) - - if request.method == "POST": - # Handle create/update/delete actions - action = request.POST.get("action") - name = request.POST.get("name", "").strip() - description = request.POST.get("description", "").strip() - price = request.POST.get("price_cents") - currency = request.POST.get("currency", "pln").strip() - - if action == "delete" and product: - product.delete() - return redirect("admin_purchase_dashboard") - - # Create or update - if not name or not price: - # Simple validation: require name and price - error = "Name and price are required" - return render( - request, - "purchase/admin/admin_purchase.html", - {"product": product, "error": error}, - ) - - price_cents = int(price) - if product: - product.name = name - product.description = description - product.price_cents = price_cents - product.currency = currency - product.save() - else: - PurchasableProduct.objects.create( - name=name, - description=description, - price_cents=price_cents, - currency=currency, - ) - return redirect("admin_purchase_dashboard") - - return render(request, "purchase/admin/admin_purchase.html", {"product": product}) diff --git a/home/wagtail_hooks.py b/home/wagtail_hooks.py index 718eb81..550e831 100644 --- a/home/wagtail_hooks.py +++ b/home/wagtail_hooks.py @@ -55,25 +55,9 @@ def register_admin_urls(): views.admin_chat, name="admin_chat", ), - path("purchase/", views.admin_purchase_dashboard, name="admin_purchase_dashboard"), - path("purchase/add/", views.admin_purchase, name="admin_purchase_add"), - path( - "purchase//", - views.admin_purchase, - name="admin_purchase", - ), ] - - - @hooks.register("register_admin_menu_item") def register_admin_chat_menu_item(): return MenuItem("Chat", reverse("admin_chat_dashboard"), icon_name="mail") - - -@hooks.register("register_admin_menu_item") -def register_admin_purchase_menu_item(): - return MenuItem("Products", reverse("admin_purchase_dashboard"), icon_name="tag") - diff --git a/purchase/stripe_client.py b/purchase/stripe_client.py deleted file mode 100644 index 3f84c17..0000000 --- a/purchase/stripe_client.py +++ /dev/null @@ -1,36 +0,0 @@ -import os - -import stripe -from django.conf import settings -from django.http import HttpResponse, request -from django.shortcuts import redirect -from django.urls import reverse - - -class StripeClient: - def __init__(self, api_key: str): - self.api_key = api_key - - self.stripe = stripe.StripeClient(api_key=self.api_key) - - def create_checkout_session(self, price_id: str): - try: - checkout_session = self.stripe.v1.checkout.sessions.create( - params={ - "line_items": [ - { - "price": price_id, - "quantity": 1, - }, - ], - "mode": "payment", - "success_url": f"{settings.SITE_URL}{reverse('purchase_success')}", - } - ) - except Exception as e: - return HttpResponse(str(e)) - - return redirect(checkout_session.url, code=303) - - -stripe_client = StripeClient(api_key=os.getenv("STRIPE_SECRET_KEY")) diff --git a/purchase/urls.py b/purchase/urls.py index 46d030b..715e471 100644 --- a/purchase/urls.py +++ b/purchase/urls.py @@ -13,6 +13,5 @@ urlpatterns = [ views.mock_refund_purchase, name="mock_refund_purchase", ), - path("test-purchase/", views.test_purchase, name="test_purchase"), path("success/", views.purchase_success, name="purchase_success"), ] diff --git a/purchase/views.py b/purchase/views.py index df68136..61545e5 100644 --- a/purchase/views.py +++ b/purchase/views.py @@ -3,7 +3,6 @@ from django.urls import reverse from django.views.decorators.http import require_POST from home.models import CoursePage -from purchase.stripe_client import stripe_client from purchase.models import CoursePurchase @@ -23,10 +22,5 @@ def mock_refund_purchase(request, purchase_id): return redirect(purchase.course.url) -@require_POST -def test_purchase(request): - return stripe_client.create_checkout_session("price_1TU8ZqK3lJAo3tbKX3T1jsBg") - - def purchase_success(request): return render(request, "success.html")