#gwacesmokey
1 messages ยท Page 1 of 1 (latest)
Hello rubeus!
Hello! Can you give me the Event ID (starts with evt_) of one of the Events that didn't get delivered as expected?
yes of course give me a second
the event id is: evt_1NYYEoFWekfzeLYDQnejpP3i
i have tried doing payments with it so there many more but only one should be fine if i am correct/
All I can see from our end is that your server returned a 404 status code (not found). Are you sure that URL is set up to accept POST requests from Stripe?
yes but its my genuine first time actually learning to setup all of this sooo i uh thought that POST was just there because it was there
Not sure what you mean? Can you explain further?
Sorry if i sounded too informal to understand. Basically, it is my first time managing to code premium features to a bot so i never knew ** methods=["POST"])** meant something so i did not really look at it any further. Might that be the problem for it
Also because i know you are probably really experienced you should know if there are any good free tunnels that run 24/7
We deliver Events to your Webhook Endpoint by making an HTTP POST request to the URL you specify. It seems like your server is not configured to handle POST requests to the URL you specified.
Tunnels? Like ngrok?
Do you know how to fix that, i am a bit of a newbie on this
I don't know anything about how your server is set up. Can you give me more information?
like what the server is set up on? Please explain further i am really bad at comprehending things
When you set up your Webhook Endpoint in Stripe you provided a URL. That URL is hosted by a server. Is that your server or someone else's server?
Okay, so how did you set up that URL?
Did you write code to handle requests made to that URL?
if that is what u mean
Yeah, is that the code you have running on your server?
im sorry english isnt my first language and i am probably making this way harder for you, please what do u mean
It seems like you have that code on your server, but it's not running when we try to send you an Event. Correct?
yes
Okay, so the question is why is that code not running. It seems like that code isn't hooked up to the URL properly, meaning that code doesn't run when Stripe makes an HTTP POST request to your Webhook Endpoint URL.
Can you show me the code you're using to route POST requests to that URL to that code?
u mean the code of the payment being confirmed?
No.
The code you shared above is supposed to run when Stripe sends you a checkout.session.completed Event, but it's not running.
It's not running because that code probably isn't running when we send a POST request to your server.
So I'm trying to get you to show me the code that routes POST requests to your Webhook Endpoint URL to the code you share above.
wait a second, so that means i dont think i have the code in there
Can you please share that code?
becuase i only have this @bot.command()
async def upgrade(ctx):
user_id = ctx.author.id
session = stripe.checkout.Session.create(
payment_method_types=["card"],
line_items=[{
"price": "price_1234",
"quantity": 1
}],
mode="payment",
success_url="https://your-website.com/success",
cancel_url="https://your-website.com/cancel",
metadata={
"user_id": str(user_id)
}
)
await ctx.send(session.url)
@app.route("/payment_confirmation", methods=["POST"])
def payment_confirmation():
data = request.json
event = stripe.Event.construct_from(data, stripe.api_key)
if event.type == "checkout.session.completed":
session = event.data.object
user_id = session.client_reference_id
try:
connection = sqlite3.connect("my_database.db")
cursor = connection.cursor()
cursor.execute('SELECT * FROM premium_users WHERE user_id = ?', (user_id,))
existing_user = cursor.fetchone()
if existing_user:
print(f"User with ID {user_id} is already a premium user.")
else:
cursor.execute('INSERT INTO premium_users (user_id) VALUES (?)', (user_id,))
connection.commit()
print(f"User with ID {user_id} added as a premium user")
connection.close()
except sqlite3.Error as e:
print(f"Error: {e}")
return jsonify({"status": "success"})
Yeah, that's the code I wanted.
So you've got @app.route("/payment_confirmation", methods=["POST"]) up there.
Can you add some debug logging immediately after that, then trigger a manual POST request to that URL to make sure that code runs when a POST request is made?
(sorry again) what do you mean by adding debug logging after that
Do you know how to write code that logs a message you can review in the console or in a log file?
not really, as explained before i am really new to the "payment" side of creating a discord bot
So you're not a developer?
i am learning to become one, i guess i am just in my first steps i think
I recommend you find a developer who can help you learn how to do this stuff. Unfortunately I can't walk you through developer basics, it's beyond the scope of what we can help with here.
ohh okay, thank you for the help either ways
though do u know a bit on this logging part? i have been stuck on it for days
Which logging part?
yea a bit on that side i just need to know like what to do, i am really confused like on the logging part and it sending requests to the webhook
You really need to find a developer who can help you with this. There's a lot of things that need to be explained that have nothing to do with Stripe.
okay, thank you
@celest orchid are you able to help with fixing a discord bot development code or i still need to find somewhere else to ask
I'm not familiar with that, no, unless you mean specifically anything Stripe-related
well a bit and a bit not
I can help with any Stripe SDK/API questions, but not general bot development
can u help with webhooks and it not getting received when payments are completed ?
If they're Stripe webhooks, sure
That's fine - what's the issue you're having?
sorry for the late resp
here is the problem anyone know why my webhook keeps on or timing out or saying error 404. This is because im trying to make it so after payment has been completed the bot will automatically add the person's user id to the database i have created
from talking to rubeus
he told me to write code that logs a message you can review in the console or in a log file?
Yes that sounds right -- you need to do some debugging work on your server/endpoint and find out where that error comes from
yes but im not rly good at that and i just need to understand more how to do that
Personally i'd be starting with a bunch of print statements if i had access to the console, or otherwise write to a server log file
A guide like this might help: https://towardsdatascience.com/python-logging-saving-logs-to-a-file-sending-logs-to-an-api-75ec5964943f
Get your logs to where they are needed to debug your code
Probably not -- you'll need ot read and figure out what to do or hire a developer to help you
hello hanzo!
๐
because i guess from youre role youre experienced in python, do you know about bot dev?
I don't unfortunately ๐ฆ
I can help debug if there are any errors with the Stripe API
i just need help with the payment completed webhook event
I've read through the thread and seems like you are not familiar with Python as much.
As my colleague suggested above, you'd likely need to hire a developer in this case.
basically all of you guys told me to add code that will log the message right?
well i did and nothing came out after clicking o n the payment link and paying
What code did you add? Can you share the snippet as well as logs you're seeing?
a basic like logger:
logging.basicConfig(level=logging.DEBUG, format=f"%(levelname)-8s: \t %(filename)s %(funcName)s %(lineno)s - %(message)s")
logger = logging.getLogger("mylogger")
logger.debug("debugging something")
logger.info("some message")
logger.error("something went wrong")
Are you seeing those messages being printed out when you trigger the events?
Sorry I don't follow, what do you mean by !upgrade part? ๐
basically on my discord bot the !upgrade command is to go from free to premium
it all goes well but after the payment the webhook fails with no error and doesnt automatically add the user_id to the database
If you added the logger code under
def payment_confirmation():```
Then you should be seeing the log in your server console. If you're not seeing that then it likely means that your server responded with an error before it could reach that route
is the server console just the terminal
okey
@app.route("/payment_confirmation", methods=["POST"])
def payment_confirmation():
data = request.json
print("Received data:", data)
event = stripe.Event.construct_from(data, stripe.api_key)
if event.type == "checkout.session.completed":
session = event.data.object
user_id = session.client_reference_id
print(f"User ID: {user_id}")
add_premium_user(user_id)
print("Payment confirmation successful")
return jsonify({"status": "success"})
where would i put the log thing in here?
or do i put it at the end of the file?
We can't help write your code for you unfortunately.
Also it seems like you already have a print that is supposed to log out "Received Data"
Are you seeing that getting logged in your terminal?
no
this is what happens after payment
event just doesnt go through
should i use a different local tunnel?
404 error means the URL you've provided wasn't found/reachable.
So yeah could be an issue with the server itself
u know any free local tunnel for this?
u know any free tunnel
Hi ๐
I'm stepping in as @lost urchin needs to go. I believe my colleague has already provided all the advice we can on this subject.
Right, that's not something we can advise you on