Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

using querystring for Paddle

Blue Mousebcc4ef0eb5f9
diff --git a/package.json b/package.json
index f94338f64..d4da09ce9 100644
--- a/package.json
+++ b/package.json
@@ -52,6 +52,7 @@
"nodemailer": "^6.7.2",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
+ "querystring": "^0.2.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.5.1",
diff --git a/src/main.ts b/src/main.ts
index 896393f62..9a4090440 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,6 +1,5 @@
import { NestFactory } from '@nestjs/core'
import { ValidationPipe } from '@nestjs/common'
-import * as express from 'express'
import * as cookieParser from 'cookie-parser'
import * as bodyParser from 'body-parser'
@@ -32,7 +31,6 @@ async function bootstrap() {
})
app.use('/webhook', bodyParser.raw({ type: 'application/json' }))
- app.use('/webhook/paddle', express.urlencoded())
await app.listen(5005)
}
bootstrap()
diff --git a/src/webhook/webhook.controller.ts b/src/webhook/webhook.controller.ts
index a9b7e7e88..4261d0baa 100644
--- a/src/webhook/webhook.controller.ts
+++ b/src/webhook/webhook.controller.ts
@@ -1,6 +1,7 @@
import {
Controller, Body, Post, Headers, BadRequestException, NotFoundException, UseGuards, Ip,
} from '@nestjs/common'
+import * as querystring from 'querystring'
import { ApiTags } from '@nestjs/swagger'
import * as _isEmpty from 'lodash/isEmpty'
import * as _keys from 'lodash/keys'
@@ -134,9 +135,12 @@ export class WebhookController {
@Post('/paddle')
async paddleWebhook(@Body() body, @Headers() headers, @Ip() reqIP): Promise<any> {
const ip = headers['cf-connecting-ip'] || headers['x-forwarded-for'] || reqIP || ''
+ const webhookData = querystring.parse(body)
+ console.log(webhookData)
- if (verifyPaddleWebhook(PADDLE_PUB_KEY, body)) {
- console.log(body, headers, ip)
+ if (verifyPaddleWebhook(PADDLE_PUB_KEY, webhookData)) {
+ console.log(headers, ip)
+ return
}
this.logger.error('Webhook signature verification failed.')