#gwacesmokey

1 messages ยท Page 1 of 1 (latest)

scenic sluiceBOT
pine ice
#

Hello rubeus!

timber glen
#

Hello! Can you give me the Event ID (starts with evt_) of one of the Events that didn't get delivered as expected?

pine ice
#

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/

timber glen
#

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?

pine ice
#

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

timber glen
#

Not sure what you mean? Can you explain further?

pine ice
#

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

timber glen
#

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?

pine ice
timber glen
#

I don't know anything about how your server is set up. Can you give me more information?

pine ice
timber glen
#

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?

pine ice
#

It is my server

#

hosted on local tunnel if that is what you mean

timber glen
#

Okay, so how did you set up that URL?

pine ice
#

by doing lt --port 5000 in my cmd

#

and it gave me the link like that

timber glen
#

Did you write code to handle requests made to that URL?

pine ice
#

if that is what u mean

timber glen
#

Yeah, is that the code you have running on your server?

pine ice
timber glen
#

It seems like you have that code on your server, but it's not running when we try to send you an Event. Correct?

pine ice
#

yes

timber glen
#

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?

pine ice
timber glen
#

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.

pine ice
#

wait a second, so that means i dont think i have the code in there

timber glen
#

Can you please share that code?

pine ice
#

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"})
timber glen
#

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?

pine ice
timber glen
#

Do you know how to write code that logs a message you can review in the console or in a log file?

pine ice
timber glen
#

So you're not a developer?

pine ice
#

i am learning to become one, i guess i am just in my first steps i think

timber glen
#

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.

pine ice
#

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

timber glen
#

Which logging part?

pine ice
#

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

timber glen
#

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.

scenic sluiceBOT
pine ice
#

@celest orchid are you able to help with fixing a discord bot development code or i still need to find somewhere else to ask

celest orchid
#

I'm not familiar with that, no, unless you mean specifically anything Stripe-related

pine ice
#

well a bit and a bit not

celest orchid
#

I can help with any Stripe SDK/API questions, but not general bot development

pine ice
#

can u help with webhooks and it not getting received when payments are completed ?

celest orchid
#

If they're Stripe webhooks, sure

pine ice
#

yea thats what i mean

#

but do u know lik e python because im coding the bot in python

celest orchid
#

That's fine - what's the issue you're having?

pine ice
#

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?

celest orchid
#

Yes that sounds right -- you need to do some debugging work on your server/endpoint and find out where that error comes from

pine ice
#

yes but im not rly good at that and i just need to understand more how to do that

celest orchid
#

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

pine ice
#

thank you

#

do i just copy that code shown on the site?

celest orchid
#

Probably not -- you'll need ot read and figure out what to do or hire a developer to help you

scenic sluiceBOT
pine ice
#

hello hanzo!

lost urchin
#

๐Ÿ‘‹

pine ice
#

because i guess from youre role youre experienced in python, do you know about bot dev?

lost urchin
#

I don't unfortunately ๐Ÿ˜ฆ
I can help debug if there are any errors with the Stripe API

pine ice
#

i just need help with the payment completed webhook event

lost urchin
#

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.

pine ice
#

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

lost urchin
#

What code did you add? Can you share the snippet as well as logs you're seeing?

pine ice
#

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")

lost urchin
#

Are you seeing those messages being printed out when you trigger the events?

pine ice
#

yh just at the !upgrade part to get the link to the stripe payment

#

after that nothing

lost urchin
#

Sorry I don't follow, what do you mean by !upgrade part? ๐Ÿ˜…

pine ice
#

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

lost urchin
#

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
pine ice
#

is the server console just the terminal

lost urchin
#

yes

#

where your python code is running

pine ice
#

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?

lost urchin
#

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?

pine ice
#

no

#

this is what happens after payment

#

event just doesnt go through

#

should i use a different local tunnel?

lost urchin
#

404 error means the URL you've provided wasn't found/reachable.
So yeah could be an issue with the server itself

pine ice
#

u know any free local tunnel for this?

scenic sluiceBOT
pine ice
#

u know any free tunnel

noble bay
#

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.

pine ice
#

yes

#

im just tryna find a free local tunnel thingy

#

like for the webhooks

noble bay
#

Right, that's not something we can advise you on