#shakil-signature-verification

1 messages ยท Page 1 of 1 (latest)

dusty scarabBOT
#

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.

blazing peak
#

That problem is solved

#

I need to solve new problem

signal thistle
#

Hi, how can I help?

blazing peak
#

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

GitHub

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

#

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 });
}

});"

signal thistle
#

Are you parsing the request body?

blazing peak
#

You can check my code

signal thistle
#

Also, please delete your webhook secret, it's a public forum.

blazing peak
#

Okay that is test no problem

#

This is in test mode

#

Kindly help me to integrate webhook on deno please

signal thistle
#

You only shared the code of the webhook handler. Do you use anything to parse the request body for your whole app?

blazing peak
#

No

#

I am new on deno

#

Regerding that error , How can we fix this ?

#

If possible you can provide me code sample

signal thistle
#

I don't know much about Deno and we only have an official SDK for Node.js.

dusty scarabBOT
signal thistle
#

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.

blazing peak
#

I got this error while trigering webhook

signal thistle
#

I understand that. I am asking you to print the request body.

blazing peak
#

Just 1min

#

[Function: body]

#

this was value

hardy cove
#

๐Ÿ‘‹ 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

blazing peak
#

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)"
hardy cove
#

rawBody variable seems to resolve as a function though, not a String or buffer value

blazing peak
#

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

hardy cove
#

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

blazing peak
#

Okay