Fix unit_amount retrieval and subtotal calculation

This commit is contained in:
Nathan Chapman 2022-12-30 14:12:52 -07:00
parent e9bb8714fc
commit df1ce8d265
3 changed files with 7 additions and 10 deletions

View File

@ -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,

View File

@ -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.

View File

@ -41,10 +41,6 @@
<img src="{% static 'images/box.png' %}" alt="">
Orders
</a>
<a href="{% url 'dashboard:subscription-list' %}">
<img src="{% static 'images/recurrent.png' %}" alt="">
Subscriptions
</a>
<a href="{% url 'dashboard:customer-list' %}">
<img src="{% static 'images/customer.png' %}" alt="">
Customers