mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 13:24:24 +00:00
begin stripe plugin
This commit is contained in:
@@ -15,6 +15,8 @@ const bodyParser = require( 'body-parser' );
|
||||
const cookieParser = require( 'cookie-parser' );
|
||||
const http = require( 'http' );
|
||||
const fs = require( 'fs' );
|
||||
const pm = require( './backend/plugins/manager.js' );
|
||||
const pluginManager = new pm();
|
||||
|
||||
|
||||
console.log( `
|
||||
@@ -86,8 +88,8 @@ if ( settings.init ) {
|
||||
file = path.join( __dirname + '/../webapp/setup/dist/index.html' );
|
||||
}
|
||||
|
||||
// TODO: Create plugin loader and manager
|
||||
|
||||
console.log( '[ Server ] loading plugins' );
|
||||
pluginManager.load( app, settings );
|
||||
|
||||
app.use( ( request, response ) => {
|
||||
response.sendFile( file );
|
||||
|
||||
28
src/server/backend/plugins/manager.js
Normal file
28
src/server/backend/plugins/manager.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* libreevent - manager.js
|
||||
*
|
||||
* Created by Janis Hutz 07/25/2023, Licensed under the GPL V3 License
|
||||
* https://janishutz.com, development@janishutz.com
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
This is the plugin manager. It is responsible for installing, updating and uninstalling plugins.
|
||||
*/
|
||||
|
||||
class PluginManager {
|
||||
constructor () {}
|
||||
|
||||
install ( plugin ) {
|
||||
|
||||
}
|
||||
|
||||
update () {}
|
||||
|
||||
uninstall ( plugin ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PluginManager;
|
||||
@@ -7,9 +7,22 @@ You will also need to add documentation for the user to set up the payment gatew
|
||||
In the routes.js file you should have at least the following code:
|
||||
|
||||
```
|
||||
module.exports = ( app ) => {
|
||||
module.exports = ( app, settings ) => {
|
||||
app.post( '/payments/prepare', ( req, res ) => {
|
||||
|
||||
}
|
||||
} );
|
||||
|
||||
app.get( '/payments/status', ( request, response ) => {
|
||||
response.writeHead( 200, {
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Connection': 'keep-alive',
|
||||
} );
|
||||
response.status( 200 );
|
||||
response.flushHeaders();
|
||||
response.write( 'data: connected\n\n' );
|
||||
} );
|
||||
}
|
||||
```
|
||||
|
||||
Take some inspiration of the stripe or adyen setup as these are officially supported by the system and have been developed by the original creator.
|
||||
|
||||
@@ -7,6 +7,49 @@
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = ( app ) => {
|
||||
app.post( '/payments/prepare' )
|
||||
}
|
||||
const fs = require( 'fs' );
|
||||
const path = require( 'path' );
|
||||
const stripe = require( 'stripe' )( fs.readFileSync( path.join( __dirname + '/../../../../config/payments.config.secret.json' ) )[ 'stripe' ][ 'APIKey' ] );
|
||||
|
||||
module.exports = ( app, settings ) => {
|
||||
app.post( '/payments/prepare', async ( req, res ) => {
|
||||
let purchase = {
|
||||
'line_items': [],
|
||||
'mode': 'payment',
|
||||
'success_url': settings.yourDomain + '/payments/success',
|
||||
'cancel_url': settings.yourDomain + '/payments/canceled',
|
||||
'submit_type': 'book',
|
||||
'customer_email': req.body.customer.mail
|
||||
};
|
||||
|
||||
for ( let item in req.body.products ) {
|
||||
purchase[ 'line_items' ].push( {
|
||||
'price_data': {
|
||||
'currency': req.body.currency,
|
||||
'product_data': {
|
||||
'name': req.body.products[ item ].name,
|
||||
},
|
||||
'unit_amount': req.body.products[ item ].price
|
||||
},
|
||||
'quantity': req.body.products[ item ].count ?? 1,
|
||||
} );
|
||||
}
|
||||
const session = await stripe.checkout.sessions.create( purchase );
|
||||
res.send( session.url );
|
||||
} );
|
||||
|
||||
app.get( '/payments/status', ( request, response ) => {
|
||||
response.writeHead( 200, {
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Connection': 'keep-alive',
|
||||
} );
|
||||
response.status( 200 );
|
||||
response.flushHeaders();
|
||||
response.write( 'data: connected\n\n' );
|
||||
} );
|
||||
|
||||
app.post( '/payments/webhook', ( req, res ) => {
|
||||
// The webhook stripe sends data to
|
||||
} );
|
||||
};
|
||||
0
src/server/backend/plugins/poll/pollRoutes.js
Normal file
0
src/server/backend/plugins/poll/pollRoutes.js
Normal file
5
src/server/config/payments.config.json
Normal file
5
src/server/config/payments.config.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"stripe": {
|
||||
"APIKey": ""
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
{
|
||||
"init": true,
|
||||
"twoFA": "enhanced",
|
||||
"db": "mysql"
|
||||
"db": "mysql",
|
||||
"payments": "stripe",
|
||||
"yourDomain": "http://localhost:8081"
|
||||
}
|
||||
20
src/server/package-lock.json
generated
20
src/server/package-lock.json
generated
@@ -20,7 +20,8 @@
|
||||
"mysql": "^2.18.1",
|
||||
"nodemailer": "^6.9.3",
|
||||
"serve-favicon": "^2.5.0",
|
||||
"serve-static": "^1.15.0"
|
||||
"serve-static": "^1.15.0",
|
||||
"stripe": "^12.14.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"acorn": "^8.8.2",
|
||||
@@ -236,6 +237,11 @@
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.4.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.4.tgz",
|
||||
"integrity": "sha512-CukZhumInROvLq3+b5gLev+vgpsIqC2D0deQr/yS1WnxvmYLlJXZpaQrQiseMY+6xusl79E04UjWoqyr+t1/Ew=="
|
||||
},
|
||||
"node_modules/abbrev": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
||||
@@ -2211,6 +2217,18 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/stripe": {
|
||||
"version": "12.14.0",
|
||||
"resolved": "https://registry.npmjs.org/stripe/-/stripe-12.14.0.tgz",
|
||||
"integrity": "sha512-WrDlYH1p5jliY7uzSU5nLDY7OCIeRe6FkC0hhScpTGwMthP/Muk38WXGeggjDHKeXAGCs43jUheZ7Ud/NEAJdg==",
|
||||
"dependencies": {
|
||||
"@types/node": ">=8.1.0",
|
||||
"qs": "^6.11.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.*"
|
||||
}
|
||||
},
|
||||
"node_modules/tar": {
|
||||
"version": "6.1.13",
|
||||
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.13.tgz",
|
||||
|
||||
@@ -53,7 +53,8 @@
|
||||
"mysql": "^2.18.1",
|
||||
"nodemailer": "^6.9.3",
|
||||
"serve-favicon": "^2.5.0",
|
||||
"serve-static": "^1.15.0"
|
||||
"serve-static": "^1.15.0",
|
||||
"stripe": "^12.14.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "test.js"
|
||||
|
||||
Reference in New Issue
Block a user