-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstripe-subscriptions-module.html
255 lines (251 loc) · 12.9 KB
/
stripe-subscriptions-module.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<html data-navbar="navbar.html">
<head>
<title>Stripe Subscriptions module documentation</title>
<link rel="stylesheet" href="/public/style.css" integrity="sha384-XmYAsTgQ0mGje5sxXJRryYc/mmaL3bnA+Hn9kHkpyRTgdpgM220bOzj5BgWZ41jo" crossorigin="anonymous" />
<script async="" src="/public/highlight.min.js" integrity="sha384-YicwDnP9OMQKl5DfX4/eDA3oUGqPTcuyq0+eFbwv595VqixFKEgoO/T8TxD0tjB8" crossorigin="anonymous"></script>
<script src="/public/browser.js" integrity="sha384-pNXFiUIAMNO/S1fGF4GF3fq8OV5x2fZdicewcpuMG/2EOOJ7+HH3no0GDKTePhCD" crossorigin="anonymous"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="UTF-8" />
<body><a name="top" id="top"></a>
<div class="body-container">
<header>
<h1 id="dashboard">Stripe Subscriptions module documentation</h1>
<section id="navigation" class="navigation">
<menu id="navbar-handle" class="super-navbar" style="display: none">
<li><a href="#" title="Show menu">Show navigation menu</a></li>
</menu>
<ul id="navbar-menu" style="display: block">
<li>
<h2>Dashboard</h2>
<ul>
<li><a href="/dashboard">Documentation</a></li>
<li><a href="/dashboard-configuration">Configuration variables</a></li>
<li><a href="/dashboard-sitemap">Visual sitemap</a></li>
<li><a href="/dashboard-ui">UI index</a></li>
<li><a href="/dashboard-api">API index</a></li>
</ul>
</li>
<li>
<h2>MaxMind GeoIP</h2>
<ul>
<li><a href="/maxmind-geoip-module">Documentation</a></li>
<li><a href="/maxmind-geoip-api">API index</a></li>
</ul>
</li>
<li>
<h2>Organizations</h2>
<ul>
<li><a href="/organizations-module">Documentation</a></li>
<li><a href="/organizations-configuration">Configuration variables</a></li>
<li><a href="/organizations-sitemap">Visual sitemap</a></li>
<li><a href="/organizations-ui">UI index</a></li>
<li><a href="/organizations-api">API index</a></li>
</ul>
</li>
<li>
<h2>Stripe Connect</h2>
<ul>
<li><a href="/stripe-connect-module">Documentation</a></li>
<li><a href="/stripe-connect-configuration">Configuration variables</a></li>
<li><a href="/stripe-connect-sitemap">Visual sitemap</a></li>
<li><a href="/stripe-connect-ui">UI index</a></li>
<li><a href="/stripe-connect-api">API index</a></li>
</ul>
</li>
<li>
<h2>Stripe Subscriptions</h2>
<ul>
<li><a href="/stripe-subscriptions-module">Documentation</a></li>
<li><a href="/stripe-subscriptions-configuration">Configuration variables</a></li>
<li><a href="/stripe-subscriptions-sitemap">Visual sitemap</a></li>
<li><a href="/stripe-subscriptions-ui">UI index</a></li>
<li><a href="/stripe-subscriptions-api">API index</a></li>
</ul>
</li>
<li>
<h2>Example app</h2>
<ul>
<li><a href="/example-web-app">Documentation</a></li>
<li><a href="/example-web-app-sitemap">Visual sitemap</a></li>
<li><a href="/example-web-app-ui">UI index</a></li>
</ul>
</li>
<li>
<h2>Example subscription app</h2>
<ul>
<li><a href="/example-subscription-web-app">Documentation</a></li>
<li><a href="/example-subscription-web-app-sitemap">Visual sitemap</a></li>
<li><a href="/example-subscription-web-app-ui">UI index</a></li>
</ul>
</li>
</ul>
<style>
.reveal,
.reveal ul {
display: block
}
</style>
<script>
var menu = document.getElementById("navbar-menu")
menu.style.display = "none"
var handle = document.getElementById("navbar-handle")
handle.style.display = "block"
handle.onclick = function(e) {
if (menu.style.display === "block") {
menu.style.display = "none"
menu.className = ""
handle.firstElementChild.firstElementChild.innerHTML = "Show navigation menu"
} else {
menu.style.display = "block"
menu.className = "reveal"
handle.firstElementChild.firstElementChild.innerHTML = "Hide navigation menu"
}
}
</script>
</section>
</header>
<div class="section-container">
<section class="full"><a name="content" id="content"></a>
<div class="content">
<h1 id="documentation-for-stripe-connect">Documentation for Stripe Connect</h1>
<h4>Index</h4>
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#module-contents">Module contents</a></li>
<li><a href="#import-this-module">Import this module</a></li>
<li><a href="#setting-up-your-stripe-credentials">Setting up your Stripe credentials</a></li>
<li><a href="#configuring-your-products-and-plans">Configuring your products and plans</a></li>
<li><a href="#storage-engine">Storage engine</a></li>
<li><a href="#access-the-api">Access the API</a></li>
<li><a href="https://github.com/userdashboard/stripe-subscriptions">Github repository</a></li>
<li><a href="https://npmjs.org/userdashboard/stripe-subscriptions">NPM package</a></li>
</ul>
<h1 id="introduction">Introduction</h1>
<p>Dashboard bundles everything a web app needs, all the "boilerplate" like signing in and changing passwords, into a parallel server so you can write a much smaller web app.</p>
<p>The Stripe Subscriptions module adds a complete interface for creating and managing your Stripe products, plans, subscriptions etc and a complete interface for users to subscribe to plans. Users can self-cancel their subscriptions at any time and you can nominate a 0+ day period allowing users to refund themselves too. You can optionally require a subscription and/or no unpaid invoices from all users outside of the <code data-language="js">/account/</code> and <code data-language="js">/administrator/</code> content. The <a href="https://stripe.com/docs/api">Stripe API documentation</a> supplements this documentation.</p>
<h1 id="module-contents">Module contents</h1>
<p>Dashboard modules can add pages and API routes. For more details check the <code data-language="js">sitemap.txt</code> and <code data-language="js">api.txt</code> or <code data-language="js">env.txt</code> also contained in the online documentation.</p>
<table>
<thead>
<tr>
<th>Content type</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Proxy scripts</td>
<td></td>
</tr>
<tr>
<td>Server scripts</td>
<td>Yes</td>
</tr>
<tr>
<td>Content scripts</td>
<td></td>
</tr>
<tr>
<td>User pages</td>
<td>Yes</td>
</tr>
<tr>
<td>User API routes</td>
<td>Yes</td>
</tr>
<tr>
<td>Administrator pages</td>
<td>Yes</td>
</tr>
<tr>
<td>Administrator API routes</td>
<td>Yes</td>
</tr>
</tbody>
</table>
<h2 id="import-this-module">Import this module</h2>
<p>Install the module with NPM:</p>
<pre><code data-language="js">$ npm install @userdashboard/stripe-subscriptions
</code></pre>
<p>Edit your <code data-language="js">package.json</code> to activate the module:</p>
<pre><code data-language="js">"dashboard": {
"modules": [
"@userdashboard/stripe-subscriptions"
]
}
</code></pre>
<h2 id="setting-up-your-stripe-credentials">Setting up your Stripe credentials</h2>
<p>You will need to retrieve various keys from <a href="https://stripe.com">Stripe</a>. During development your webhook will be created automatically, but in production with multiple dashboard server instances they share a configured webhook:</p>
<pre><code data-language="js">- create your Stripe account and find your API keys
- create a webhook for https://your_domain/webhooks/subscriptions/index-subscription-data
- environment STRIPE_JS=3|2|false
- environment STRIPE_KEY=sk_test_xxxxxxx
- environment STRIPE_PUBLISHABLE_KEY=pk_test_xxxxxxx
- environment SUBSCRIPTION_WEBHOOK_ENDPOINT_SECRET=whsec_xxxxxxxx
</code></pre>
<h2 id="requiring-subscriptions">Requiring subscriptions</h2>
<p>Environment variables are documented in Dashboard and each module's <code data-language="js">/start-dev.sh</code>.</p>
<p>You can require subscriptions and no overdue invoices through environment variables:</p>
<pre><code data-language="js">REQUIRE_SUBSCRIPTION=true
REQUIRE_PAYMENT=true
</code></pre>
<h3 id="configuring-your-products-and-plans">Configuring your products and plans</h3>
<p>This module adds a complete interface for creating products and plans. Stripe's nomenclature and structure is used directly so for more information refer to the <a href="https://stripe.com/docs">Stripe documentation</a> and <a href="https://stripe.com/docs/api">Stripe API documentation</a>.</p>
<p>Users subscribe to plans and plans must be built from products. Additionally, this module imposes a 'publish' status on products and plans that controls access to them by users.</p>
<ol>
<li>Administrator creates product</li>
<li>Administrator publishes product</li>
<li>Administrator creates plan</li>
<li>Administrator publishes plan</li>
<li>User selects plan from published plans</li>
<li>User creates subscription optionally with payment</li>
</ol>
<p>You can use links for users to create a subscription to a specific plan:</p>
<pre><code data-language="js">/account/subscriptions/start-subscription?planid=X
</code></pre>
<h2 id="storage-engine">Storage engine</h2>
<p>By default this module will share whatever storage you use for Dashboard. You can specify an alternate storage module to use instead, or the same module with a separate database.</p>
<pre><code data-language="js">SUBSCRIPTIONS_STORAGE=@userdashboard/storage-postgresql
SUBSCRIPTIONS_DATABASE_URL=postgres://localhost:5432/subscriptions
</code></pre>
<h3 id="access-the-api">Access the API</h3>
<p>Dashboard and official modules are completely API-driven and you can access the same APIs on behalf of the user making requests. You perform <code data-language="js">GET</code>, <code data-language="js">POST</code>, <code data-language="js">PATCH</code>, and <code data-language="js">DELETE</code> HTTP requests against the API endpoints to fetch or modify data. This example fetches the user's subscriptions using NodeJS, you can do this with any language:</p>
<p>You can view API documentation within the NodeJS modules' <code data-language="js">api.txt</code> files, or on the <a href="https://userdashboard.github.io/stripe-subscriptions-api">documentation site</a>.</p>
<pre><code data-language="js">const subscriptions = await proxy(`/api/user/subscriptions/subscriptions?accountid=${accountid}&all=true`, accountid, sessionid)
const proxy = util.promisify((path, accountid, sessionid, callback) => {
const requestOptions = {
host: 'dashboard.example.com',
path: path,
port: '443',
method: 'GET',
headers: {
'x-application-server': 'application.example.com',
'x-application-server-token': process.env.APPLICATION_SERVER_TOKEN,
'x-accountid': accountid,
'x-sessionid': sessionid
}
}
const proxyRequest = require('https').request(requestOptions, (proxyResponse) => {
let body = ''
proxyResponse.on('data', (chunk) => {
body += chunk
})
return proxyResponse.on('end', () => {
return callback(null, JSON.parse(body))
})
})
proxyRequest.on('error', (error) => {
return callback(error)
})
return proxyRequest.end()
})
}
</code></pre>
</div>
<p><a href="#top">Top of page</a></p>
</section>
</div>
</div>
</body>
</head>
</html>