#π Trying to integrate Stripe payment with my database
35 messages Β· Page 1 of 1 (latest)
@lapis ruin
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
What's your code look like so far?
I have a discord bot, a database, and a website with a checkout through Stripe
the discord bot and database are good. It checks to see if the current server ID is inside of the column 'premium_server_id' after every command. tested and it works great
i just need stripe to get the server_id from the user at checkout and insert that into my database so its fully automated
i think what i need is a "webhook endpoint" in my server? Both the database and discord bot are hosted on the same server. So they interact through localhost
Your website is flask Django FastAPI?
Plain HTML?
ohhh
i just used wordpress that redirects you to my stripe checkout URL if you press the button
figured that was probably safer than any low-end version of wordpress
https://docs.stripe.com/payments/handling-payment-events
im trying to piece together this, since i think this is what i need
So you'll need to make your own webhook handler with Django/FastAPI/flask/quart etc
How do you run your bot?
a python script i leave running
Probably you want systemd or supervisord to run both
i used to have a .service file that started everything
If you're running quart/FastAPI you can integrate your bot into the same process
i dont think i am
*If you decide to use quart/FastAPI
You'll need something to handle web requests
If you use an asgi server you can run your bot in your lifespan task
# app.py
#
# Use this sample code to handle webhook events in your integration.
#
# 1) Paste this code into a new file (app.py)
#
# 2) Install dependencies
# pip3 install flask
# pip3 install stripe
#
# 3) Run the server on http://localhost:4242
# python3 -m flask run --port=4242
import json
import os
import stripe
from flask import Flask, jsonify, request
# The library needs to be configured with your account's secret key.
# Ensure the key is kept out of any version control system you might be using.
stripe.api_key = "sk_test_..."
# This is your Stripe CLI webhook secret for testing your endpoint locally.
endpoint_secret = '******'
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def webhook():
event = None
payload = request.data
sig_header = request.headers['STRIPE_SIGNATURE']
try:
event = stripe.Webhook.construct_event(
payload, sig_header, endpoint_secret
)
except ValueError as e:
# Invalid payload
raise e
except stripe.error.SignatureVerificationError as e:
# Invalid signature
raise e
# Handle the event
if event['type'] == 'checkout.session.completed':
session = event['data']['object']
# ... handle other event types
else:
print('Unhandled event type {}'.format(event['type']))
return jsonify(success=True)
``` I got this off the stripe website
so i think it wants me to use flask
is that the only thing i need to run then?
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.