#AlphaRyze

1 messages · Page 1 of 1 (latest)

woven phoenixBOT
gloomy lake
#

Are you using node?

abstract valley
#

yea

#

i have a lambda function that it's this:

import Stripe from 'stripe';
const crypto = require('crypto');

export const handler = async (event) => {
  
  const stripe = new Stripe("sk_test_51M58KgH2C2RzFFBjiFo8gTUPngmbR1S01fVislHLAFL9nru1pCvO5RIbu2Gy6UzfLl6a8qZ6IiTScMLZSuMOnJu300ndEfui1y");
  // Validate the webhook signature
  const sig = event.headers['stripe-signature'];
  const payload = event.body;
  const endpointSecret = "whsec_HTQdBGSWh0BGAeaWSEhrsrebQFwVmBum";
  
  const client = await JSON.stringify(stripe)
  
  return {
    statusCode: 220,
    body: client,
  }

  let stripeEvent;

  try {
    stripeEvent = stripe.webhooks.constructEvent(payload, sig, endpointSecret);
  } catch (err) {
    console.error(`Webhook Error: ${err.message}`);
    return {
      statusCode: 400,
      body: `Webhook Error: ${err.message}`,
    };
  }

  // Handle different event types
  switch (stripeEvent.type) {
    case 'checkout.session.completed':
      // Update the user profile in DynamoDB
      const session = stripeEvent.data.object;
      const stripeCustomerId = session.customer;
      const subscriptionId = session.subscription;
      const userId = session.metadata.userId;

      try {
        return { statusCode: 200, body: 'Success' };
      } catch (error) {
        console.error('Error updating user profile:', error);
        return { statusCode: 500, body: 'Error updating user profile' };
      }

  }
};
#

i've copy pasted the code in docs

gloomy lake
abstract valley
#

but it just timeouts after 3 secs

gloomy lake
#

Do you get the signature verification error?

abstract valley
#

no

#

i get the task timeout error

#

i sent my code

#

the private key for the webhook secret is this:

#

but somehow i get errors

gloomy lake
#

@abstract valley please remove your secret key from your code as it's now compromised

#

As well as the webhook secret

#

That's sensitive data so never share that publicly

abstract valley
#

i thought that via the thread no-one could've read

#

i'm dumb mb

gloomy lake
#

no worries

abstract valley
#

anyways i've just resetted them

#

idk why it doesn't work

gloomy lake
#

Ok. You'll probably need to increase the lambda timeout

abstract valley
#

oke i'm gonna try

gloomy lake