Skip to content

Commit 141505c

Browse files
feat: check paddle supported product ids in function webhook
1 parent 85aefe2 commit 141505c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

functions/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ Paddle---POST-Request-->Firebase
2525

2626
### Webhook
2727

28-
https://console.firebase.google.com/u/0/project/staging-zenuml-27954/functions
28+
find the webhook : https://console.firebase.google.com/u/0/project/staging-zenuml-27954/functions
29+
30+
### Webhook Support paddle product ids
31+
32+
- `firebase -P staging functions:config:set paddle.product_ids=552378,882893,882890,882891`
33+
- `firebase -P prod functions:config:set paddle.product_ids=879334,551167,879927,883078,883082`

functions/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ exports.sync_diagram = functions.https.onRequest(async (req, res) => {
4848
console.log('using LaraSite URL:', baseUrlHttps);
4949
console.log('using publicBaseUrl:', publicBaseUrl);
5050

51+
const supportedProductIds = (functions.config().paddle.product_ids || '')
52+
.split(',')
53+
.filter(Boolean);
54+
const checkSupportedProductIds = (productId) =>
55+
Boolean(productId && supportedProductIds.includes(productId));
56+
57+
exports.supportedProductIds = functions.https.onRequest(async (req, res) => {
58+
res.status(200).send(JSON.stringify(supportedProductIds));
59+
});
60+
5161
const replaceBaseUrlInShareLink = (responseData) => {
5262
const data = JSON.parse(responseData);
5363
data.page_share = data.page_share
@@ -122,6 +132,12 @@ exports.webhook = functions.https.onRequest(async (req, res) => {
122132
if (valid) {
123133
if (alertParser.supports(req)) {
124134
const subscription = alertParser.parse(req);
135+
if (!checkSupportedProductIds(subscription.subscription_plan_id)) {
136+
res.send(
137+
`subscription_plan_id:${subscription.subscription_plan_id} not supported`,
138+
);
139+
return;
140+
}
125141
const userId = getUserIdFromPassthrough(subscription.passthrough);
126142
const user = await db.collection('users').doc(userId).get();
127143
if (user.exists) {

0 commit comments

Comments
 (0)