Started Stripe Integration
This commit is contained in:
@@ -5,6 +5,10 @@ const QRCode=require('qrcode');
|
||||
const crypto=require('crypto');
|
||||
const path=require('path');
|
||||
const fs = require('fs');
|
||||
require('dotenv').config();
|
||||
const port=process.env.PORT||3000;
|
||||
const base_url = process.env.BASE_URL;
|
||||
const stripe=require('stripe')(process.env.STRIPE_SECRET_KEY);
|
||||
|
||||
const app = express();
|
||||
app.set('view engine','ejs');
|
||||
@@ -63,6 +67,12 @@ const QRSalt ="!SaltyMagic5392370662";
|
||||
// CLAIM ticket email
|
||||
//
|
||||
|
||||
//
|
||||
// Stripe Integration:
|
||||
// The Stripe CLI is configured for Andrew Tepper with account id acct_1QZlMSCHHjDgpHos
|
||||
// Login on stripe.com is tickets@fallsonfire.net Password is x65195241X.1
|
||||
//
|
||||
|
||||
function base64ToBase64Url(base64) {
|
||||
return base64
|
||||
.replace(/\+/g, '-') // Replace '+' with '-'
|
||||
@@ -583,6 +593,48 @@ app.post('/update-setting', requireSuperUser, (req, res) => {
|
||||
});
|
||||
|
||||
|
||||
app.get('/checkout', (req, res) => {
|
||||
// We’ll render a payment form here
|
||||
res.render('checkout2');
|
||||
});
|
||||
|
||||
app.post('/charge', async (req, res) => {
|
||||
try {
|
||||
// Token or Payment Method ID from the client
|
||||
const paymentMethodId = req.body.paymentMethodId;
|
||||
|
||||
// Create a PaymentIntent on the server
|
||||
const return_url=base_url+'/mytickets';
|
||||
const paymentIntent = await stripe.paymentIntents.create({
|
||||
amount: 1999, // Amount in cents (e.g., $19.99)
|
||||
currency: 'usd',
|
||||
payment_method: paymentMethodId,
|
||||
confirmation_method: 'automatic',
|
||||
confirm: true, // Attempt to confirm the payment immediately
|
||||
return_url: return_url,
|
||||
});
|
||||
|
||||
// Check status of payment intent
|
||||
if (paymentIntent.status === 'requires_action') {
|
||||
// Additional action is required (e.g. 3D Secure)
|
||||
res.json({
|
||||
requiresAction: true,
|
||||
paymentIntentClientSecret: paymentIntent.client_secret,
|
||||
});
|
||||
} else if (paymentIntent.status === 'succeeded') {
|
||||
// Payment is complete
|
||||
console.log("Returning json success: true");
|
||||
res.json({ success: true, redirect_url: return_url });
|
||||
} else {
|
||||
res.json({ error: 'Invalid PaymentIntent status' });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Payment error:', error);
|
||||
res.json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Start the server
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running at http://localhost:${PORT}`);
|
||||
|
||||
Reference in New Issue
Block a user