Skip to content

Commit a8710a9

Browse files
fix(payment): correct Stripe price calculation and webhook host
This commit addresses two critical issues related to payment processing: 1. Correct Stripe Price Calculation: Previously, the unit_amount sent to Stripe used the total line item price (order_item.price) instead of the individual product price (product.price). This caused Stripe to multiply the price by quantity again, inflating the final amount. The logic now correctly uses item.product.price as unit_amount. 2. Fix Webhook Host Configuration: Stripe webhooks were failing due to a DisallowedHost error because the container hostname ('web') was not listed in ALLOWED_HOSTS in the production settings. 'web' has now been added to the list in prod.py.
1 parent 0347b0d commit a8710a9

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

ecommerce_api/settings/prod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
('Yousef Y', '[email protected]'),
77
]
88

9-
ALLOWED_HOSTS = ['eCommerce.com', 'www.eCommerce.com']
9+
ALLOWED_HOSTS = ['eCommerce.com', 'www.eCommerce.com', 'web']
1010

1111
REDIS_URL = 'redis://cache:6379'
1212
CACHES['default']['LOCATION'] = REDIS_URL

payment/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def post(self, request, *args, **kwargs):
9595
session_data["line_items"].append(
9696
{
9797
"price_data": {
98-
"unit_amount": int(item.price * Decimal('10')), # Convert price to cents
98+
"unit_amount": int(item.product.price * Decimal('100')), # Convert price to cents
9999
"currency": "usd",
100100
"product_data": {
101101
"name": item.product.name, # Use the product name

0 commit comments

Comments
 (0)