From 54a3c96cf18793f7617b034bd691090bb3eae590 Mon Sep 17 00:00:00 2001 From: rgaudin Date: Tue, 26 Nov 2024 10:14:42 +0000 Subject: [PATCH] normalizing currencies --- donation-api/src/donation_api/constants.py | 9 ++++++--- donation-api/src/donation_api/stripe.py | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/donation-api/src/donation_api/constants.py b/donation-api/src/donation_api/constants.py index 76e6e775..a1c5dd19 100644 --- a/donation-api/src/donation_api/constants.py +++ b/donation-api/src/donation_api/constants.py @@ -45,9 +45,12 @@ class Constants: stripe_maximum_amount: int = int(os.getenv("STRIPE_MAXIMUM_AMOUNT") or "999999") def __post_init__(self): - self.alllowed_currencies = ( - os.getenv("ALLOWED_CURRENCIES") or "USD|EUR|CHF" - ).split("|") + self.alllowed_currencies = [ + currency.upper() + for currency in (os.getenv("ALLOWED_CURRENCIES") or "USD|EUR|CHF").split( + "|" + ) + ] self.stripe_webhook_testing_ips = os.getenv( "STRIPE_WEBHOOK_TESTING_IPS", "" diff --git a/donation-api/src/donation_api/stripe.py b/donation-api/src/donation_api/stripe.py index 71a67aff..e2121334 100644 --- a/donation-api/src/donation_api/stripe.py +++ b/donation-api/src/donation_api/stripe.py @@ -181,13 +181,13 @@ async def check_config(): ) async def create_payment_intent(pi_payload: PaymentIntentRequest): """API endpoint to receive Book addition requests and add to database""" - if not re.match(r"[a-z]{3}", pi_payload.currency.lower()): + if not re.match(r"[A-Z]{3}", pi_payload.currency.upper()): logger.error("Currency doesnt look like a currency") raise HTTPException( status_code=HTTPStatus.BAD_REQUEST, detail="Currency doesnt look like a currency", ) - if pi_payload.currency not in conf.alllowed_currencies: + if pi_payload.currency.upper() not in conf.alllowed_currencies: raise HTTPException( status_code=HTTPStatus.BAD_REQUEST, detail="Currency not supported",