aboutsummaryrefslogtreecommitdiffstats
path: root/alphabetlearning/payments
diff options
context:
space:
mode:
Diffstat (limited to 'alphabetlearning/payments')
-rw-r--r--alphabetlearning/payments/views.py35
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)