mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 21:34:24 +00:00
stripe integration done, handling missing still
This commit is contained in:
@@ -8,7 +8,17 @@
|
||||
*/
|
||||
|
||||
class PaymentHandler {
|
||||
constructor () {}
|
||||
constructor () {
|
||||
this.canceledTransactions = {};
|
||||
}
|
||||
|
||||
async handleSuccess ( token ) {
|
||||
console.log( token );
|
||||
}
|
||||
|
||||
async handleError ( token ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PaymentHandler;
|
||||
@@ -12,13 +12,18 @@ const path = require( 'path' );
|
||||
const db = require( '../../../db/db.js' );
|
||||
const stripConfig = JSON.parse( fs.readFileSync( path.join( __dirname + '/../../../../config/payments.config.secret.json' ) ) )[ 'stripe' ];
|
||||
const stripe = require( 'stripe' )( stripConfig[ 'APIKey' ] );
|
||||
const bodyParser = require( 'body-parser' );
|
||||
const ph = require( '../../../payments/paymentHandler.js' );
|
||||
const paymentHandler = new ph();
|
||||
|
||||
const endpointSecret = stripConfig[ 'endpointSecret' ];
|
||||
|
||||
let sessionReference = {};
|
||||
|
||||
// TODO: Remove all selected tickets if timestamp more than user defined amount ago
|
||||
|
||||
module.exports = ( app, settings ) => {
|
||||
app.post( '/payments/prepare', ( req, res ) => {
|
||||
app.post( '/payments/prepare', bodyParser.json(), ( req, res ) => {
|
||||
let purchase = {
|
||||
'line_items': [],
|
||||
'mode': 'payment',
|
||||
@@ -48,6 +53,7 @@ module.exports = ( app, settings ) => {
|
||||
}
|
||||
}
|
||||
const session = await stripe.checkout.sessions.create( purchase );
|
||||
sessionReference[ session.id ] = req.session.id;
|
||||
res.send( session.url );
|
||||
} )();
|
||||
} );
|
||||
@@ -69,9 +75,10 @@ module.exports = ( app, settings ) => {
|
||||
response.status( 200 );
|
||||
response.flushHeaders();
|
||||
response.write( 'data: connected\n\n' );
|
||||
// TODO: Finish up
|
||||
} );
|
||||
|
||||
app.post( '/payments/webhook', ( req, res ) => {
|
||||
app.post( '/payments/webhook', bodyParser.raw( { type: 'application/json' } ), ( req, res ) => {
|
||||
const payload = req.body;
|
||||
const sig = req.headers[ 'stripe-signature' ];
|
||||
|
||||
@@ -80,9 +87,14 @@ module.exports = ( app, settings ) => {
|
||||
try {
|
||||
event = stripe.webhooks.constructEvent( payload, sig, endpointSecret );
|
||||
} catch ( err ) {
|
||||
console.error( err );
|
||||
return res.status( 400 ).send( 'Webhook Error' );
|
||||
}
|
||||
|
||||
if ( event.type === 'checkout.session.completed' ) {
|
||||
paymentHandler.handleSuccess( sessionReference[ event.data.object.id ] );
|
||||
}
|
||||
|
||||
res.status( 200 ).end();
|
||||
} );
|
||||
};
|
||||
@@ -12,6 +12,7 @@ const geth = require( './api/getHandler.js' );
|
||||
const postHandler = new posth();
|
||||
const getHandler = new geth();
|
||||
const path = require( 'path' );
|
||||
const bodyParser = require( 'body-parser' );
|
||||
|
||||
// settings is missing in arguments which shouldn't pose any problem
|
||||
module.exports = ( app, settings ) => {
|
||||
@@ -31,7 +32,7 @@ module.exports = ( app, settings ) => {
|
||||
} );
|
||||
} );
|
||||
|
||||
app.post( '/API/:call', ( req, res ) => {
|
||||
app.post( '/API/:call', bodyParser.json(), ( req, res ) => {
|
||||
// add lang in the future
|
||||
postHandler.handleCall( req.params.call, req.body, req.session ).then( data => {
|
||||
res.send( data );
|
||||
|
||||
@@ -14,6 +14,7 @@ const twoFA = new auth();
|
||||
const path = require( 'path' );
|
||||
const mail = require( './mail/mailSender.js' );
|
||||
const mailManager = new mail();
|
||||
const bodyParser = require( 'body-parser' );
|
||||
|
||||
let responseObjects = {};
|
||||
let authOk = {};
|
||||
@@ -43,7 +44,7 @@ module.exports = ( app, settings ) => {
|
||||
res.send( 'ok' );
|
||||
} );
|
||||
|
||||
app.post( '/user/login', ( request, response ) => {
|
||||
app.post( '/user/login', bodyParser.json(), ( request, response ) => {
|
||||
if ( request.body.mail && request.body.password ) {
|
||||
pwdmanager.checkpassword( request.body.mail, request.body.password ).then( data => {
|
||||
request.session.username = request.body.mail;
|
||||
@@ -98,7 +99,7 @@ module.exports = ( app, settings ) => {
|
||||
}
|
||||
} );
|
||||
|
||||
app.post( '/user/2fa/verify', ( request, response ) => {
|
||||
app.post( '/user/2fa/verify', bodyParser.json(), ( request, response ) => {
|
||||
let verified = twoFA.verifyEnhanced( request.body.token, request.body.code );
|
||||
if ( verified ) {
|
||||
request.session.loggedInUser = true;
|
||||
@@ -136,7 +137,7 @@ module.exports = ( app, settings ) => {
|
||||
response.send( 'logoutOk' );
|
||||
} );
|
||||
|
||||
app.post( '/user/signup', ( request, response ) => {
|
||||
app.post( '/user/signup', bodyParser.json(), ( request, response ) => {
|
||||
// TODO: Make sure that user does not exist yet first and if user
|
||||
// exists, send back info that it is that way
|
||||
response.send( 'ok' );
|
||||
|
||||
Reference in New Issue
Block a user