Untitled
unknown
plain_text
10 months ago
975 B
12
Indexable
import express from "express";
import Stripe from "stripe";
const app = express();
const stripe = new Stripe("YOUR_STRIPE_SECRET_KEY");
// 1. Create payment intent (user pays full amount)
app.post("/create-payment", async (req, res) => {
try {
const { amount, providerAccountId } = req.body;
// amount in paisa (₹100 = 10000)
// providerAccountId = Stripe connected account of service provider
const paymentIntent = await stripe.paymentIntents.create({
amount,
currency: "inr",
payment_method_types: ["card"],
application_fee_amount: Math.round(amount * 0.1), // 10% platform fee
transfer_data: {
destination: providerAccountId, // money goes to service provider
},
});
res.json({ clientSecret: paymentIntent.client_secret });
} catch (err) {
console.error(err);
res.status(500).send("Payment failed");
}
});
// Run server
app.listen(3000, () => console.log("Server running on 3000"));Editor is loading...
Leave a Comment