#AlphaRyze
1 messages · Page 1 of 1 (latest)
Are you using node?
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
but it just timeouts after 3 secs
Do you get the signature verification error?
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
@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
no worries
You'll have to roll them now though: https://stripe.com/docs/keys#rolling-keys
Ok. You'll probably need to increase the lambda timeout
oke i'm gonna try
Learn optional configuration tasks, such as increasing the memory allotted to your Lambda function, in both the Lambda console and CLI.