#jannik-webhook-signature
1 messages ยท Page 1 of 1 (latest)
Hello! Is this something you're seeing with all your webhook events, or just a few?
hi
i only have one
const webhookSecret = this.configService.get('STRIPE_WEBHOOK_SECRET');
console.log('WEBHOOK SECRET', webhookSecret);
console.log(payload);``` this payload is empty
i give you some context
@Post('webhooks/stripe')
async handleIncomingEvents(
@Headers('stripe-signature') signature: string,
@Req() request: RequestWithRawBody,
) {
if (!signature) {
console.log('Missing stripe-signature header');
throw new BadRequestException('Missing stripe-signature header');
}
const event = await this.stripeService.constructEventFromPayload(
signature,
request.rawBody,
);
console.log(event);
return { received: true };
// ...
}```
bootstrap fn to stat backend ```async function bootstrap() {
const logger = new Logger();
const app = await NestFactory.create(AppModule);
app.use(rawBodyMiddleware());
//app.use(helmet());
app.enableCors({
origin: '*',
});
//app.useGlobalPipes(new ValidationPipe());
const config = new DocumentBuilder()
.setTitle('GH Heroes')
.setDescription('The Uploader Service Api Description')
.setVersion('1.0')
.addTag('uploads')
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
const PORT = process.env.PORT || 8080;
await app.listen(PORT, () => {
logger.log(Server is running on port ${PORT});
});
}
bootstrap();```
middleware ```import { Response } from 'express';
import { json } from 'body-parser';
export interface RequestWithRawBody extends Request {
rawBody: Buffer;
}
function rawBodyMiddleware() {
return json({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
verify: (
request: RequestWithRawBody,
response: Response,
buffer: Buffer,
) => {
if (request.url === '/webhook' && Buffer.isBuffer(buffer)) {
request.rawBody = Buffer.from(buffer);
}
return true;
},
});
}
export default rawBodyMiddleware;
Have you logged the request.rawBody to verify it's correct?
Fixed!!
๐
id: 'evt_3O5Wx1BxbqzVV8bq1rlrv7d2',
object: 'event',
api_version: '2022-11-15',
created: 1698339751,
data: {
object: {
id: 'pi_3O5Wx1BxbqzVV8bq1qf7tqEh',
object: 'payment_intent',
amount: 4999,
amount_capturable: 0,
amount_details: [Object],
amount_received: 0,
application: null,
application_fee_amount: null,
automatic_payment_methods: null,
canceled_at: null,
cancellation_reason: null,
capture_method: 'automatic',
client_secret: 'pi_3O5Wx1BxbqzVV8bq1qf7tqEh_secret_lTiNRGNkljs6jOiS4dtteu4sN',
confirmation_method: 'automatic',
created: 1698339751,
currency: 'usd',
customer: null,
description: null,
invoice: null,
last_payment_error: null,
latest_charge: null,
livemode: false,
metadata: [Object],
next_action: null,
on_behalf_of: null,
payment_method: null,
payment_method_configuration_details: null,
payment_method_options: [Object],
payment_method_types: [Array],
processing: null,
receipt_email: null,
review: null,
setup_future_usage: null,
shipping: null,
source: null,
statement_descriptor: null,
statement_descriptor_suffix: null,
status: 'requires_payment_method',
transfer_data: null,
transfer_group: null
}
},
livemode: false,
pending_webhooks: 2,
request: {
id: 'req_R8XClShwJxi4h9',
idempotency_key: 'ec7e5088-2ddf-4d3f-8a81-2ff4072b515e'
},
type: 'payment_intent.created'
}```
but where is my additional data?
``` payment_intent_data: {
metadata: {
userId: user.id,
skulls: blackMarketOption.skulls,
price: PRICE_IN_USD,
},
},```
got all data
thank you so much!
glad you got it working ๐