#CryptoBeaver
1 messages · Page 1 of 1 (latest)
Could you share the error you're facing?
Give me a minut i'll get teh error
next > TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument
This error is too generic. Could you share the full error message and your code?
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
Let's step back and start one by one.
Can you put a console log to print sig and share the output?
yes
t=1667788569,v1=1bf8afbe150edb0813c12be8947f5c4bb75c2294cd679f6e3ad1bb37dc884d84,v0=64ef4de43f7cada44c836d87c743515b169716a44c66362f11ac09af2157b2aa
👀
sorry i feel stupid this si a simple thing and i must be doign something little that is wrong
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?
If you copy the code here: https://stripe.com/docs/webhooks/quickstart
does it work?
stripe listen --forward-to https://domain/api/webhooks
forwarding is fine
let me try
that code uses express
i'll get back in a few, will test something
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?
it's ok i'm checking teh Express code make sure it reflect same as me
mine
and i will check teh secrets too
sure! let me know if you still encounter any issue
yeah i'll be able to test in 5 minutes
almost done
StripeSignatureVerificationError: No signatures found matching the expected signature for payload.
This is a better error message!
😉
i think i got it
i now changed back to the buffer
or close
i got a transaction declined i think
is your code able to go pass constructEvent function?
StripeSignatureVerificationError: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing
no same error
let me ttest
No signatures found matching the expected signature for payload usually due to:
- webhook secret is incorrect
- the request body is not in raw form, i.e. your framework might have parse the json for you that changes the raw form
webhook secret on local server and dashboard are different. every newly created webhook on dashboard also has different webhook secret
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
ah i see! if you create the object in live, then live secret key and webhook secret will work
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

woohoo! that's great! glad that it's working now
sure! what's your question?
i'm using payment links, are they sending the clients address and email in the post back?
web hooks
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.
ok perfect thank you so much!
No problem! Happy to help 😄
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
Hi @echo harbor I'm taking over. Let me know if you have a follow-up question
Hey Jack! question well not really question, just seem the payment intent create postback is after teh succeeded payment when i test.
Can you share with me the event IDs?
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?
You can listen to checkout.session.completed event, can check the associated payment_intent and see if its status=suceeded