mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 21:34:24 +00:00
begin stripe plugin
This commit is contained in:
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
Reference in New Issue
Block a user