Stripe Webhook Errors
October 1, 2020 at 1:52amStripe Webhook Errors
October 1, 2020 at 1:52amHello!
I believe the issues that I'm having are with the Stripe webhooks in my site.
When I try to access the checkout page from any part of my site, I get the following errors:
"Unexpected token in JSON at position 0"
and
"Failed to load resource: :8888/api/stripe-create-checkout-session
the server responded with a status of 500 (Internal Server Error)"
I was getting a similar 403 error using npm run start instead of netlify dev (which I'm using now).
I should note I'm not quite sure which api endpoints to use to set up the Stripe webhooks in the Stripe dashboard.
Help!
October 1, 2020 at 1:54am
◈ Rewrote URL to /.netlify/functions/stripe-create-checkout-sessionRequest from ::1: POST /.netlify/functions/stripe-create-checkout-sessionwarning Using both auth systems: aws\_access\_key/id and secret\_access\_token !warning Using both auth systems: aws\_access\_key/id and secret\_access\_token !{"level":"error","message":"End - Error:"}{"errorMessage":"Cannot read property 'replace' of undefined","errorType":"TypeError","stackTrace":["Object.<anonymous> (/Users/rhendren/Desktop/walleye-react/u8f3w/api/\_firebase.js:8:52)","Module.\_compile (internal/modules/cjs/loader.js:701:30)","Object.Module.\_extensions..js (internal/modules/cjs/loader.js:712:10)","Module.load (internal/modules/cjs/loader.js:600:32)","tryModuleLoad (internal/modules/cjs/loader.js:539:12)","Function.Module.\_load (internal/modules/cjs/loader.js:531:3)","Module.require (internal/modules/cjs/loader.js:637:17)","require (internal/modules/cjs/helpers.js:22:18)","Object.<anonymous> (/Users/rhendren/Desktop/walleye-react/u8f3w/api/\_require-auth.js:1:85)","Module.\_compile (internal/modules/cjs/loader.js:701:30)"],"level":"error"}Response with status 500 in 8 ms.◈ Error during invocation: { errorMessage: 'Cannot read property \'replace\' of undefined',errorType: 'TypeError',stackTrace:[ 'Object.<anonymous> (/Users/rhendren/Desktop/walleye-react/u8f3w/api/\_firebase.js:8:52)','Module.\_compile (internal/modules/cjs/loader.js:701:30)','Object.Module.\_extensions..js (internal/modules/cjs/loader.js:712:10)','Module.load (internal/modules/cjs/loader.js:600:32)','tryModuleLoad (internal/modules/cjs/loader.js:539:12)','Function.Module.\_load (internal/modules/cjs/loader.js:531:3)','Module.require (internal/modules/cjs/loader.js:637:17)','require (internal/modules/cjs/helpers.js:22:18)','Object.<anonymous> (/Users/rhendren/Desktop/walleye-react/u8f3w/api/\_require-auth.js:1:85)','Module.\_compile (internal/modules/cjs/loader.js:701:30)' ],level: 'error',[Symbol(message)]:'{"errorMessage":"Cannot read property \'replace\' of undefined","errorType":"TypeError","stackTrace":["Object.<anonymous> (/Users/rhendren/Desktop/walleye-react/u8f3w/api/\_firebase.js:8:52)","Module.\_compile (internal/modules/cjs/loader.js:701:30)","Object.Module.\_extensions..js (internal/modules/cjs/loader.js:712:10)","Module.load (internal/modules/cjs/loader.js:600:32)","tryModuleLoad (internal/modules/cjs/loader.js:539:12)","Function.Module.\_load (internal/modules/cjs/loader.js:531:3)","Module.require (internal/modules/cjs/loader.js:637:17)","require (internal/modules/cjs/helpers.js:22
A good start might be that I don't think I set up the webhooks correctly because I wasn't sure what api endpoint to use.
I think this is unrelated to the webhook, as you should be able to go through the checkout flow without a working webhook. It appears to be an issue with your
FIREBASE_PRIVATE_KEY
environment variable being undefined. Do you have all the Firebase values specified in your .env file and have you restarted netlify dev
since adding them?And it should all be on one-line, although if that's just your code editor wrapping automatically then it should be fine.
So when running locally you want to run
npm run stripe-webhook
(detailed more here: https://www.notion.so/divjoy/Divjoy-Stripe-Guide-aa232ce518d845b6b7c66d7e63acdf00#4cf53eca8a534529a37ab9aaac0bd490)Unfortunately even after I replaced the firebase private key and reran
netlify dev
I get the same error:◈ Rewrote URL to /.netlify/functions/stripe-create-checkout-sessionRequest from ::1: POST /.netlify/functions/stripe-create-checkout-sessionwarning Using both auth systems: aws\_access\_key/id and secret\_access\_token !{"level":"error","message":"End - Error:"}{"errorMessage":"Cannot read property 'replace' of undefined","errorType":"TypeError","stackTrace":["Object.<anonymous> (/Users/rhendren/Desktop/walleye-react/u8f3w/api/\_firebase.js:8:52)","Module.\_compile (internal/modules/cjs/loader.js:701:30)","Object.Module.\_extensions..js (internal/modules/cjs/loader.js:712:10)","Module.load (internal/modules/cjs/loader.js:600:32)","tryModuleLoad (internal/modules/cjs/loader.js:539:12)","Function.Module.\_load (internal/modules/cjs/loader.js:531:3)","Module.require (internal/modules/cjs/loader.js:637:17)","require (internal/modules/cjs/helpers.js:22:18)","Object.<anonymous> (/Users/rhendren/Desktop/walleye-react/u8f3w/api/\_require-auth.js:1:85)","Module.\_compile (internal/modules/cjs/loader.js:701:30)"],"level":"error"}Response with status 500 in 22 ms.◈ Error during invocation: { errorMessage: 'Cannot read property \'replace\' of undefined',errorType: 'TypeError',stackTrace:[ 'Object.<anonymous> (/Users/rhendren/Desktop/walleye-react/u8f3w/api/\_firebase.js:8:52)','Module.\_compile (internal/modules/cjs/loader.js:701:30)','Object.Module.\_extensions..js (internal/modules/cjs/loader.js:712:10)','Module.load (internal/modules/cjs/loader.js:600:32)','tryModuleLoad (internal/modules/cjs/loader.js:539:12)','Function.Module.\_load (internal/modules/cjs/loader.js:531:3)','Module.require (internal/modules/cjs/loader.js:637:17)','require (internal/modules/cjs/helpers.js:22:18)','Object.<anonymous> (/Users/rhendren/Desktop/walleye-react/u8f3w/api/\_require-auth.js:1:85)','Module.\_compile (internal/modules/cjs/loader.js:701:30)' ],level: 'error',[Symbol(message)]:'{"errorMessage":"Cannot read property \'replace\' of undefined","errorType":"TypeError","stackTrace":["Object.<anonymous> (/Users/rhendren/Desktop/walleye-react/u8f3w/api/\_firebase.js:8:52)","Module.\_compile (internal/modules/cjs/loader.js:701:30)","Object.Module.\_extensions..js (internal/modules/cjs/loader.js:712:10)","Module.load (internal/modules/cjs/loader.js:600:32)","tryModuleLoad (internal/modules/cjs/loader.js:539:12)","Function.Module.\_load (internal/modules/cjs/loader.js:531:3)","Module.require (internal/modules/cjs/loader.js:637:17)","require (internal/modules/cjs/helpers.js:22:18)","Object.<anonymous> (/Users/rhendren/Desktop/walleye-react/u8f3w/api/\_require-auth.js:1:85)","Module.\_compile (internal/modules/cjs/loader.js:701:30)"],"level":"error"}' }
Hmm, if you're comfortable emailing me your
.env
file then I could take a look and make sure it's not a formatting issue: [email protected]In fact I don't see firebase private key called from any other file
Yeah I'll send it
const firebaseAdmin = require("firebase-admin");if (!firebaseAdmin.apps.length) {firebaseAdmin.initializeApp({credential: firebaseAdmin.credential.cert({projectId: process.env.FIREBASE\_PROJECT\_ID,clientEmail: process.env.FIREBASE\_CLIENT\_EMAIL,privateKey: process.env.FIREBASE\_PRIVATE\_KEY.replace(/\n/g, "\n"),}),databaseURL: `https://${process.env.FIREBASE_PROJECT_ID}.firebaseio.com`,});}module.exports = firebaseAdmin;
Yeah you're right, it's in there.
Sent env vars via email
For anyone looking on this thread for similar errors, I had wrongly formatted things in my ENV file and the firebase private key was commented out (lol)!