-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.js
40 lines (37 loc) · 966 Bytes
/
handler.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
'use strict';
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
module.exports.createCharge = async (event, context) => {
const requestBody = JSON.parse(event.body);
const token = requestBody.token.id;
const amount = requestBody.charge.amount;
const currency = requestBody.charge.currency;
const metadata = requestBody.metadata;
const response = {
headers: {
'Access-Control-Allow-Origin': '*',
}
};
// create charge
try {
const charge = await stripe.charges.create({
amount,
currency,
description: 'The Away Team, LLC',
source: token,
metadata
});
// successful charge created
response.statusCode = 200;
response.body = JSON.stringify({
message: 'Charge processed successfully',
charge
});
return response;
} catch(error) {
response.statusCode = 500;
response.body =JSON.stringify({
error
});
return response;
}
};