-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
40 lines (29 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const express = require("express");
const cors = require("cors");
const stripe = require("stripe")(
"sk_test_51HRG48FyQkicy6LeM5WVSGHsLMB9lusu4aTpm6PbK60RXLUsMa1OCuJHCj99OKO27XHPtJq4gPEjjnR0vYjJWB4800BvaJM5yA"
);
// API
// - App config
const app = express();
// - Middlewares
app.use(cors({ origin: true }));
app.use(express.json());
// - API routes
app.get("/", (request, response) => response.status(200).send("hello world"));
app.post("/payments/create", async (request, response) => {
const total = request.query.total;
console.log("Payment Request Recieved BOOM!!! for this amount >>> ", total);
const paymentIntent = await stripe.paymentIntents.create({
amount: total, // subunits of the currency
currency: "inr",
});
// OK - Created
response.status(201).send({
clientSecret: paymentIntent.client_secret,
});
});
// - Listen command
app.listen( process.env.PORT || 5000, () => console.log( `The application is listening on port 8000!` ) );
// Example endpoint
// http://localhost:5001/challenge-4b2b2/us-central1/api