From df1ce8d265e20890c684e2cda06a26f2cf821e74 Mon Sep 17 00:00:00 2001 From: Nathan Chapman Date: Fri, 30 Dec 2022 14:12:52 -0700 Subject: [PATCH] Fix unit_amount retrieval and subtotal calculation --- src/core/models.py | 5 +++-- src/storefront/views.py | 8 ++++---- src/templates/dashboard.html | 4 ---- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/core/models.py b/src/core/models.py index 92e8da8..3323210 100644 --- a/src/core/models.py +++ b/src/core/models.py @@ -568,7 +568,7 @@ class Subscription(models.Model): subscription = {} for x in data: - if 'products_and_quantities' in x['metadata']: + if 'Coffee' in x['description']: subscription['unit_price'] = self.convert_int_to_decimal(x['price']['unit_amount']) if 'Shipping' in x['description']: @@ -585,7 +585,8 @@ class Subscription(models.Model): customer=self.customer, status=OrderStatus.UNFULFILLED, shipping_address=self.shipping_address, - subtotal_amount=self.convert_int_to_decimal(data_object['subtotal']), + subtotal_amount=self.convert_int_to_decimal( + data_object['subtotal']) - subscription['shipping_cost'], shipping_total=subscription['shipping_cost'], total_amount=self.convert_int_to_decimal(data_object['total']), weight=self.total_weight, diff --git a/src/storefront/views.py b/src/storefront/views.py index 9620686..46f4acf 100644 --- a/src/storefront/views.py +++ b/src/storefront/views.py @@ -779,10 +779,10 @@ def stripe_webhook(request): data_object = data['object'] - logger.warning('\n') - logger.warning(event_type.upper() + ':\n') - logger.warning(data) - logger.warning('\n') + # logger.warning('\n') + # logger.warning(event_type.upper() + ':\n') + # logger.warning(data) + # logger.warning('\n') if event_type == 'checkout.session.completed': # Payment is successful and the subscription is created. diff --git a/src/templates/dashboard.html b/src/templates/dashboard.html index 5c1a0b8..0f6734a 100644 --- a/src/templates/dashboard.html +++ b/src/templates/dashboard.html @@ -41,10 +41,6 @@ Orders - - - Subscriptions - Customers