Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add purchase url #695

Merged
merged 3 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RAILS_LOG_LEVEL=INFO
RAILS_SERVE_STATIC_FILES=true
SECRET_KEY_BASE=test
APP_HOST=http://localhost:3001
PURCHASE_URL=https://standardnotes.com/purchase

EXTENSIONS_MANAGER_LOCATION=extensions/extensions-manager/dist/index.html
SF_DEFAULT_SERVER=http://localhost:3000
Expand Down
9 changes: 9 additions & 0 deletions app/assets/javascripts/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
'use strict';

declare global {
interface Window {
// eslint-disable-next-line camelcase
_bugsnag_api_key?: string;
// eslint-disable-next-line camelcase
_purchase_url?: string;
}
}

import { SNLog } from '@standardnotes/snjs';
import angular from 'angular';
import { configRoutes } from './routes';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ export const NoSubscription: FunctionalComponent<{
const errorMessage = 'There was an error when attempting to redirect you to the subscription page.';
setIsLoadingPurchaseFlow(true);
try {
const url = await application.getPurchaseFlowUrl();
if (url) {
const token = await application.getNewSubscriptionToken();
if (token) {
const currentUrl = window.location.href;
const successUrl = isDesktopApplication() ? `standardnotes://${currentUrl}` : currentUrl;
window.location.assign(`${url}&success_url=${successUrl}`);
const purchaseUrl = `${window._purchase_url}?subscription_token=${token}&success_url=${successUrl}`;
amanharwara marked this conversation as resolved.
Show resolved Hide resolved
window.location.assign(purchaseUrl);
} else {
setPurchaseFlowError(errorMessage);
}
Expand Down
7 changes: 0 additions & 7 deletions app/assets/javascripts/services/errorReporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ import Bugsnag from '@bugsnag/js';
import { WebCrypto } from '../crypto';
import { AppVersion } from '@/version';

declare global {
interface Window {
// eslint-disable-next-line camelcase
_bugsnag_api_key?: string;
}
}

function redactFilePath(line: string): string {
const fileName = line.match(/\w+\.(html|js)/)?.[0];
const redacted = '<redacted file path>';
Expand Down
1 change: 1 addition & 0 deletions app/views/application/app.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
window._bugsnag_api_key = "<%= ENV['BUGSNAG_API_KEY'] %>";
window._enable_unfinished_features = "<%= ENV['ENABLE_UNFINISHED_FEATURES'] %>" === 'true';
window._websocket_url = "<%= ENV['WEBSOCKET_URL'] %>";
window._purchase_url = "<%= ENV['PURCHASE_URL'] %>";
</script>

<% if Rails.env.development? %>
Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
data-bugsnag-api-key="<%= env.DEV_BUGSNAG_API_KEY %>"
data-enable-unfinished-features="<%= env.ENABLE_UNFINISHED_FEATURES %>"
data-web-socket-url="<%= env.DEV_WEBSOCKET_URL %>"
data-purchase-url="<%= env.PURCHASE_URL %>"
>
<script>
window._default_sync_server = document.body.dataset.defaultSyncServer || "https://api.standardnotes.com";
window._extensions_manager_location = document.body.dataset.extensionsManagerLocation || "public/extensions/extensions-manager/dist/index.html";
window._bugsnag_api_key = document.body.dataset.bugsnagApiKey;
window._enable_unfinished_features = document.body.dataset.enableUnfinishedFeatures === 'true';
window._websocket_url = document.body.dataset.webSocketUrl;
window._purchase_url = document.body.dataset.purchaseUrl;
</script>
<application-group-view />
</body>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@reach/listbox": "^0.16.1",
"@standardnotes/features": "1.7.2",
"@standardnotes/sncrypto-web": "1.5.2",
"@standardnotes/snjs": "2.15.2",
"@standardnotes/snjs": "2.16.0",
"mobx": "^6.3.2",
"mobx-react-lite": "^3.2.0",
"preact": "^10.5.12",
Expand Down