Skip to content

Instantly share code, notes, and snippets.

@Snakeyyy
Created September 25, 2023 11:38
Show Gist options
  • Save Snakeyyy/a313e1132217bb9855987c825bd5cd15 to your computer and use it in GitHub Desktop.
Save Snakeyyy/a313e1132217bb9855987c825bd5cd15 to your computer and use it in GitHub Desktop.
PartnerJam - Get discount - Python / Django
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