diff options
author | vantezzen <hello@vantezzen.io> | 2019-10-24 15:15:42 +0200 |
---|---|---|
committer | vantezzen <hello@vantezzen.io> | 2019-10-24 15:15:42 +0200 |
commit | 54f8b191a94bd78a85b046bbf21dd2245d3a6f3e (patch) | |
tree | ada5876f0e8a697ba4693bba07f5e0f31fea1fc9 /src/stores/PaymentStore.js | |
parent | Update submodules (diff) | |
parent | bump version to 5.4.0 (diff) | |
download | ferdium-app-54f8b191a94bd78a85b046bbf21dd2245d3a6f3e.tar.gz ferdium-app-54f8b191a94bd78a85b046bbf21dd2245d3a6f3e.tar.zst ferdium-app-54f8b191a94bd78a85b046bbf21dd2245d3a6f3e.zip |
Merge https://github.com/meetfranz/franz into franz-5.4.0-release
Diffstat (limited to 'src/stores/PaymentStore.js')
-rw-r--r-- | src/stores/PaymentStore.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/stores/PaymentStore.js b/src/stores/PaymentStore.js index 8579812ad..69e6eb9c3 100644 --- a/src/stores/PaymentStore.js +++ b/src/stores/PaymentStore.js | |||
@@ -1,9 +1,12 @@ | |||
1 | import { action, observable, computed } from 'mobx'; | 1 | import { action, observable, computed } from 'mobx'; |
2 | import { remote } from 'electron'; | ||
2 | 3 | ||
3 | import Store from './lib/Store'; | 4 | import Store from './lib/Store'; |
4 | import CachedRequest from './lib/CachedRequest'; | 5 | import CachedRequest from './lib/CachedRequest'; |
5 | import Request from './lib/Request'; | 6 | import Request from './lib/Request'; |
6 | 7 | ||
8 | const { BrowserWindow } = remote; | ||
9 | |||
7 | export default class PaymentStore extends Store { | 10 | export default class PaymentStore extends Store { |
8 | @observable plansRequest = new CachedRequest(this.api.payment, 'plans'); | 11 | @observable plansRequest = new CachedRequest(this.api.payment, 'plans'); |
9 | 12 | ||
@@ -13,6 +16,7 @@ export default class PaymentStore extends Store { | |||
13 | super(...args); | 16 | super(...args); |
14 | 17 | ||
15 | this.actions.payment.createHostedPage.listen(this._createHostedPage.bind(this)); | 18 | this.actions.payment.createHostedPage.listen(this._createHostedPage.bind(this)); |
19 | this.actions.payment.upgradeAccount.listen(this._upgradeAccount.bind(this)); | ||
16 | } | 20 | } |
17 | 21 | ||
18 | @computed get plan() { | 22 | @computed get plan() { |
@@ -27,4 +31,38 @@ export default class PaymentStore extends Store { | |||
27 | 31 | ||
28 | return request; | 32 | return request; |
29 | } | 33 | } |
34 | |||
35 | @action _upgradeAccount({ planId, onCloseWindow = () => null }) { | ||
36 | let hostedPageURL = this.stores.features.features.subscribeURL; | ||
37 | |||
38 | const parsedUrl = new URL(hostedPageURL); | ||
39 | const params = new URLSearchParams(parsedUrl.search.slice(1)); | ||
40 | |||
41 | params.set('plan', planId); | ||
42 | |||
43 | hostedPageURL = this.stores.user.getAuthURL(`${parsedUrl.origin}${parsedUrl.pathname}?${params.toString()}`); | ||
44 | |||
45 | const win = new BrowserWindow({ | ||
46 | parent: remote.getCurrentWindow(), | ||
47 | modal: true, | ||
48 | title: '🔒 Upgrade Your Franz Account', | ||
49 | width: 800, | ||
50 | height: window.innerHeight - 100, | ||
51 | maxWidth: 800, | ||
52 | minWidth: 600, | ||
53 | autoHideMenuBar: true, | ||
54 | webPreferences: { | ||
55 | nodeIntegration: true, | ||
56 | webviewTag: true, | ||
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 | } | ||
30 | } | 68 | } |