Skip to content

Commit

Permalink
Merge pull request #693 from ZenUml/feat/new-pricing-page
Browse files Browse the repository at this point in the history
feat: new pricing
  • Loading branch information
MrCoder authored May 19, 2024
2 parents faa4b88 + 5008f51 commit a144721
Show file tree
Hide file tree
Showing 20 changed files with 700 additions and 376 deletions.
9 changes: 9 additions & 0 deletions functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ Paddle---POST-Request-->Firebase

- `firebase -P prod functions:config:set larasite.host=sequence-diagram.zenuml.com`
- `firebase -P prod functions:config:set larasite.public_base_url=https://zenuml.com/sequence-diagram`

### Webhook

find the webhook : https://console.firebase.google.com/u/0/project/staging-zenuml-27954/functions

### Webhook Support paddle product ids

- `firebase -P staging functions:config:set paddle.product_ids=552378,882893,882890,882891`
- `firebase -P prod functions:config:set paddle.product_ids=879334,551167,879927,883078,883082`
4 changes: 2 additions & 2 deletions functions/alert_parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const alertParsers = {
subscription_created: (req) => ({
cancel_url: req.body.cancel_url,
cancel_url: req.body.cancel_url || '',
checkout_id: req.body.checkout_id,
currency: req.body.currency,
email: req.body.email,
Expand All @@ -13,7 +13,7 @@ const alertParsers = {
subscription_id: req.body.subscription_id,
subscription_plan_id: req.body.subscription_plan_id,
unit_price: req.body.unit_price,
update_url: req.body.update_url,
update_url: req.body.update_url || '',
}),
subscription_cancelled: (req) => ({
cancellation_effective_date: req.body.cancellation_effective_date,
Expand Down
35 changes: 33 additions & 2 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ exports.info = functions.https.onRequest((req, res) => {

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

const supportedProductIds = (functions.config().paddle.product_ids || '')
.split(',')
.filter(Boolean);
const checkSupportedProductIds = (productId) => {
return productId && supportedProductIds.includes(productId);
};

exports.supported_product_ids = functions.https.onRequest(async (req, res) => {
res.status(200).send(JSON.stringify(supportedProductIds));
});

exports.authenticate = functions.https.onRequest(async (req, res) => {
console.log('request:', req);
const auth = req.get('Authorization');
Expand Down Expand Up @@ -122,8 +133,13 @@ exports.webhook = functions.https.onRequest(async (req, res) => {
if (valid) {
if (alertParser.supports(req)) {
const subscription = alertParser.parse(req);
const userId = subscription.passthrough;

if (!checkSupportedProductIds(subscription.subscription_plan_id)) {
res.send(
`subscription_plan_id:${subscription.subscription_plan_id} not supported`,
);
return;
}
const userId = getUserIdFromPassthrough(subscription.passthrough);
const user = await db.collection('users').doc(userId).get();
if (user.exists) {
await db
Expand All @@ -145,3 +161,18 @@ exports.webhook = functions.https.onRequest(async (req, res) => {
res.send('Invaid request');
}
});

function getUserIdFromPassthrough(passthrough) {
return isJSONString(passthrough)
? JSON.parse(passthrough).userId
: passthrough;
}

function isJSONString(str) {
try {
JSON.parse(str);
return true;
} catch (e) {
return false;
}
}
2 changes: 1 addition & 1 deletion src/components/ContentWrap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ export default class ContentWrap extends Component {
onCSSActiviation() {
if (!window.user) {
this.props.onLogin();
} else if (userService.isPro()) {
} else if (userService.isPlusOrAdvanced()) {
return true;
} else {
this.props.onProFeature();
Expand Down
Loading

0 comments on commit a144721

Please sign in to comment.