diff options
author | 2019-08-19 12:11:38 +0200 | |
---|---|---|
committer | 2019-08-19 12:11:38 +0200 | |
commit | 478b5fc6574765072eafd4fa074ae832e67627bf (patch) | |
tree | 07dba02a6746685b00106ae2f37b529573876852 /src/containers | |
parent | remove monthly & yearly names (diff) | |
download | ferdium-app-478b5fc6574765072eafd4fa074ae832e67627bf.tar.gz ferdium-app-478b5fc6574765072eafd4fa074ae832e67627bf.tar.zst ferdium-app-478b5fc6574765072eafd4fa074ae832e67627bf.zip |
Add trial / subscription handling
Diffstat (limited to 'src/containers')
-rw-r--r-- | src/containers/subscription/SubscriptionFormScreen.js | 83 | ||||
-rw-r--r-- | src/containers/subscription/SubscriptionPopupScreen.js | 3 |
2 files changed, 30 insertions, 56 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 @@ | |||
1 | import { remote } from 'electron'; | ||
2 | import React, { Component } from 'react'; | 1 | import React, { Component } from 'react'; |
3 | import PropTypes from 'prop-types'; | 2 | import PropTypes from 'prop-types'; |
4 | import { inject, observer } from 'mobx-react'; | 3 | import { inject, observer } from 'mobx-react'; |
@@ -6,70 +5,31 @@ import { inject, observer } from 'mobx-react'; | |||
6 | import PaymentStore from '../../stores/PaymentStore'; | 5 | import PaymentStore from '../../stores/PaymentStore'; |
7 | 6 | ||
8 | import SubscriptionForm from '../../components/subscription/SubscriptionForm'; | 7 | import SubscriptionForm from '../../components/subscription/SubscriptionForm'; |
9 | 8 | import TrialForm from '../../components/subscription/TrialForm'; | |
10 | const { BrowserWindow } = remote; | ||
11 | 9 | ||
12 | export default @inject('stores', 'actions') @observer class SubscriptionFormScreen extends Component { | 10 | export 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} |
diff --git a/src/containers/subscription/SubscriptionPopupScreen.js b/src/containers/subscription/SubscriptionPopupScreen.js index f76d6c5a6..0de5a87c4 100644 --- a/src/containers/subscription/SubscriptionPopupScreen.js +++ b/src/containers/subscription/SubscriptionPopupScreen.js | |||
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; | |||
3 | import { inject, observer } from 'mobx-react'; | 3 | import { inject, observer } from 'mobx-react'; |
4 | 4 | ||
5 | import SubscriptionPopup from '../../components/subscription/SubscriptionPopup'; | 5 | import SubscriptionPopup from '../../components/subscription/SubscriptionPopup'; |
6 | import { isDevMode } from '../../environment'; | ||
6 | 7 | ||
7 | 8 | ||
8 | export default @inject('stores', 'actions') @observer class SubscriptionPopupScreen extends Component { | 9 | export default @inject('stores', 'actions') @observer class SubscriptionPopupScreen extends Component { |
@@ -13,7 +14,7 @@ export default @inject('stores', 'actions') @observer class SubscriptionPopupScr | |||
13 | completeCheck(event) { | 14 | completeCheck(event) { |
14 | const { url } = event; | 15 | const { url } = event; |
15 | 16 | ||
16 | if ((url.includes('recurly') && url.includes('confirmation')) || (url.includes('meetfranz') && url.includes('success'))) { | 17 | if ((url.includes('recurly') && url.includes('confirmation')) || ((url.includes('meetfranz') || isDevMode) && url.includes('success'))) { |
17 | this.setState({ | 18 | this.setState({ |
18 | complete: true, | 19 | complete: true, |
19 | }); | 20 | }); |