Skip to content

Commit

Permalink
feat: display tax details for countries where taxes are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali145 committed Aug 22, 2024
1 parent 1ceb478 commit d110105
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
15 changes: 15 additions & 0 deletions ecommerce/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ def calculate_tax(
return (0, "", item_price)


def display_taxes(user):
"""
Calculates the taxes display for a specific user.
Args:
user(users.User): User object
"""
return (
settings.FEATURES.get("ENABLE_TAXES_DISPLAY", False)
and user.is_authenticated
and user.legal_address.country
in TaxRate.objects.filter(active=True).values_list("country_code", flat=True)
)


def generate_cybersource_sa_signature(payload):
"""
Generate an HMAC SHA256 signature for the CyberSource Secure Acceptance payload
Expand Down
7 changes: 4 additions & 3 deletions ecommerce/mail_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
EMAIL_WELCOME_COURSE_RUN_ENROLLMENT,
)
from mitxpro.utils import format_price
from users.models import User

log = logging.getLogger()
ENROLL_ERROR_EMAIL_SUBJECT = "MIT xPRO enrollment error"
Expand Down Expand Up @@ -297,6 +298,7 @@ def send_ecommerce_order_receipt(order, cyber_source_provided_email=None):
cyber_source_provided_email: Include the email address if user provide though CyberSource payment process.
order: An order.
"""
from ecommerce.api import display_taxes
from ecommerce.serializers import OrderReceiptSerializer

data = OrderReceiptSerializer(instance=order).data
Expand All @@ -306,6 +308,7 @@ def send_ecommerce_order_receipt(order, cyber_source_provided_email=None):
order = data.get("order")
receipt = data.get("receipt")
country = pycountry.countries.get(alpha_2=purchaser.get("country"))
user = User.objects.get(email=purchaser.get("email"))
recipients = [purchaser.get("email")]
if cyber_source_provided_email and cyber_source_provided_email not in recipients:
recipients.append(cyber_source_provided_email)
Expand Down Expand Up @@ -356,9 +359,7 @@ def send_ecommerce_order_receipt(order, cyber_source_provided_email=None):
"company": purchaser.get("company"),
"vat_id": purchaser.get("vat_id"),
},
"enable_taxes_display": settings.FEATURES.get(
"ENABLE_TAXES_DISPLAY", False
),
"enable_taxes_display": display_taxes(user),
},
),
)
Expand Down
2 changes: 1 addition & 1 deletion mail/templates/product_order_receipt/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Cambridge, MA 02139 USA
<br />
{% if enable_taxes_display %}
GSTIN: Pending
GSTIN: 9923USA29055OSB
<br />
{% endif %}
Support:
Expand Down
4 changes: 3 additions & 1 deletion mitxpro/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ def get_js_settings(request: HttpRequest):
Returns:
dict: the settings object
"""
from ecommerce.api import display_taxes

return {
"gtmTrackingID": settings.GTM_TRACKING_ID,
"gaTrackingID": settings.GA_TRACKING_ID,
Expand All @@ -600,7 +602,7 @@ def get_js_settings(request: HttpRequest):
"course_dropdown": settings.FEATURES.get("COURSE_DROPDOWN", False),
"webinars": settings.FEATURES.get("WEBINARS", False),
"enable_blog": settings.FEATURES.get("ENABLE_BLOG", False),
"enable_taxes_display": settings.FEATURES.get("ENABLE_TAXES_DISPLAY", False),
"enable_taxes_display": display_taxes(request.user),
"enable_enterprise": settings.FEATURES.get("ENABLE_ENTERPRISE", False),
}

Expand Down
2 changes: 1 addition & 1 deletion static/js/containers/pages/ReceiptPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class ReceiptPage extends React.Component<Props> {
<br />
Cambridge, MA 02139 USA
{SETTINGS.enable_taxes_display ? (
<div>GSTIN: Pending</div>
<div>GSTIN: 9923USA29055OSB</div>
) : null}
Support:{" "}
<a href={`mailto:${SETTINGS.support_email}`}>
Expand Down

0 comments on commit d110105

Please sign in to comment.