Skip to content

Commit a144721

Browse files
authored
Merge pull request #693 from ZenUml/feat/new-pricing-page
feat: new pricing
2 parents faa4b88 + 5008f51 commit a144721

File tree

20 files changed

+700
-376
lines changed

20 files changed

+700
-376
lines changed

functions/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ Paddle---POST-Request-->Firebase
2222

2323
- `firebase -P prod functions:config:set larasite.host=sequence-diagram.zenuml.com`
2424
- `firebase -P prod functions:config:set larasite.public_base_url=https://zenuml.com/sequence-diagram`
25+
26+
### Webhook
27+
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/alert_parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const alertParsers = {
22
subscription_created: (req) => ({
3-
cancel_url: req.body.cancel_url,
3+
cancel_url: req.body.cancel_url || '',
44
checkout_id: req.body.checkout_id,
55
currency: req.body.currency,
66
email: req.body.email,
@@ -13,7 +13,7 @@ const alertParsers = {
1313
subscription_id: req.body.subscription_id,
1414
subscription_plan_id: req.body.subscription_plan_id,
1515
unit_price: req.body.unit_price,
16-
update_url: req.body.update_url,
16+
update_url: req.body.update_url || '',
1717
}),
1818
subscription_cancelled: (req) => ({
1919
cancellation_effective_date: req.body.cancellation_effective_date,

functions/index.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ exports.info = functions.https.onRequest((req, res) => {
1919

2020
const verifyIdToken = (token) => admin.auth().verifyIdToken(token);
2121

22+
const supportedProductIds = (functions.config().paddle.product_ids || '')
23+
.split(',')
24+
.filter(Boolean);
25+
const checkSupportedProductIds = (productId) => {
26+
return productId && supportedProductIds.includes(productId);
27+
};
28+
29+
exports.supported_product_ids = functions.https.onRequest(async (req, res) => {
30+
res.status(200).send(JSON.stringify(supportedProductIds));
31+
});
32+
2233
exports.authenticate = functions.https.onRequest(async (req, res) => {
2334
console.log('request:', req);
2435
const auth = req.get('Authorization');
@@ -122,8 +133,13 @@ exports.webhook = functions.https.onRequest(async (req, res) => {
122133
if (valid) {
123134
if (alertParser.supports(req)) {
124135
const subscription = alertParser.parse(req);
125-
const userId = subscription.passthrough;
126-
136+
if (!checkSupportedProductIds(subscription.subscription_plan_id)) {
137+
res.send(
138+
`subscription_plan_id:${subscription.subscription_plan_id} not supported`,
139+
);
140+
return;
141+
}
142+
const userId = getUserIdFromPassthrough(subscription.passthrough);
127143
const user = await db.collection('users').doc(userId).get();
128144
if (user.exists) {
129145
await db
@@ -145,3 +161,18 @@ exports.webhook = functions.https.onRequest(async (req, res) => {
145161
res.send('Invaid request');
146162
}
147163
});
164+
165+
function getUserIdFromPassthrough(passthrough) {
166+
return isJSONString(passthrough)
167+
? JSON.parse(passthrough).userId
168+
: passthrough;
169+
}
170+
171+
function isJSONString(str) {
172+
try {
173+
JSON.parse(str);
174+
return true;
175+
} catch (e) {
176+
return false;
177+
}
178+
}

src/components/ContentWrap.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ export default class ContentWrap extends Component {
804804
onCSSActiviation() {
805805
if (!window.user) {
806806
this.props.onLogin();
807-
} else if (userService.isPro()) {
807+
} else if (userService.isPlusOrAdvanced()) {
808808
return true;
809809
} else {
810810
this.props.onProFeature();

0 commit comments

Comments
 (0)