Commit 558b34a 1 parent bbae5e2 commit 558b34a Copy full SHA for 558b34a
File tree 3 files changed +30
-3
lines changed
donation-api/src/donation_api
3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,19 @@ class Constants:
12
12
stripe_webhook_secret : str = os .getenv ("STRIPE_WEBHOOK_SECRET" ) or ""
13
13
stripe_webhook_sender_ips : list [str ] = field (default_factory = list )
14
14
stripe_webhook_testing_ips : list [str ] = field (default_factory = list )
15
+ alllowed_currencies : list [str ] = field (default_factory = list )
16
+ merchantid_domain_association : str = (
17
+ os .getenv ("MERCHANTID_DOMAIN_ASSOCIATION" ) or ""
18
+ )
15
19
16
- stripe_minimal_amount : float = 1.0
17
- stripe_maximum_amount : float = 1000000
20
+ stripe_minimal_amount : int = int ( os . getenv ( "STRIPE_MINIMAL_AMOUNT" ) or "5" )
21
+ stripe_maximum_amount : int = int ( os . getenv ( "STRIPE_MAXIMUM_AMOUNT" ) or "999999" )
18
22
19
23
def __post_init__ (self ):
24
+ self .alllowed_currencies = (
25
+ os .getenv ("ALLOWED_CURRENCIES" ) or "USD|EUR|CHF"
26
+ ).split ("|" )
27
+
20
28
self .stripe_webhook_testing_ips = os .getenv (
21
29
"STRIPE_WEBHOOK_TESTING_IPS" , ""
22
30
).split ("|" )
Original file line number Diff line number Diff line change 2
2
3
3
from fastapi import FastAPI
4
4
from fastapi .middleware .cors import CORSMiddleware
5
- from fastapi .responses import RedirectResponse
5
+ from fastapi .responses import PlainTextResponse , RedirectResponse
6
6
7
7
from donation_api import stripe
8
8
from donation_api .__about__ import __description__ , __title__ , __version__
9
+ from donation_api .constants import conf
9
10
10
11
PREFIX = "/v1"
11
12
@@ -22,6 +23,16 @@ async def _():
22
23
"""Redirect to root of latest version of the API"""
23
24
return RedirectResponse (f"{ PREFIX } /" , status_code = HTTPStatus .PERMANENT_REDIRECT )
24
25
26
+ # could be done on infra ; this is a handy shortcut
27
+ if conf .merchantid_domain_association :
28
+
29
+ @app .get ("/.well-known/apple-developer-merchantid-domain-association" )
30
+ async def _ ():
31
+ """Used to validate domain ownership with apple/stripe"""
32
+ return PlainTextResponse (
33
+ conf .merchantid_domain_association , status_code = HTTPStatus .OK
34
+ )
35
+
25
36
api = FastAPI (
26
37
title = __title__ ,
27
38
description = __description__ ,
Original file line number Diff line number Diff line change @@ -96,6 +96,9 @@ async def check_config():
96
96
if not conf .stripe_webhook_sender_ips :
97
97
errors .append ("Missing Stripe IPs" )
98
98
99
+ if not conf .alllowed_currencies :
100
+ errors .append ("Missing currencies list" )
101
+
99
102
if errors :
100
103
raise HTTPException (
101
104
status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = "\n " .join (errors )
@@ -124,6 +127,11 @@ async def create_payment_intent(pi_payload: PaymentIntentRequest):
124
127
status_code = HTTPStatus .BAD_REQUEST ,
125
128
detail = "Currency doesnt look like a currency" ,
126
129
)
130
+ if pi_payload .currency not in conf .alllowed_currencies :
131
+ raise HTTPException (
132
+ status_code = HTTPStatus .BAD_REQUEST ,
133
+ detail = "Currency not supported" ,
134
+ )
127
135
128
136
if (
129
137
pi_payload .amount < conf .stripe_minimal_amount
You can’t perform that action at this time.
0 commit comments