Skip to content

Commit

Permalink
normalizing currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rgaudin committed Nov 26, 2024
1 parent e4ea32e commit 54a3c96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions donation-api/src/donation_api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""
Expand Down
4 changes: 2 additions & 2 deletions donation-api/src/donation_api/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 54a3c96

Please sign in to comment.