Skip to content

Commit

Permalink
alpha v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
theADAMJR committed Apr 19, 2020
1 parent 708e1ca commit efd50bf
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 147 deletions.
13 changes: 6 additions & 7 deletions api/routes/api-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import Stripe from 'stripe';
import bodyParser from 'body-parser';
import { SavedUser } from '../../models/user';

export const router = Router(),
endpointSecret = 'whsec_uNgUHx7T0J1vbOgcTuRCEjXGZYTMvqs0';
export const router = Router();

let commands: CommandDocument[] = [];
SavedCommand.find().then(cmds => commands = cmds);
Expand All @@ -28,6 +27,9 @@ router.get('/auth', async (req, res) => {

router.post('/webhook', async(req, res) => {
try {
// TODO: ensure it matches a stripe signature
// -> this will prevent anyone giving themselves 2PG+ for free
if (!req.headers['stripe-signature']) return;
// stripe.webhooks.signature
// .parseHeader(req.headers['stripe-signature']);

Expand All @@ -37,13 +39,10 @@ router.post('/webhook', async(req, res) => {
return res.json({ success: true });
}
res.json({ received: true });
} catch (error) { res.status(400).send(error); console.log(error);
}
} catch (error) { res.status(400).send(error); }
});

async function giveUserPlus(id: string) {
console.log('give ' + id + ' premium');

async function giveUserPlus(id: string) {
const savedUser = await SavedUser.findById(id);
savedUser.premium = true;
savedUser.save();
Expand Down
2 changes: 1 addition & 1 deletion api/routes/user-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ router.get('/', async (req, res) => {
const items = [
{
name: '2PG+',
description: 'Support 2PG, and unlock exclusive user features!',
description: 'Support 2PG, and unlock exclusive features!',
amount: 500,
currency: 'usd',
quantity: 1,
Expand Down
Loading

0 comments on commit efd50bf

Please sign in to comment.