11
11
from donation_api .constants import conf
12
12
13
13
logger = logging .getLogger ("uvicorn.error" )
14
- stripe .api_key = conf .stripe_api_key
14
+ stripe .api_key = conf .stripe_secret_api_key
15
15
16
16
router = APIRouter (
17
17
prefix = "/stripe" ,
@@ -32,6 +32,10 @@ class PaymentIntent(BaseModel):
32
32
secret : str
33
33
34
34
35
+ class PublicConfigResponse (BaseModel ):
36
+ publishable_key : str
37
+
38
+
35
39
class StripeWebhookPayload (BaseModel ):
36
40
"""Stripe-sent payload during the webhook call
37
41
https://stripe.com/docs/webhooks"""
@@ -72,6 +76,20 @@ def can_send_webhook(ip_addr: str) -> bool:
72
76
return ip_addr in conf .stripe_webhook_sender_ips
73
77
74
78
79
+ @router .get (
80
+ "/config" ,
81
+ status_code = HTTPStatus .OK ,
82
+ responses = {
83
+ HTTPStatus .OK : {
84
+ "model" : PublicConfigResponse ,
85
+ "description" : "Health Check passed" ,
86
+ },
87
+ },
88
+ )
89
+ async def get_config ():
90
+ return {"publishable_key" : conf .stripe_publishable_api_key }
91
+
92
+
75
93
@router .get (
76
94
"/health-check" ,
77
95
status_code = HTTPStatus .OK ,
@@ -87,12 +105,23 @@ def can_send_webhook(ip_addr: str) -> bool:
87
105
)
88
106
async def check_config ():
89
107
errors : list [str ] = []
108
+
90
109
if conf .stripe_on_prod and not str (stripe .api_key ).startswith ("sk_live_" ):
91
110
errors .append ("Missing Live API Key" )
92
111
93
112
if not conf .stripe_on_prod and not str (stripe .api_key ).startswith ("sk_test_" ):
94
113
errors .append ("Missing Test API Key" )
95
114
115
+ if conf .stripe_on_prod and not conf .stripe_publishable_api_key .startswith (
116
+ "pk_live_"
117
+ ):
118
+ errors .append ("Missing Live Publishable API Key" )
119
+
120
+ if not conf .stripe_on_prod and not conf .stripe_publishable_api_key .startswith (
121
+ "pk_test_"
122
+ ):
123
+ errors .append ("Missing Test Publishable API Key" )
124
+
96
125
if not conf .stripe_webhook_sender_ips :
97
126
errors .append ("Missing Stripe IPs" )
98
127
0 commit comments