aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/PaymentStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/PaymentStore.js')
-rw-r--r--src/stores/PaymentStore.js68
1 files changed, 0 insertions, 68 deletions
diff --git a/src/stores/PaymentStore.js b/src/stores/PaymentStore.js
deleted file mode 100644
index 05bb5b3d0..000000000
--- a/src/stores/PaymentStore.js
+++ /dev/null
@@ -1,68 +0,0 @@
1import { action, observable, computed } from 'mobx';
2import { BrowserWindow, getCurrentWindow } from '@electron/remote';
3
4import Store from './lib/Store';
5import CachedRequest from './lib/CachedRequest';
6import Request from './lib/Request';
7
8export default class PaymentStore extends Store {
9 @observable plansRequest = new CachedRequest(this.api.payment, 'plans');
10
11 @observable createHostedPageRequest = new Request(this.api.payment, 'getHostedPage');
12
13 constructor(...args) {
14 super(...args);
15
16 this.actions.payment.createHostedPage.listen(this._createHostedPage.bind(this));
17 this.actions.payment.upgradeAccount.listen(this._upgradeAccount.bind(this));
18 }
19
20 @computed get plan() {
21 if (this.plansRequest.isError) {
22 return {};
23 }
24 return this.plansRequest.execute().result || {};
25 }
26
27 @action _createHostedPage({ planId }) {
28 const request = this.createHostedPageRequest.execute(planId);
29
30 return request;
31 }
32
33 @action _upgradeAccount({ planId, onCloseWindow = () => null }) {
34 let hostedPageURL = this.stores.features.features.subscribeURL;
35
36 const parsedUrl = new URL(hostedPageURL);
37 const params = new URLSearchParams(parsedUrl.search.slice(1));
38
39 params.set('plan', planId);
40
41 hostedPageURL = this.stores.user.getAuthURL(`${parsedUrl.origin}${parsedUrl.pathname}?${params.toString()}`);
42
43 const win = new BrowserWindow({
44 parent: getCurrentWindow(),
45 modal: true,
46 title: '🔒 Upgrade Your Franz Account',
47 width: 800,
48 height: window.innerHeight - 100,
49 maxWidth: 800,
50 minWidth: 600,
51 autoHideMenuBar: true,
52 webPreferences: {
53 nodeIntegration: true,
54 webviewTag: true,
55 enableRemoteModule: true,
56 contextIsolation: false,
57 },
58 });
59 win.loadURL(`file://${__dirname}/../index.html#/payment/${encodeURIComponent(hostedPageURL)}`);
60
61 win.on('closed', () => {
62 this.stores.user.getUserInfoRequest.invalidate({ immediately: true });
63 this.stores.features.featuresRequest.invalidate({ immediately: true });
64
65 onCloseWindow();
66 });
67 }
68}