@@ -52,29 +52,31 @@ const titles = {
5252 router . post ( '/donate' , async ( req , res , next ) => {
5353 let data ;
5454 try {
55+ data = JSON . parse ( req . body . data ) ;
5556 let body = await request . post ( {
5657 url :'https://www.google.com/recaptcha/api/siteverify' ,
5758 form : {
58- secret : settings . googleCaptchaKey ,
59- response : data . recaptcha
59+ secret : settings . googleCaptchaKey ,
60+ response : data . recaptcha
6061 }
6162 } ) ;
6263 body = JSON . parse ( body ) ;
63- if ( body . success === true ) {
64- data = JSON . parse ( req . body . data ) ;
65- stripe . charges . create ( {
66- amount : data . token . price ,
67- currency : "usd" ,
68- source : data . token . id , // obtained with Stripe.js
69- description : `Donation from ${ data . token . email } - ${ data . comment } `
70- } , ( err , charge ) => {
71- if ( process . env . spec === "true" ) return res . sendStatus ( 200 ) ;
72- if ( err ) return res . sendStatus ( 400 ) ;
73- else return res . sendStatus ( 200 ) ;
74- } ) ;
75- }
7664 } catch ( e ) {
77- return res . sendStatus ( 400 ) ;
65+ if ( process . env . spec === "true" ) body = { success : true } ;
66+ else return res . sendStatus ( 400 ) ;
67+ }
68+ if ( body . success === true ) {
69+ data = JSON . parse ( req . body . data ) ;
70+ stripe . charges . create ( {
71+ amount : data . token . price ,
72+ currency : "usd" ,
73+ source : data . token . id , // obtained with Stripe.js
74+ description : `Donation from ${ data . token . email } - ${ data . comment } `
75+ } , ( err , charge ) => {
76+ if ( process . env . spec === "true" ) return res . sendStatus ( 200 ) ;
77+ if ( err ) return res . sendStatus ( 400 ) ;
78+ else return res . sendStatus ( 200 ) ;
79+ } ) ;
7880 }
7981 } ) ;
8082
0 commit comments