mirror of
https://github.com/KevinMidboe/planetposen.git
synced 2025-10-29 17:50:32 +00:00
Implemented payments with stripe.
This commit is contained in:
@@ -14,6 +14,8 @@ const PORT = 30010;
|
||||
|
||||
const productsController = require('./controllers/product.js');
|
||||
const variationsController = require('./controllers/variation.js');
|
||||
const applePayController = require('./controllers/applePay.js');
|
||||
const stripeController = require('./controllers/stripe.js');
|
||||
|
||||
app.use(express.json());
|
||||
// app.use(express.urlencoded());
|
||||
@@ -24,6 +26,10 @@ router.post('/product', productsController.addNewProduct)
|
||||
|
||||
router.post('/variation/:id', variationsController.addNewVariationToProduct);
|
||||
|
||||
router.post('/applepay/validateSession', applePayController.validateSession)
|
||||
router.post('/applepay/pay', applePayController.pay)
|
||||
router.post('/stripe/create-payment-intent', stripeController.createPaymentIntent)
|
||||
|
||||
app.use("/public", express.static(path.join(__dirname, "public")));
|
||||
app.use("/dist", express.static(path.join(__dirname, "/../public/dist")));
|
||||
app.use('/.well-known', express.static(path.join(__dirname, "/../frontend/assets/well-known")));
|
||||
|
||||
7
server/config.example.js
Normal file
7
server/config.example.js
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
module.exports = {
|
||||
stripe: {
|
||||
publicKey: '',
|
||||
secretKey: ''
|
||||
}
|
||||
}
|
||||
22
server/controllers/stripe.js
Normal file
22
server/controllers/stripe.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const config = require('../config')
|
||||
const Stripe = require('stripe')
|
||||
const stripe = Stripe(config.stripe.secretKey)
|
||||
|
||||
const createPaymentIntent = async (req, res) => {
|
||||
const { items, currency } = req.body;
|
||||
|
||||
const paymentIntent = await stripe.paymentIntents.create({
|
||||
amount: 1009,
|
||||
currency: 'NOK'
|
||||
})
|
||||
console.log('created payment intent:', paymentIntent);
|
||||
|
||||
return res.send({
|
||||
publishableKey: config.stripe.publicKey,
|
||||
clientSecret: paymentIntent.client_secret
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createPaymentIntent
|
||||
}
|
||||
Reference in New Issue
Block a user