@@ -61,9 +61,17 @@ class StripeWebhookResponse(BaseModel):
61
61
status : str
62
62
63
63
64
+ class ApplePayPaymentSessionRequest (BaseModel ):
65
+ # defaulting to test gateway
66
+ validation_url : str = "apple-pay-gateway-cert.apple.com"
67
+
68
+
64
69
class OpaqueApplePayPaymentSession (BaseModel ):
65
70
model_config = ConfigDict (extra = "allow" )
66
71
72
+ initiative : str
73
+ initiativeContext : str
74
+
67
75
68
76
async def get_body (request : Request ):
69
77
"""raw request body"""
@@ -285,7 +293,23 @@ def webhook_received(
285
293
},
286
294
status_code = HTTPStatus .OK ,
287
295
)
288
- async def create_payment_session ():
296
+ async def create_payment_session (ps_payload : ApplePayPaymentSessionRequest ):
297
+ allowed_domains : list [str ] = [
298
+ # Global
299
+ "apple-pay-gateway.apple.com" ,
300
+ # China
301
+ "cn-apple-pay-gateway.apple.com" ,
302
+ # Testing (Global)
303
+ "apple-pay-gateway-cert.apple.com" ,
304
+ # Testing (China)
305
+ "cn-apple-pay-gateway-cert.apple.com" ,
306
+ ]
307
+ if ps_payload .validation_url not in allowed_domains :
308
+ raise HTTPException (
309
+ status_code = HTTPStatus .FORBIDDEN ,
310
+ detail = "Validation URL is not in Apple's whitelist" ,
311
+ )
312
+
289
313
payload = {
290
314
"merchantIdentifier" : conf .applepay_merchant_identifier ,
291
315
"displayName" : conf .applepay_displayname ,
@@ -295,7 +319,7 @@ async def create_payment_session():
295
319
296
320
data : dict [str , Any ] = {}
297
321
resp = requests .post (
298
- url = "https://apple-pay-gateway.apple.com /paymentservices/paymentSession" ,
322
+ url = f "https://{ ps_payload . validation_url } /paymentservices/paymentSession" ,
299
323
cert = (
300
324
str (conf .applepay_merchant_certificate_path ),
301
325
str (conf .applepay_merchant_certificate_key_path ),
0 commit comments