Fixes: 1) None. Extra: 1) Remove deprecated payment gateway configuration settings; 2) Refactor `EXCHANGE_RATE_API_KEY` usage into `COMPANY_CONFIGURATION` group; 3) Add logging import to `currencies.py` module.
22 lines
708 B
Python
22 lines
708 B
Python
import logging
|
|
from decimal import Decimal
|
|
|
|
import requests
|
|
from constance import config
|
|
from django.core.cache import cache
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def update_currencies_to_euro(currency: str, amount: str | float | int | Decimal) -> float:
|
|
logger.warning("update_currencies_to_euro will be deprecated soon!")
|
|
rates = cache.get("rates", None)
|
|
|
|
if not rates:
|
|
response = requests.get(f"https://rates.icoadm.in/api/v1/rates?key={config.EXCHANGE_RATE_API_KEY}")
|
|
rates = response.json().get("rates")
|
|
cache.set("rates", rates, 60 * 60 * 24)
|
|
|
|
usd_to_eur = rates.get("eur")
|
|
|
|
return float(amount) * float(rates.get(currency.lower(), 1)) / float(usd_to_eur)
|