74 lines
1.7 KiB
JavaScript
74 lines
1.7 KiB
JavaScript
const express = require('express');
|
|
|
|
const BillingService = require('../services/billing');
|
|
const wrapAsync = require('../helpers').wrapAsync;
|
|
|
|
const router = express.Router();
|
|
|
|
router.get(
|
|
'/plans',
|
|
wrapAsync(async (req, res) => {
|
|
const plans = await BillingService.listPlans();
|
|
res.status(200).send({ plans });
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/current',
|
|
wrapAsync(async (req, res) => {
|
|
const subscription = await BillingService.getCurrentSubscription(req.currentUser);
|
|
res.status(200).send({ subscription });
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/stripe-settings',
|
|
wrapAsync(async (req, res) => {
|
|
const settings = await BillingService.getStripeSettings(req.currentUser, req.get('host'));
|
|
res.status(200).send({ settings });
|
|
}),
|
|
);
|
|
|
|
router.put(
|
|
'/stripe-settings',
|
|
wrapAsync(async (req, res) => {
|
|
const settings = await BillingService.updateStripeSettings(
|
|
req.body.data,
|
|
req.currentUser,
|
|
req.get('host'),
|
|
);
|
|
res.status(200).send({ settings });
|
|
}),
|
|
);
|
|
|
|
router.post(
|
|
'/subscribe',
|
|
wrapAsync(async (req, res) => {
|
|
const checkout = await BillingService.subscribe(req.body.planId, req.currentUser);
|
|
res.status(200).send(checkout);
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/checkout-session',
|
|
wrapAsync(async (req, res) => {
|
|
const subscription = await BillingService.confirmCheckoutSession(
|
|
req.query.sessionId,
|
|
req.currentUser,
|
|
);
|
|
res.status(200).send({ subscription });
|
|
}),
|
|
);
|
|
|
|
router.post(
|
|
'/cancel',
|
|
wrapAsync(async (req, res) => {
|
|
const subscription = await BillingService.cancel(req.currentUser);
|
|
res.status(200).send({ subscription });
|
|
}),
|
|
);
|
|
|
|
router.use('/', require('../helpers').commonErrorHandler);
|
|
|
|
module.exports = router;
|