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!

added test paddle

Blue Mousee45fee80af34
diff --git a/package.json b/package.json
index a9f2adf81..f94338f64 100644
--- a/package.json
+++ b/package.json
@@ -58,7 +58,8 @@
"stripe": "^8.195.0",
"typeorm": "^0.2.41",
"ua-parser-js": "^0.7.31",
- "uuid": "^8.3.2"
+ "uuid": "^8.3.2",
+ "verify-paddle-webhook": "^1.1.0"
},
"devDependencies": {
"@nestjs/cli": "^7.6.0",
diff --git a/src/webhook/webhook.controller.ts b/src/webhook/webhook.controller.ts
index 9a69cf6a3..a9b7e7e88 100644
--- a/src/webhook/webhook.controller.ts
+++ b/src/webhook/webhook.controller.ts
@@ -1,10 +1,11 @@
import {
- Controller, Body, Post, Headers, BadRequestException, NotFoundException, UseGuards,
+ Controller, Body, Post, Headers, BadRequestException, NotFoundException, UseGuards, Ip,
} from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import * as _isEmpty from 'lodash/isEmpty'
import * as _keys from 'lodash/keys'
import * as _find from 'lodash/find'
+import { verifyPaddleWebhook } from 'verify-paddle-webhook'
import {
PlanCode, ACCOUNT_PLANS,
@@ -18,6 +19,32 @@ const stripe = require('stripe')(STRIPE_SECRET)
const PLANS_LIST = _keys(ACCOUNT_PLANS)
+const paddleWhitelistIPs = [
+ // Production IPs
+ '34.232.58.13',
+ '34.195.105.136',
+ '34.237.3.244',
+ // Sandbox IPs
+ '34.194.127.46',
+ '54.234.237.108',
+ '3.208.120.145',
+]
+
+const PADDLE_PUB_KEY = ` -----BEGIN PUBLIC KEY-----
+MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqFcHslKkXcJlTYg4FL6j
+XIKu0jM8PUMHRNbseLVqXS81DX7C5rZbacs6mU9MpyZv0QEXjiyZ9zXbQH5200Nx
+7Jv/e5ZdXwIZc6jIMSdxY5Oxuw3ZSRZnHxZp3CD56QfbtnzKsvgRYKMfwdiYE9iC
+7glB5Q++GHmfvgGKHqQtXaSpgYIREMO3XMYTBX2lqkdUZKnFFGEsL1ZgCiPGZjw8
+DLVNrDAfDsPBy/hubZnrs3wFuP4ZywDG7vNU5nLCOt7nx5IiCBvlOcFpfYxpyV7+
+OXLlANuYY6fM1PNjnAt6Eo8R+2bZcB9Xn2JusiS7NQavVbSHsvuZsI+6Q2T3dEr7
+TAqkc4JDL/AjZcbJW2EGU9RakZ0lgj5aAwAMxn/s1mQ6s+UCe9S8fJnsbu07tRY8
+oTrbUhdemtk1I+n2OWYJttsL2wLf8ppiJ3cer2h/3KB5JhSRbsjhz5sqYNe9D6j/
+mx7yrcfyeObxKGhLoGiwcTwmeK1OnCQSgrCkEBjtCTqlqiYvBfXO4vuqBRmpCgZC
+0p7cqvGNvtO+OupqNImTb0sNVk8oeVBpqsQzlI5lN2FdA5FRUYtgodT09rPFleX+
+PFP+Wo9wV4n1J8KYm8nfpOiSCrPKT9XktsWhAneg6Obzy+LdDM3m2w2/pk+Ja4AO
+ThpjdAzyWEhdnTyWWbxeoxsCAwEAAQ==
+-----END PUBLIC KEY-----`
+
@ApiTags('Webhook')
@Controller('webhook')
export class WebhookController {
@@ -102,4 +129,18 @@ export class WebhookController {
}
return
}
+
+ @UseGuards(SelfhostedGuard)
+ @Post('/paddle')
+ async paddleWebhook(@Body() body, @Headers() headers, @Ip() reqIP): Promise<any> {
+ const ip = headers['cf-connecting-ip'] || headers['x-forwarded-for'] || reqIP || ''
+
+ if (verifyPaddleWebhook(PADDLE_PUB_KEY, body)) {
+ console.log(body, headers, ip)
+ }
+
+ this.logger.error('Webhook signature verification failed.')
+ this.logger.error('Check the .env file and enter the correct webhook secret.')
+ throw new BadRequestException('Webhook signature verification failed')
+ }
}