-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbilling.js
More file actions
30 lines (27 loc) · 790 Bytes
/
Copy pathbilling.js
File metadata and controls
30 lines (27 loc) · 790 Bytes
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
import stripePackage from "stripe";
import handler from "./libs/handler-lib";
import { calculateCost } from "./libs/billing-lib";
export const main = handler(async (event, context) => {
const { storage, source } = JSON.parse(event.body);
const amount = calculateCost(storage);
const description = "Scratch charge";
// Load our secret key from the environment variables
const stripe = stripePackage(process.env.stripeSecretKey);
await stripe.charges.create({
source,
amount,
description,
currency: "usd",
shipping: {
name: "Srikanth Katti",
address: {
line1: "510 Townsend St",
postal_code: "98140",
city: "San Francisco",
state: "CA",
country: "US",
},
},
});
return { status: true };
});