-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
26 lines (23 loc) · 844 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from flask import Flask, jsonify, request
import stripe
import os
app = Flask(__name__)
stripe.api_key = os.getenv("STRIPE_SECRET_KEY")
@app.route('/create-payment-intent', methods=['POST'])
def create_payment():
try:
data = request.get_json()
amount = data.get('amount', 500)
print(f"Creating payment intent for amount: {amount}")
intent = stripe.PaymentIntent.create(
amount=amount,
currency='usd',
automatic_payment_methods={"enabled": True}
)
print(f"Created intent with secret: {intent.client_secret}")
return jsonify({
'clientSecret': intent.client_secret # Verify this matches exactly
})
except Exception as e:
print(f"Error creating payment intent: {e}")
return jsonify(error=str(e)), 403