menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

Divjoy

The ⚛️ React codebase generator.

Channels
Team

Stripe Webhook Errors

October 1, 2020 at 1:52am

Stripe Webhook Errors

October 1, 2020 at 1:52am
Hello!
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
I've already replaced all of the environment variables. When I trigger a Stripe event from a separate terminal it runs successful; however, when I listen for Stripe events from my app, I don't see any.
Hey Rylie, are you seeing any errors in the terminal window where you're running netlify dev? In your api/stripe-create-checkout-session.js file it should catch any errors and output stripe-create-checkout-session error to the console.
◈ Rewrote URL to /.netlify/functions/stripe-create-checkout-session
Request from ::1: POST /.netlify/functions/stripe-create-checkout-session
warning 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
Edited
like-fill
1
Weird, this is a new one.. I'll do an export now and see if I can reproduce the issue.
Thank you so much!
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?
You're right! I don't have firebase private key defined. I generated a new private key from firebase. This is the result. Should I just store the private_key value as an environment variable from this json?
Yup! Although delete those images since this is sensitive data :)
like-fill
1
And it should all be on one-line, although if that's just your code editor wrapping automatically then it should be fine.
While it is not a stripe webhooks issue, I still don't understand what api endpoint to use when setting up the stripe web hook. Is it api/stripe-webhook or is that supposed to be a placeholder?
Great, thanks.
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-session
Request from ::1: POST /.netlify/functions/stripe-create-checkout-session
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 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"}' }
Edited
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
Edited
Yeah I'll send it
Could you paste the contents of your api/_firebase.js file? It should be in there.
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;
Edited
Yeah you're right, it's in there.
Sent env vars via email
like-fill
1
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)!
like-fill
1