#shakil-signature-verification
1 messages ยท Page 1 of 1 (latest)
Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- shakilkhan496, 2 hours ago, 59 messages
- shakilkhan496, 5 hours ago, 6 messages
Hi, how can I help?
I need to help with webhook setup on deno
Error message: Webhook payload must be provided as a string or a Buffer (https://nodejs.org/api/buffer.html) instance representing the raw request body.Payload was provided as a parsed JavaScript object instead.
Signature verification is impossible without access to the original signed material.
Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing
This is the error message I got
I have followed the stripe docs
Here is my code "router.post('/webhookMain', async (context) => {
try {
const signature = context.request.headers?.get('Stripe-Signature') || '';
const signInSecret = 'whsec_mNEmSD5aLWwqB3GsYjwj2lWtZG1eCvlj';
// Use context.request.body().value to get the raw body
const rawBody = await context.request.body().value;
let event;
try {
event = await stripe.webhooks.constructEventAsync(
rawBody,
signature,
signInSecret,
undefined
);
} catch (err) {
console.log(`โ Error message: ${err.message}`);
return new Response(err.message, { status: 400 });
}
// Successfully constructed event
console.log('โ
Success:', event.id);
// Process the event based on its type
if (event.type === 'payment_intent.succeeded') {
const stripeObject = event.data.object;
console.log(`๐ฐ PaymentIntent status: ${stripeObject.status}`);
} else if (event.type === 'charge.succeeded') {
const charge = event.data.object;
console.log(`๐ต Charge id: ${charge.id}`);
} else {
console.warn(`๐คทโโ๏ธ Unhandled event type: ${event.type}`);
}
return new Response(JSON.stringify({ received: true }), { status: 200 });
} catch (error) {
console.error('Error:', error);
return new Response('Internal Server Error', { status: 500 });
}
});"
Are you parsing the request body?
You can check my code
Also, please delete your webhook secret, it's a public forum.
Okay that is test no problem
This is in test mode
Kindly help me to integrate webhook on deno please
You only shared the code of the webhook handler. Do you use anything to parse the request body for your whole app?
No
I am new on deno
Regerding that error , How can we fix this ?
If possible you can provide me code sample
I don't know much about Deno and we only have an official SDK for Node.js.
I won't be able to help you if you don't share more information with me.
Can you please print the request body and see what type it is.
Yes but I have followed : https://www.youtube.com/watch?v=pA1YD4adP9I
Part two of how to handle webhooks using stripe-node in a Deno application. We recommend starting with the part one (https://youtu.be/epCHqHEdz8I).
In this episode, CJ walks you through handling webhooks using stripe-node in a Deno application.
Presenter
CJ Avilla - Developer Advocate at Stripe - https://twitter.com/cjav_dev
Tab...
I got this error while trigering webhook
I understand that. I am asking you to print the request body.
๐ taking over as vanya needs to step away
I don't think you're printing the request body correctly.
You should either see a string or a buffer when printing the request body
I am trying
This is the code part " // Use context.request.body().value to get the raw body
const rawBody = await context.request.body().value;
console.log('Request body: ', rawBody)"
rawBody variable seems to resolve as a function though, not a String or buffer value
Request body: {
id: "evt_3OX2RTJRdeoMFQJ22ZULZ4s2",
object: "event",
api_version: "2023-08-16",
created: 1704895659,
data: {
object: {
id: "pi_3OX2RTJRdeoMFQJ225YEvRAy",
object: "payment_intent",
amount: 10000,
amount_capturable: 0,
amount_details: { tip: {} },
amount_received: 0,
application: null,
application_fee_amount: null,
automatic_payment_methods: { allow_redirects: "always", enabled: true },
canceled_at: null,
cancellation_reason: null,
capture_method: "automatic",
client_secret: "pi_3OX2RTJRdeoMFQJ225YEvRAy_secret_USD5bQiqhBwdzcJHzE5HW2lZh",
confirmation_method: "automatic",
created: 1704895659,
currency: "gbp",
customer: null,
description: null,
invoice: null,
last_payment_error: null,
latest_charge: null,
livemode: false,
metadata: { connectedAccountId: "acct_1OWyUiQoTh4gMc3V" },
next_action: null,
on_behalf_of: null,
payment_method: null,
payment_method_configuration_details: { id: "pmc_1OWmlLJRdeoMFQJ2uSySYDb1", parent: null },
payment_method_options: {
card: {
installments: null,
mandate_options: null,
network: null,
request_three_d_secure: "automatic"
},
link: { persistent_token: null }
},
payment_method_types: [ "card", "link" ],
processing: null,
receipt_email: null,
review: null,
setup_future_usage: null,
shipping: null,
source: null,
statement_descriptor: null,
sta
this is the console.log of rawBody
that's clearly json then yeah?
So something in your code is parsing the incoming request to JSON
The SDK expects untouched raw request body
Okay