#chayse_api
1 messages · Page 1 of 1 (latest)
👋 Welcome to your new thread!
⏲️ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.
🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1253303800903766016
📝 Have more to share? Add details, code, screenshots, videos, etc. below.
What is new stripe.Stripe? Can you share that method
Of course
I import Stripe (using js) like this: const stripe = require("stripe"); so It's just a Stripe object.
Hmm, just normally you'd instantiate the client via new Stripe(...)
I can certainly give that a try, though using new stripe.Stripe does work with the hardcoded secret key
OK, then I'd imagine something is malforming the key when reading it from your secret store
I see! Reading it in console.log it's exactly the same, do you have any advice on anything I could try when parsing it to Stripe?
How do you actually retrieve it from Google? (not familiar with that at all)
No problem,
I retrieve it from Google Secrets Manager and use a Firestore function to retrieve it, the start of my backend Stripe flow looks like this:
exports.stripePayment = onRequest({secrets: ["StripeKey"]}, async (req, res) => {
Then, I use process.env.StripeKey in order to access the string. If I console.log it, it's exactly the same, so I assumed it was a parsing to Stripe error too but I'm unsure on any way how to fix it.
Yeah but how are you retrieving it?
Sorry ynnoj, I'm not entirely certain what you mean. I've enabled the Google Secrets API inside Firestore so it handles the background work itself. I followed this guide https://cloud.google.com/functions/docs/configuring/env-var#setting_and_retrieving_runtime_environment_variables_an_example
My apologies, it was actually the mounting as a volume part of this guide https://cloud.google.com/functions/docs/configuring/secrets
Hmm, that seems unintuitive. Everything I've found suggests you should be able to access the secrets in the function runtime: https://firebase.google.com/docs/functions/config-env?gen=2nd#create-secret
Exactly right! That looks to be the same way I'm performing the task, hence I'm unsure what else I can do
Like I say, I can console.log() the key and it works, but when I parse it I get TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Authorization"]
I've also tried with just new Stripe() instead of new stripe.Stripe to see if that was the issue, but it didn't fix it unfortunately.
Where exactly is that error thrown? It doesn't look like an error from our SDK/API but instead Google/Firebase
The error is thrown on:
await validatedStripe.paymentIntents.create({
amount: req.body.amount,
currency: "gbp",
metadata: req.body.metadata,
}, (err, paymentIntent) => {
if (err != null) {
console.log(err);
} else {
res.json({
paymentIntent: paymentIntent.client_secret,
});
}
});
It's the err in this function I'm printing. It says:
StripeConnectionError: An error occurred with our connection to Stripe. Request was retried 1 times. at /workspace/node_modules/stripe/cjs/RequestSender.js:322:37
message: 'An error occurred with our connection to Stripe. Request was retried 1 times.',
detail: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Authorization"]
Yeah I mean something is malforming your secret so it's not the expected format unfortunately
Really hard for us to pinpoint the issue as we're not Google/Firebase
Okay, if there's nothing else that can be done on your side I'll go ahead and contact them - thanks for looking into it though!
Apologies, hope you get sorted