#putte
1 messages · Page 1 of 1 (latest)
Can you share the code that invokes that error?
Extra info: When I console.log the stripe object, I see this:
api: {
auth: 'Bearer sk_test******',
host: 'api.stripe.com',
port: '443',
protocol: 'https',
basePath: '/v1/',
version: '2022-11-15',
timeout: 80000,
maxNetworkRetries: 0,
agent: null,
httpClient: NodeHttpClient { _agent: undefined },
dev: false,
stripeAccount: null
},
Yes
import Stripe from "stripe";
const stripe = new Stripe(process.env.TEST_STRIPE_SECRET_KEY as string, {
apiVersion: "2022-11-15",
typescript: true
});
export default stripe
The function that triggers the error:
stripe.paymentIntents.search(paymentIntentQuery.query)
What's the value of paymentIntentQuery.query?
status:\'requires_action\' AND customer:\'${stripe_customer_id}\'
But its not really the issue, I know the query works because I've used it thousands times. The issue is that Stripe is now rejecting my API key since I converted to ES6 instead of using commonjs require
It's a string? That method expects an object:
stripe.paymentIntents.search({ query: paymentIntentQuery.query })
paymentIntentQuery = {query: status:\'requires_action\' AND customer:\'${stripe_customer_id}\'}
Yeah its an object, but hey lets not focus too much on that, if that was the error then Stripe would tell that an error occurred with the request due to formatting issues
The issue now is that my API key is getting rejected
The issue isn't that your API key is being rejected. The issue is is that your TS code is being incorrectly compiled and as such you're inadvertently overwriting the Stripe instance (and the API key). Bear with me
you are absolutely right
Dammit
Sorry for my impatience, I got some really bad support yesterday
But you are correct, I fixed the mistake and it now works
The error message should point out that its a formatting issue rather than an incorrect API key though, like it would if you used require, but good, now I know
What was the issue?
It was like you said, the stripe.paymentIntents.search expected an object and not a string, and I only passed a string
Perfect. In future, I'd recommend casting your paymentIntentQuery.query variable: https://github.com/stripe/stripe-node/blob/master/types/PaymentIntentsResource.d.ts#L5563
Absolutely, thank you very much!