I have a simple flask site that is connected to a dial script in python. It will call the phone number you enter in on the home page and connect to your phone number along with some other things. How would I pass through the phone number the customer is trying to call through the Stripe Checkout process?
Currently I have the customer's homepage information shared in a database and it's passed through various routes via the URL ex site.com/subit/userID1234. The site works but I am not sure how to pass through these variables through the Stripe Checkout process.
I am trying to get from /stripe_purchase_page/ to /webhook/
#STRIPE
@app.route('/stripe_purchase_page/<uniqueID>')
def stripePurchasePage(uniqueID):
render_template('stripe_redirect_test.html')
stripe_keys = {
"secret_key": os.environ["STRIPE_SECRET_KEY"],
"publishable_key": os.environ["STRIPE_PUBLISHABLE_KEY"],
"endpoint_secret": os.environ["STRIPE_ENDPOINT_SECRET"]
}
stripe.api_key = stripe_keys["secret_key"]
# @app.route("/")
# def index():
# return render_template("index.html")
@app.route("/config")
def get_publishable_key():
# customer = request.form['customer']
# print(customer)
stripe_config = {"publicKey": stripe_keys["publishable_key"]}
return jsonify(stripe_config)
@app.route("/create-checkout-session")
def create_checkout_session():
domain_url = "http://localhost:5000/"
stripe.api_key = stripe_keys["secret_key"]
try:
# Create new Checkout Session for the order
# Other optional params include:
# [billing_address_collection] - to display billing address details on the page
# [customer] - if you have an existing Stripe Customer ID
# [payment_intent_data] - lets capture the payment later
# [customer_email] - lets you prefill the email input in the form
# For full details see https:#stripe.com/docs/api/checkout/sessions/create
# ?session_id={CHECKOUT_SESSION_ID} means the redirect will have the session ID set as a query param
checkout_session = stripe.checkout.Session.create(
success_url=domain_url + "success?session_id={CHECKOUT_SESSION_ID}",
cancel_url=domain_url + "cancelled",
payment_method_types=["card"],
mode="payment",
line_items=[
{
"name": "T-shirt",
"quantity": 1,
"currency": "usd",
"amount": "2000",
}
]
)
return jsonify({"sessionId": checkout_session["id"]})
except Exception as e:
return jsonify(error=str(e)), 403
@app.route("/webhook", methods=['POST'])
def stripe_webhook():
payload = request.get_data(as_text=True)
sig_header = request.headers.get('Stripe-Signature')
try:
event = stripe.Webhook.construct_event(
payload, sig_header, stripe_keys["endpoint_secret"]
)
except ValueError as e:
# Invalid payload
return 'Invalid payload', 400
except stripe.error.SignatureVerificationError as e:
# Invalid signature
return 'Invalid signature', 400
# Handle the checkout.session.completed event
if event['type'] == 'checkout.session.completed':
session = event['data']['object']
# Fulfill the purchase...
handle_checkout_session(session)
return 'Success', 200
def handle_checkout_session(session):
print("Payment was successful.")
# run some custom code here with the Unique ID