#jaz-testing
1 messages · Page 1 of 1 (latest)
hi! well first of all, amount:2 won't work, that is 2c and there is a minimum charge of 50c. That might be the issue but doesn't sound like the symptom.
Thanks for your response! Then I suppose the parameter type should be a string right? I changed that but seems to be happening the same.
One question, is there any problem if we are doing live api calls and testing api calls without resolving the first one? I mean, first I create a paymentINtent with live api keys and then without resolving that one, I create a paymentIntent with test api key (In a separate server).
could you share a bit more context? What's the environment you're running this in, what version of Node? can you share more of the surrounding code?
that wouldn't cause any issue I'm aware of
Of course, I'm integrating Stripe with react version 16.13.1, node version v16.14.0. The code surrounding the creation of the paymentIntent is something like this:
(top of page)
const stripeMod = require('stripe')('sk_test_...');
...
async function pymt(stripe){
const paymentIntent = await stripe.paymentIntents.create({
amount: "2c",
currency: "usd",
payment_method_types: ['card']
});
return paymentIntent;
}
...
useEffect(()=>{
...
else if(condition){
pymt(stripeMod) // call to the async function that holds the paymentIntent.create call. It receives the stripeMod
// object
}
...
Stripe version is 8.210.0
Is my frontend. I know that this should be handle by the backend and this is only for testing purposes
PaymentIntents can only be created on the backend server, using our stripe-node library, not on the frontend using our react library
yeah that''s impossible
you have to run this on a backend server, there's no other option. The stripe-node library only runs in a Node environment and uses your secret key, you can't do this on the frontend in a browser, it just won't work.
I'm working in a node environment, I have the stripe module needed to run this operations installed localy, i have harcoded the secret key in my local repo, this does not work?
Maybe I'm missing something vital about how stripe is handled
It needs a backend server(a Node server), and a frontend(a web page, maybe using React).
I think you have combined the two of them, and you added the stripe-node dependency to your frontend React project's package.json for example. That won't work
but you can certainly do all this locally, the backend can just be running at localhost, doesn't have to deployed somewhere. But there is that backend/frontend distinction. i.e you need a Node server that your React code can make HTTP calls to to get the PaymentIntent.
I'd suggest maybe starting with one of our samples instead like https://stripe.com/docs/payments/quickstart (Custom payment flow, React frontend, Node backend) and getting those running as they have the right structure already
Thanks for your help. Excuse me if I'm asking an stupid question, but I dont see why that does not work. I know that does't have sense to do it like that in a production environment, but I dont get why making the request to Stripe directly from the react app does not work. What is exactly the problem? I mean technically speaking, again sorry if this is a stupid question.
I understand the examples. Maybe the problem is the context from where it executed the api calls that holds something important that I dont know about.
Hey, taking over from @small sail
As they explained you're using stripe-node (https://github.com/stripe/stripe-node) which is a backend library, in your front-end application
You need a server component to make those API calls to create a PI using that lib
technically speaking
it's because stripe-node expects to run in Node, which has different globals available than in the browser
it's not just a case of "it's Javascript so it can all run everywhere", they are different environments. For example we rely on Node's in-built HTTP request handlers, which doesn't exist in the browser.
Oh, I see, there is the something I was missing, thank you both for your answers!!