diff options
author | Matthew Lemon <y@yulqen.org> | 2024-10-20 17:36:29 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-10-20 17:36:29 +0100 |
commit | a5942c7f240686146c243e22d849db97d0a904b9 (patch) | |
tree | 9918b615d9decc7e397b7b7fd4ab833e23c38791 /alphabetlearning/payments/views.py | |
parent | 97cd01917e26dc21b992b470e6960bf5a64b952b (diff) |
tidying up the cart detail page - still nowhere near good enough
Diffstat (limited to 'alphabetlearning/payments/views.py')
-rw-r--r-- | alphabetlearning/payments/views.py | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/alphabetlearning/payments/views.py b/alphabetlearning/payments/views.py index f7ab583..cf77e5b 100644 --- a/alphabetlearning/payments/views.py +++ b/alphabetlearning/payments/views.py @@ -40,14 +40,15 @@ from .models import ShoppingCart stripe.api_key = settings.STRIPE_SECRET_KEY def create_line_items(resources): - price_objs = [r.price_obj.first() for r in resources] - stripe_price_ids = [p.stripe_price_id for p in price_objs] - return [{"quantity": 1, "price": s} for s in stripe_price_ids] - pass + price_objs = [r.price_obj.first() for r in resources] + stripe_price_ids = [p.stripe_price_id for p in price_objs] + return [{"quantity": 1, "price": s} for s in stripe_price_ids] + pass + class CreateCheckoutSessionView(View): def post(self, request, *args, **kwargs): - #price = Price.objects.get(id=self.kwargs["pk"]) + # price = Price.objects.get(id=self.kwargs["pk"]) cart = ShoppingCart.objects.get(id=self.kwargs["pk"]) resources = [i.resource for i in cart.items.all()] total = sum([r.price_obj.first().price for r in resources]) @@ -86,7 +87,9 @@ class ProductLandingPageView(TemplateView): def add_to_cart(request, resource_id): resource = get_object_or_404(Resource, id=resource_id) if not resource.price_obj.first(): - return HttpResponseBadRequest(f"There is no price assigned to this resource. Please contact Alphabet Learning Support.") + return HttpResponseBadRequest( + f"There is no price assigned to this resource. Please contact Alphabet Learning Support." + ) cart, created = ShoppingCart.objects.get_or_create(user=request.user) cart_item, created = CartItem.objects.get_or_create(cart=cart, resource=resource) # cart_item.quantity += 1 @@ -98,12 +101,8 @@ def add_to_cart(request, resource_id): def cart_detail(request): cart, created = ShoppingCart.objects.get_or_create(user=request.user) resources = [i.resource for i in cart.items.all()] - total = sum([r.price_obj.first().price for r in resources]) - context = { - "cart": cart, - "resources": resources, - "total": total - } + total = sum([r.price_obj.first().price for r in resources]) / 1000 + context = {"cart": cart, "resources": resources, "total": total} return render(request, "payments/cart_detail.html", context) @@ -160,15 +159,13 @@ def stripe_webhook(request): # TODO add the transaction to our local history? Or just use Stripe? - # TODO send an email to the customer send_mail( - "Thank you for your purchase", - "You have bought something nice - enjoy it", - settings.DEFAULT_FROM_EMAIL, - [customer_email], - fail_silently=False, + "Thank you for your purchase", + "You have bought something nice - enjoy it", + settings.DEFAULT_FROM_EMAIL, + [customer_email], + fail_silently=False, ) - return HttpResponse(status=200) |