feat: add purchase url (#695)
* feat: add purchase url * chore: bump snjs * fix: reuse existing function
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -3,7 +3,7 @@ import { LinkButton, Text } from '@/preferences/components';
|
||||
import { Button } from '@/components/Button';
|
||||
import { WebApplication } from "@/ui_models/application";
|
||||
import { useState } from "preact/hooks";
|
||||
import { isDesktopApplication } from "@/utils";
|
||||
import { loadPurchaseFlowUrl } from "@/purchaseFlow/PurchaseFlowWrapper";
|
||||
|
||||
export const NoSubscription: FunctionalComponent<{
|
||||
application: WebApplication;
|
||||
@@ -15,12 +15,7 @@ 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 currentUrl = window.location.href;
|
||||
const successUrl = isDesktopApplication() ? `standardnotes://${currentUrl}` : currentUrl;
|
||||
window.location.assign(`${url}&success_url=${successUrl}`);
|
||||
} else {
|
||||
if (!await loadPurchaseFlowUrl(application)) {
|
||||
setPurchaseFlowError(errorMessage);
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -10,17 +10,25 @@ export type PurchaseFlowWrapperProps = {
|
||||
application: WebApplication;
|
||||
};
|
||||
|
||||
export const getPurchaseFlowUrl = async (application: WebApplication): Promise<string | undefined> => {
|
||||
const token = await application.getNewSubscriptionToken();
|
||||
if (token) {
|
||||
const currentUrl = window.location.href;
|
||||
const successUrl = isDesktopApplication() ? `standardnotes://${currentUrl}` : currentUrl;
|
||||
return `${window._purchase_url}?subscription_token=${token}&success_url=${successUrl}`;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const loadPurchaseFlowUrl = async (
|
||||
application: WebApplication
|
||||
): Promise<void> => {
|
||||
const url = await application.getPurchaseFlowUrl();
|
||||
): Promise<boolean> => {
|
||||
const url = await getPurchaseFlowUrl(application);
|
||||
if (url) {
|
||||
const currentUrl = window.location.href.split('/?')[0];
|
||||
const successUrl = isDesktopApplication()
|
||||
? `standardnotes://${currentUrl}`
|
||||
: currentUrl;
|
||||
window.location.assign(`${url}&success_url=${successUrl}`);
|
||||
window.location.assign(url);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
export const PurchaseFlowWrapper: FunctionComponent<PurchaseFlowWrapperProps> =
|
||||
|
||||
@@ -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>';
|
||||
|
||||
Reference in New Issue
Block a user