diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
commit | 58cda9cc7fb79ca9df6746de7f9662bc08dc156a (patch) | |
tree | 1211600c2a5d3b5f81c435c6896618111a611720 /src/stores/PaymentStore.js | |
download | ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.gz ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.zst ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.zip |
initial commit
Diffstat (limited to 'src/stores/PaymentStore.js')
-rw-r--r-- | src/stores/PaymentStore.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/stores/PaymentStore.js b/src/stores/PaymentStore.js new file mode 100644 index 000000000..9e348d14e --- /dev/null +++ b/src/stores/PaymentStore.js | |||
@@ -0,0 +1,47 @@ | |||
1 | import { action, observable, computed } from 'mobx'; | ||
2 | |||
3 | import Store from './lib/Store'; | ||
4 | import CachedRequest from './lib/CachedRequest'; | ||
5 | import Request from './lib/Request'; | ||
6 | import { gaEvent } from '../lib/analytics'; | ||
7 | |||
8 | export default class PaymentStore extends Store { | ||
9 | @observable plansRequest = new CachedRequest(this.api.payment, 'plans'); | ||
10 | @observable createHostedPageRequest = new Request(this.api.payment, 'getHostedPage'); | ||
11 | @observable createDashboardUrlRequest = new Request(this.api.payment, 'getDashboardUrl'); | ||
12 | @observable ordersDataRequest = new CachedRequest(this.api.payment, 'getOrders'); | ||
13 | |||
14 | constructor(...args) { | ||
15 | super(...args); | ||
16 | |||
17 | this.actions.payment.createHostedPage.listen(this._createHostedPage.bind(this)); | ||
18 | this.actions.payment.createDashboardUrl.listen(this._createDashboardUrl.bind(this)); | ||
19 | } | ||
20 | |||
21 | @computed get plan() { | ||
22 | if (this.plansRequest.isError) { | ||
23 | return {}; | ||
24 | } | ||
25 | return this.plansRequest.execute().result || {}; | ||
26 | } | ||
27 | |||
28 | @computed get orders() { | ||
29 | return this.ordersDataRequest.execute().result || []; | ||
30 | } | ||
31 | |||
32 | @action _createHostedPage({ planId }) { | ||
33 | const request = this.createHostedPageRequest.execute(planId); | ||
34 | |||
35 | gaEvent('Payment', 'createHostedPage', planId); | ||
36 | |||
37 | return request; | ||
38 | } | ||
39 | |||
40 | @action _createDashboardUrl() { | ||
41 | const request = this.createDashboardUrlRequest.execute(); | ||
42 | |||
43 | gaEvent('Payment', 'createDashboardUrl'); | ||
44 | |||
45 | return request; | ||
46 | } | ||
47 | } | ||