aboutsummaryrefslogtreecommitdiffstats
path: root/src/containers/subscription/SubscriptionFormScreen.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers/subscription/SubscriptionFormScreen.js')
-rw-r--r--src/containers/subscription/SubscriptionFormScreen.js83
1 files changed, 28 insertions, 55 deletions
diff --git a/src/containers/subscription/SubscriptionFormScreen.js b/src/containers/subscription/SubscriptionFormScreen.js
index 7486cc498..587889e7f 100644
--- a/src/containers/subscription/SubscriptionFormScreen.js
+++ b/src/containers/subscription/SubscriptionFormScreen.js
@@ -1,4 +1,3 @@
1import { remote } from 'electron';
2import React, { Component } from 'react'; 1import React, { Component } from 'react';
3import PropTypes from 'prop-types'; 2import PropTypes from 'prop-types';
4import { inject, observer } from 'mobx-react'; 3import { inject, observer } from 'mobx-react';
@@ -6,70 +5,31 @@ import { inject, observer } from 'mobx-react';
6import PaymentStore from '../../stores/PaymentStore'; 5import PaymentStore from '../../stores/PaymentStore';
7 6
8import SubscriptionForm from '../../components/subscription/SubscriptionForm'; 7import SubscriptionForm from '../../components/subscription/SubscriptionForm';
9 8import TrialForm from '../../components/subscription/TrialForm';
10const { BrowserWindow } = remote;
11 9
12export default @inject('stores', 'actions') @observer class SubscriptionFormScreen extends Component { 10export default @inject('stores', 'actions') @observer class SubscriptionFormScreen extends Component {
13 static propTypes = { 11 async openBrowser() {
14 onCloseWindow: PropTypes.func,
15 content: PropTypes.node,
16 showSkipOption: PropTypes.bool,
17 skipAction: PropTypes.func,
18 skipButtonLabel: PropTypes.string,
19 hideInfo: PropTypes.bool,
20 }
21
22 static defaultProps = {
23 onCloseWindow: () => null,
24 content: '',
25 showSkipOption: false,
26 skipAction: () => null,
27 skipButtonLabel: '',
28 hideInfo: false,
29 }
30
31 async handlePayment(plan) {
32 const { 12 const {
33 actions, 13 actions,
34 stores, 14 stores,
35 onCloseWindow,
36 } = this.props; 15 } = this.props;
37 16
38 const interval = plan; 17 const {
18 user,
19 features,
20 } = stores;
21
22 let hostedPageURL = user.data.hadSubscription ? features.features.planSelectionURL : features.features.subscribeURL;
23 const url = new URL(hostedPageURL);
24 const params = new URLSearchParams(url.search.slice(1));
39 25
40 const { id } = stores.payment.plan[interval]; 26 params.append('authToken', user.authToken);
41 actions.payment.createHostedPage({
42 planId: id,
43 });
44 27
45 const hostedPage = await stores.payment.createHostedPageRequest; 28 hostedPageURL = `${url.origin}${url.pathname}?${params.toString()}`;
46 29
47 if (hostedPage.url) { 30 actions.app.openExternalUrl({ url: hostedPageURL });
48 if (hostedPage.legacyCheckoutFlow) {
49 const paymentWindow = new BrowserWindow({
50 parent: remote.getCurrentWindow(),
51 modal: true,
52 title: '🔒 Franz Supporter License',
53 width: 600,
54 height: window.innerHeight - 100,
55 maxWidth: 600,
56 minWidth: 600,
57 webPreferences: {
58 nodeIntegration: true,
59 webviewTag: true,
60 },
61 });
62 paymentWindow.loadURL(`file://${__dirname}/../../index.html#/payment/${encodeURIComponent(hostedPage.url)}`);
63 31
64 paymentWindow.on('closed', () => { 32 console.log('hostedPage', hostedPageURL);
65 onCloseWindow();
66 });
67 } else {
68 actions.app.openExternalUrl({
69 url: hostedPage.url,
70 });
71 }
72 }
73 } 33 }
74 34
75 render() { 35 render() {
@@ -77,8 +37,21 @@ export default @inject('stores', 'actions') @observer class SubscriptionFormScre
77 actions, 37 actions,
78 stores, 38 stores,
79 } = this.props; 39 } = this.props;
40
41 const { data: user } = stores.user;
42
43 if (user.hadSubscription) {
44 return (
45 <SubscriptionForm
46 plan={stores.payment.plan}
47 selectPlan={() => this.openBrowser()}
48 isActivatingTrial={stores.user.activateTrialRequest.isExecuting || stores.user.getUserInfoRequest.isExecuting}
49 />
50 );
51 }
52
80 return ( 53 return (
81 <SubscriptionForm 54 <TrialForm
82 plan={stores.payment.plan} 55 plan={stores.payment.plan}
83 activateTrial={() => actions.user.activateTrial({ planId: stores.features.features.defaultTrialPlan })} 56 activateTrial={() => actions.user.activateTrial({ planId: stores.features.features.defaultTrialPlan })}
84 isActivatingTrial={stores.user.activateTrialRequest.isExecuting || stores.user.getUserInfoRequest.isExecuting} 57 isActivatingTrial={stores.user.activateTrialRequest.isExecuting || stores.user.getUserInfoRequest.isExecuting}