aboutsummaryrefslogtreecommitdiffstats
path: root/alphabetlearning/payments
diff options
context:
space:
mode:
Diffstat (limited to 'alphabetlearning/payments')
-rw-r--r--alphabetlearning/payments/tests/test_views.py2
-rw-r--r--alphabetlearning/payments/views.py9
2 files changed, 8 insertions, 3 deletions
diff --git a/alphabetlearning/payments/tests/test_views.py b/alphabetlearning/payments/tests/test_views.py
index 7d0f8b5..3289c12 100644
--- a/alphabetlearning/payments/tests/test_views.py
+++ b/alphabetlearning/payments/tests/test_views.py
@@ -13,7 +13,7 @@ def test_cart_view(client, user):
@pytest.mark.django_db
def test_add_resource_to_cart(client, resource, user):
- url = reverse("payments:add_to_cart", kwargs={"resource_id": resource.id})
+ url = reverse("payments:add_to_basket", kwargs={"resource_id": resource.id})
client.force_login(user)
response = client.get(url)
assert response.status_code == 200
diff --git a/alphabetlearning/payments/views.py b/alphabetlearning/payments/views.py
index d32542b..95eb5c8 100644
--- a/alphabetlearning/payments/views.py
+++ b/alphabetlearning/payments/views.py
@@ -1,5 +1,5 @@
import stripe
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponseBadRequest
from django.core.mail import send_mail
from django.conf import settings
from django.contrib.auth.decorators import login_required
@@ -21,9 +21,11 @@ from .models import ShoppingCart
# TODO get the cart integrated with Stripe
# Steps to convert our Cart into something that can be used with Stripe:
#
+# - Fix the total in the cart
# - X Sort out the webhook
# - Associate the purchases with the users profile page
# - We need a profile page!
+# - Link in navbar (when logged in)
# - Fix the email and make it nice
# - Associate each of our resources with a Product item
# - this should be done in the create resource page
@@ -94,7 +96,10 @@ 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])
+ try:
+ total = sum([r.price_obj.first().price for r in resources])
+ except AttributeError:
+ return HttpResponseBadRequest(f"There is no price assigned to at least one of the resources you have added to the basket. Please contact Alphabet Learning Support.")
context = {
"cart": cart,
"resources": resources,