#wizz_error

1 messages ยท Page 1 of 1 (latest)

crimson pelicanBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1348939266084044892

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

raw mantle
#

Hi, let me help you with this.

tranquil bone
#

Hello ! Please, im struggling since 1 week ๐Ÿ˜„

raw mantle
#

Could you please share your webhook handler code?

tranquil bone
#

Sure !

#

index.js right ?

raw mantle
#

I don't know how you name your files, unfortunately.

tranquil bone
raw mantle
#

What variable type is payload?

tranquil bone
#

So basically, after the payment, in the firestore database should save UID, email, plan, endDate and startDate

#

I dont know, a friend of mine tried to help me, and he did some things into it

raw mantle
#

The error you see is because the payload you provide to constructEvent() is probably parsed, and is not exactly the same as what Stripe sent out.

#

Could you please print typeof payload and payload?

tranquil bone
raw mantle
#

Where is the Request details log?

tranquil bone
#

Do you want me to reproduce the steps, and send you the new log file ? Or can i get the Request details logs from somewhere else ?

raw mantle
#

Your code is supposed to print a log with :pencil: Request details: with many local variables. Do you see it in your logs?

tranquil bone
raw mantle
#

Are you sure these are the logs from the current version of your app? Or, is the code you shared is currently running?

tranquil bone
#

Let me reproduce the steps, and tell me if im doing something wrong

soft marten
#

Hi there ๐Ÿ‘‹ I'm jumping in as my teammate needs to step away soon. The error that you shared has a couple common causes that we should look at first.

The error indicates that the value calculated by our constructEvent function doesn't match the value contained in the stripe-signature header. So we need to look at things that could impact the calculation of that hash.

tranquil bone
#

Oh sure, welcome toby, thanks for your help !

soft marten
#

First thing, is this a new webhook endpoint that you're standing up using code from a previous endpoint? If so, you should double check that the signing secret you're using in this environment, matches the signing secret for the webhook endpoint in Stripe that it's associated with.

#

Each webhook endpoint generates its own signing secret rather than them using a shared one.

tranquil bone
#

Oh, yeah, im using the key from "Signing secret

Reveal" from webhooks dashboard from stripe, and ive been applied it by using "firebase functions:config:set stripe.secret_key="sk_live_KEY" and the other command

#

So now, when i write the stripe get command, i get :

D:\ELECTRON2\immortal_companion>firebase functions:config:get stripe
{
"secret_key": "sk_live_51........",
"webhook_secret": "whsec.........."
}

D:\ELECTRON2\immortal_companion>

soft marten
#

You're using a live secret key here? Did you already get this working in testmode?
Are you able to share the ID of an Event that isn't being handled successfully? That ID should have an evt_ prefix.

tranquil bone
#

No, i didnt work in test mode..

#

I tought it was easier to implement the Stripe payments

#

๐Ÿ˜„

soft marten
#

I would strongly recommend getting everything working in testmode first, so you can make plenty of test payments without actually moving any money.

tranquil bone
#

This is it, the last checkout session

#

Ive been doing only 0.50Euro payments to test the payments

soft marten
#

You can use our test cards in testmode, and not process any real payments while you're getting everything built:
https://docs.stripe.com/testing

Use test cards to validate your Stripe integration without moving real money. Test a variety of international scenarios, including successful and declined payments, card errors, disputes, and bank authentication. You can also test non-card payment methods and redirects.

#

Are you comfortable sharing which webhook endpoint you're debugging here? I see that Event is being sent to three different ones.

tranquil bone
tranquil bone
soft marten
#

Either the URL, or the ID of the webhook endpoint which will have a we_ prefix

soft marten
#

Perfect, thanks!

#

Looking at the most recent attempt to deliver the shared Event to that endpoint, I see the following error message, which I also see in your logs. The important part seems to the be last line, can you double check the value you're using for your signing secret?

Webhook Error: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?

Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing

Note: The provided signing secret contains whitespace. This often indicates an extra newline or space is in the value

GitHub

Node.js library for the Stripe API. . Contribute to stripe/stripe-node development by creating an account on GitHub.

#

I see you're using .trim(), which I would expect to remove leading and trailing white spaces, maybe there's whitespace in the middle of the string?

tranquil bone
#

I have this code

let event;
try {
// Get the raw body
const payload = req.rawBody;
if (!payload) {
throw new Error("No raw body found in request");
}

in the index.js file from functions folder

soft marten
#

Can we start with where the error being returned by our library is pointing? It indicates that there is whitespace within the signing secret value you're trying to use.

tranquil bone
#

Should I send you the full code for

So now, when i write the stripe get command, i get :

D:\ELECTRON2\immortal_companion>firebase functions:config:get stripe
{
"secret_key": "sk_live_51........",
"webhook_secret": "whsec.........."
}

D:\ELECTRON2\immortal_companion>

?

soft marten
#

No, I don't think I need to see more code right now, as you've shared your webhook endpoint handler.

Can you add a log line in your code to log exactly what value ends up in your webhookSecret variable? Don't share the output of that log here, as signing secrets should remain secret, but the error indicates there is whitespace in that value so you should log it to confirm whether that's the case.

tranquil bone
#

Sure, but one more thing. I applied the last index.js file, and now i receive only

Webhook Error: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing

#

So no more whitespace

soft marten
#

Awesome, that's progress! So then the question is whether req.rawBody is actually giving you the raw payload of the request. Any modification of the request's payload will result in our hashing failing, it is even sensitive to whitespace changes.

tranquil bone
#

Maybe if i replace this code "app.use(bodyParser.raw({ type: "application/json" }));
" with "app.use(express.json({ verify: (req, res, buf) => { req.rawBody = buf; } }));" will fix the issue ?

soft marten
#

I think it might

tranquil bone
#

Trying now

#

Deploying the new code..

#

But i got 1 question. When i use "stripe trigger checkout.session.completed
" , why i dont see a new log into the dashboard ? I need to press "resend" manually, is that okay ?

soft marten
#

Because stripe trigger does everything in testmode

tranquil bone
#

Oh..

#

Yeah, doesnt work, same errors

soft marten
#

Are you logging the contents of the payload variable, to make sure you're getting the raw unmodified contents of the request payload and not some parsed value?

tranquil bone
#

This is the new and updated code. More of that, i cant do, because i dont understand whats going on ๐Ÿ˜„ This is my first time using Stripe

soft marten
#

I'm not sure I understand what you're trying to say. It looks like you have log lines to log out the contents of req.rawBody:

    console.log("๐Ÿ” Raw body content:", req.rawBody.toString("utf8"));```
tranquil bone
#

Give me a moment please

soft marten
#

:mag: Raw body type: object
that seems concerning, if it's the raw body I'd expect it to typically be a string or a buffer

tranquil bone
#

Hmm ok, give me a moment please

soft marten
#

Wait, are you actually using Express to host your endpoints? I don't see any app.post lines like I'd expect to if you were.

Instead it seems like you're using onRequest from some firebase library, does that sound right?

crimson pelicanBOT
tranquil bone
#

I dont know, yesterday because ive been so exhausted to try over and over again to fix the problem ,ive been using ChatGPT , but i think ill start it over from scratch.. All i want to do is to make the payments work ๐Ÿ˜„

wise jolt
#

You're definitely using the correct whsec_xxx secret, yes? I see you have multiple webhhook configured to point to the same URL

tranquil bone
#

Yes, should i delete the other ones ?

wise jolt
#

Up to you, just potentially confusing matters have multiple endpoints for one URL

tranquil bone
#

Done, just the important one left

wise jolt
#

You're running this on Firebase/Google Cloud yes? If so, req.rawBody should definitely be a Buffer so that's likely your issue looking at your logs. Can you remove this logs? They could malform the raw request body

console.log("๐Ÿ” Raw body content:", req.rawBody.toString("utf8"));```
tranquil bone
#

Sure, just a moment please. And yeah, im working with Firestore Database and Funtions

#

Deploying now

wise jolt
#

And your code is basically the same

wise jolt
tranquil bone
#

No no, im using only firebase function. Ive been trying something, sorry. This is the latest code

wise jolt
#

Remove this line too bodyParser.raw({ type: "application/json" })(req, res, async () => {

tranquil bone
#

Done, deploying

wise jolt
tranquil bone
#

Okay, give me few minutes, cause i reached the quota, need to wait 5 - 7 minutes

wise jolt
#

Yeah you need to setup a local env to test this

#

But generaly passing req.rawBody to constructEvent is enough. You don't need bodyParser and everything else for a Firebase function

tranquil bone
wise jolt
#

Let's try it

tranquil bone
wise jolt
tranquil bone
#

Its from "firebase functions:log"

wise jolt
#

Right but where is the console.log in the code that spits out :mag: Raw body type: object

You said you removed it, so how is it still in the logs?

#

Are you sure you're hitting the endpoint you're updating the code on?

tranquil bone
#

I'm in cmd, in the app directory, writing "firebase deploy --only functions", and then "firebase functions:log"

wise jolt
#

Yes, I understand how you access the logs. But in the code you sent me there is no console.log() that spits out that line

wise jolt
#

We're likely gonna wrap up this thread soon as this is not really a Stripe issue and we've been ongoing for 2 hours. You seem to be blindly deploying code without understanding the changes you're making, and they don't even seem to be taking effect

tranquil bone
#

I dont see that part in the code either..

wise jolt
#

Exactly, you're hitting the wrong endpoint/function when you're testing

tranquil bone
wise jolt
#

I don't really know enough about Firebase Functions to advise. As I said, I'd recommend looking at the example I shared or reading their docs

crimson pelicanBOT
tranquil bone
wise jolt
#

Then I would guess that your webhookSecret var is for a different endpoint

tranquil bone
#

Let me understand, what is that endpoint, and where can i find it ?

#

And in firebase

#

I have this

wise jolt
#

You want to secret from the corresponding we_xxx endpoint in your Dashboard

thin hemlock
#

Hey, taking over here. Let me know if there's any follow-up Qs I can answer!

tranquil bone