Skip to content

Commit 54a3c96

Browse files
committed
normalizing currencies
1 parent e4ea32e commit 54a3c96

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

donation-api/src/donation_api/constants.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ class Constants:
4545
stripe_maximum_amount: int = int(os.getenv("STRIPE_MAXIMUM_AMOUNT") or "999999")
4646

4747
def __post_init__(self):
48-
self.alllowed_currencies = (
49-
os.getenv("ALLOWED_CURRENCIES") or "USD|EUR|CHF"
50-
).split("|")
48+
self.alllowed_currencies = [
49+
currency.upper()
50+
for currency in (os.getenv("ALLOWED_CURRENCIES") or "USD|EUR|CHF").split(
51+
"|"
52+
)
53+
]
5154

5255
self.stripe_webhook_testing_ips = os.getenv(
5356
"STRIPE_WEBHOOK_TESTING_IPS", ""

donation-api/src/donation_api/stripe.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ async def check_config():
181181
)
182182
async def create_payment_intent(pi_payload: PaymentIntentRequest):
183183
"""API endpoint to receive Book addition requests and add to database"""
184-
if not re.match(r"[a-z]{3}", pi_payload.currency.lower()):
184+
if not re.match(r"[A-Z]{3}", pi_payload.currency.upper()):
185185
logger.error("Currency doesnt look like a currency")
186186
raise HTTPException(
187187
status_code=HTTPStatus.BAD_REQUEST,
188188
detail="Currency doesnt look like a currency",
189189
)
190-
if pi_payload.currency not in conf.alllowed_currencies:
190+
if pi_payload.currency.upper() not in conf.alllowed_currencies:
191191
raise HTTPException(
192192
status_code=HTTPStatus.BAD_REQUEST,
193193
detail="Currency not supported",

0 commit comments

Comments
 (0)