-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (40 loc) · 1.28 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
41
42
43
44
45
46
47
48
49
50
51
52
const functions = require("firebase-functions");
const express = require("express");
const stripe = require("stripe")("Stripe API key");
const request = require("request");
let port = process.env.PORT || 5050;
const app = express();
app.use(express.json());
const cors = require("cors");
app.use(cors());
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
next();
});
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 for a total of => ", total);
const paymentIntent = await stripe.paymentIntents.create({
amount: total,
currency: "usd",
description: "Software development services",
shipping: {
name: "email", // TODO: Capture name for {user.displayName}
address: {
line1: "510 Townsend St", // TODO: Capture the details from user.
postal_code: "98140",
city: "San Francisco",
state: "CA",
country: "US",
},
},
});
response.status(201).send({
clientSecret: paymentIntent.client_secret,
});
});
exports.api = functions.https.onRequest(app);
app.listen(port, () => {
console.log(`App listening on port ${port}`);
});