-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
43 lines (43 loc) · 1.72 KB
/
main.js
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
(async () => {
if (!process.env.SUBSCRIPTION_WEBHOOK_ENDPOINT_SECRET) {
const fs = require('fs')
const path = require('path')
const events = fs.readdirSync(path.join(__dirname, '/src/www/webhooks/subscriptions/stripe-webhooks'))
const eventList = []
for (const event of events) {
eventList.push(event.substring(0, event.indexOf('.js')))
}
const stripeKey = {
apiKey: process.env.STRIPE_KEY
}
const stripe = require('stripe')({
apiVersion: global.stripeAPIVersion
})
if (global.maxmimumStripeRetries) {
stripe.setMaxNetworkRetries(global.maximumStripeRetries)
}
const webhooks = await stripe.webhookEndpoints.list({ limit: 100 }, stripeKey)
if (webhooks && webhooks.data && webhooks.data.length) {
for (const webhook of webhooks.data) {
await stripe.webhookEndpoints.del(webhook.id, stripeKey)
}
}
const webhook = await stripe.webhookEndpoints.create({
url: `${process.env.DASHBOARD_SERVER}/webhooks/subscriptions/index-subscription-data`,
enabled_events: eventList
}, {
apiKey: process.env.STRIPE_KEY
})
global.subscriptionWebhookEndPointSecret = webhook.secret
}
require('./index.js')
const dashboard = require('@userdashboard/dashboard')
await dashboard.start(__dirname)
if (process.env.NODE_ENV === 'testing') {
const helperRoutes = require('./test-helper-routes.js')
global.sitemap['/api/create-fake-payout'] = helperRoutes.createFakePayout
global.sitemap['/api/fake-amount-owed'] = helperRoutes.fakeAmountOwed
global.sitemap['/api/toggle-refunds'] = helperRoutes.toggleRefunds
global.sitemap['/api/toggle-overdue-invoice-threshold'] = helperRoutes.toggleOverdueInvoiceThreshold
}
})()