Created
September 25, 2023 11:38
-
-
Save Snakeyyy/a313e1132217bb9855987c825bd5cd15 to your computer and use it in GitHub Desktop.
PartnerJam - Get discount - Python / Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_discounted_charge(request): | |
price, plan_name = create_charge(request) | |
if discount_token := request.COOKIES.get('partner_jam_token'): | |
try: | |
response = requests.get( | |
"https://be-app.partnerjam.com/api/v1/discount-check/", | |
params={ | |
"token": discount_token, | |
}, | |
) | |
response.raise_for_status() | |
discount = response.json().get("discount") | |
if discount: | |
price -= price * (discount / 100) | |
plan_name = f"{plan_name} ({discount}% discount)" | |
except requests.exceptions.RequestException as e: | |
print(f"Error occurred while checking discount: {e}") | |
return price, plan_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment