File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed
Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change 22
33# dependencies
44/node_modules
5- /.pnp
6- .pnp.js
75
86# testing
97/coverage
108
119# production
1210/build
11+ /lambda
1312
1413# misc
1514.DS_Store
15+ .env
1616.env.local
1717.env.development.local
1818.env.test.local
Original file line number Diff line number Diff line change 1+ const stripe = require ( 'stripe' ) ( 'sk_test_yaKbjP7rkSGdMeQtQvTMx4cG' ) ;
2+
3+ exports . handler = ( event , context , callback ) => {
4+ // This will allow us to freeze open connections to a database
5+ // context.callbackWaitsForEmptyEventLoop = false;
6+
7+ // Only allow POST
8+ if ( event . httpMethod !== 'POST' ) {
9+ return callback ( null , { statusCode : 405 , body : 'Method Not Allowed' } ) ;
10+ }
11+
12+ const data = JSON . parse ( event . body ) ;
13+
14+ if ( ! data . token || parseInt ( data . amount ) < 1 ) {
15+ return callback ( null , {
16+ statusCode : 400 ,
17+ body : JSON . stringify ( {
18+ message : 'Some required fields were not supplied.' ,
19+ } ) ,
20+ } ) ;
21+ }
22+
23+ stripe . charges
24+ . create ( {
25+ amount : parseInt ( data . amount ) ,
26+ currency : 'usd' ,
27+ description : 'Dreamcast game shop' ,
28+ source : data . token ,
29+ } )
30+ . then ( ( { status } ) => {
31+ return callback ( null , {
32+ statusCode : 200 ,
33+ body : JSON . stringify ( { status } ) ,
34+ } ) ;
35+ } )
36+ . catch ( err => {
37+ return callback ( null , {
38+ statusCode : 400 ,
39+ body : JSON . stringify ( {
40+ message : `Error: ${ err . message } ` ,
41+ } ) ,
42+ } ) ;
43+ } ) ;
44+ } ;
You can’t perform that action at this time.
0 commit comments