#CryptoBeaver

1 messages · Page 1 of 1 (latest)

opal peakBOT
final ginkgo
#

Could you share the error you're facing?

echo harbor
#

Give me a minut i'll get teh error

#

next > TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument

final ginkgo
#

This error is too generic. Could you share the full error message and your code?

echo harbor
#

seems it's teh req.headers['stripe-signature']

#

i'm running nextjs

#

`import initStripe from "stripe";
import { buffer } from "micro";

export const config = { api: { bodyParser: false } };

const handler = async (req, res) => {
const sig = req.headers['stripe-signature'];
const stripe = initStripe(process.env.STRIPE_SECRET_KEY);
const signingSecret = process.env.STRIPE_SIGNING_SECRET;
const reqBuffer = await buffer(req);

let event;

try {
event = stripe.webhooks.constructEvent(reqBuffer, sig, signingSecret);
} catch (error) {
console.log(error);
return res.status(400).send(Webhook error: ${error.message});
}

console.log("event!");

res.send({ received: true });
};

export default handler;`

#

i'm setting the webhooks link again and putting the keys

#

i get his error
next > StripeSignatureVerificationError: │ │ ││ next > at parseEventDetails (/home/ec2-u │ │ ││ next > at Object.verifyHeader (/home/ec2 │ │ ││ next > at Object.constructEvent │ │ ││ next > at handler (/home/ec2-user/headsh │ │ ││ next > at processTicksAndRejections │ │ ││ next > at async Object.apiResolver │ │ ││ next > at async NextNodeServer.runApi │ │ ││ next > at async Object.fn (/home/ec2-use │ │ ││ next > at async Router.execute │ │ ││ next > at async NextNodeServer.run │ │ ││ next > type: 'StripeSignatureVerificationE │ │ ││ next > raw: { │ │ ││ next > message: 'Unable to extract │ │ ││ next > detail: { decodedHeader: │ │ ││ next > }, │ │ ││ next > rawType: undefined, │ │ ││ next > code: undefined, │ │ ││ next > doc_url: undefined, │ │ ││ next > param: undefined, │ │ ││ next > detail: { decodedHeader: undefined, │ │ ││ next > headers: undefined, │ │ ││ next > requestId: undefined, │ │ ││ next > statusCode: undefined, │ │ ││ next > charge: undefined, │ │ ││ next > decline_code: undefined, │ │ ││ next > payment_intent: undefined, │ │ ││ next > payment_method: undefined, │ │ ││ next > payment_method_type: undefined, │ │ ││ next > setup_intent: undefined, │ │ ││ next > source: undefined │ │ ││ next > }

#

this should be pretty simple to dodon't know why i'm getting such a problem getting this working

final ginkgo
#

Let's step back and start one by one.

Can you put a console log to print sig and share the output?

echo harbor
#

yes

#

t=1667788569,v1=1bf8afbe150edb0813c12be8947f5c4bb75c2294cd679f6e3ad1bb37dc884d84,v0=64ef4de43f7cada44c836d87c743515b169716a44c66362f11ac09af2157b2aa

final ginkgo
#

okay! signature is correct

#

let's move on to the next one

echo harbor
#

👀

#

sorry i feel stupid this si a simple thing and i must be doign something little that is wrong

final ginkgo
#

can you put req.body into constructEvent instead of using reqBuffer?

req.body is the request body alone whereas req contains other information like headers.

#

does it work or give you different error message that's not StripeSignatureVerificationError?

echo harbor
#

STILL SAME

#

oups cap

#

what else could be doing this, could it be my sstripe cli?

final ginkgo
echo harbor
final ginkgo
#

forwarding is fine

echo harbor
#

that code uses express

#

i'll get back in a few, will test something

final ginkgo
#

sorry, i forgot that you're using Next. can you also double check if your secret key (sk_xxx) and webhook secret (whsec_xxx) is correct?

echo harbor
#

it's ok i'm checking teh Express code make sure it reflect same as me

#

mine

#

and i will check teh secrets too

final ginkgo
#

sure! let me know if you still encounter any issue

echo harbor
#

yeah i'll be able to test in 5 minutes

#

almost done

#

StripeSignatureVerificationError: No signatures found matching the expected signature for payload.

final ginkgo
#

This is a better error message!

echo harbor
#

😉

#

i think i got it

#

i now changed back to the buffer

#

or close

#

i got a transaction declined i think

final ginkgo
#

is your code able to go pass constructEvent function?

echo harbor
#

no same error

final ginkgo
#

No signatures found matching the expected signature for payload usually due to:

  1. webhook secret is incorrect
  2. the request body is not in raw form, i.e. your framework might have parse the json for you that changes the raw form
echo harbor
#

i removed all my webhooks url and restarted

#

fresh on the dashboard

#

lol

final ginkgo
#

webhook secret on local server and dashboard are different. every newly created webhook on dashboard also has different webhook secret

echo harbor
#

yes

#

i'm runnign the test live server

#

ok i think it's getting to my api now, just trying to output teh data

#

omg i got it to work 😄

#

so the stripe cli --listen and forward

#

i think i had that misconfigured, then running live i got it to work

#

So i think it's my fault i haven't grasp the setup properly for the cli running local and that

final ginkgo
#

ah i see! if you create the object in live, then live secret key and webhook secret will work

echo harbor
#

yes ii understand now

#

i had a 15 hour day yesterday and that was at teh end so maybe i wasn't awake enough haah

#

i got local to work too

#

omg

final ginkgo
#

woohoo! that's great! glad that it's working now

echo harbor
#

cani ask another question

#

before you leave 😄

final ginkgo
#

sure! what's your question?

echo harbor
#

i'm using payment links, are they sending the clients address and email in the post back?

#

web hooks

final ginkgo
#

If the information is collected, then it will be included in webhook event.

By default, email address is collected whereas billing address is only collected when it's necessary.

echo harbor
#

ok perfect thank you so much!

final ginkgo
#

No problem! Happy to help 😄

echo harbor
#

i just see in my test, that i receive a webhook of payment_intent.succeeded before my payment_intent.created in my testing pay link lol

halcyon whale
#

Hi @echo harbor I'm taking over. Let me know if you have a follow-up question

echo harbor
#

Hey Jack! question well not really question, just seem the payment intent create postback is after teh succeeded payment when i test.

halcyon whale
#

Can you share with me the event IDs?

echo harbor
#

Sorry was taking a break

#

it's ok for now the order, it's not an issue, but i have a question

#

once someone pays on a payment links, i can get it to return a {CHECKOUT_SESSION_ID} but in whic event on the webhooks i can confirm the session_id and match it to a confirmed payment?

halcyon whale
#

You can listen to checkout.session.completed event, can check the associated payment_intent and see if its status=suceeded

echo harbor
#

great!

#

thanks