#hayazee.
1 messages · Page 1 of 1 (latest)
hi, can you say more about what you have so far or what your code looks like?
My code at the backend to create the paymentIntent:
const paymentIntent = await stripe.paymentIntents.create({
amount: amount,
currency: currency,
payment_method_types: ['card'],
metadata: {
walletId: walletId,
paymentMethod: 'CARD',
},
});
Retrieving the paymentIntent:
// Retrieve the payment intent
const retrievedPaymentIntent = await stripe.paymentIntents.retrieve(
paymentIntent.id,
);
And passing the data:
return {
status: SUCCESS,
data: {
clientSecret: paymentIntent.client_secret,
paymentIntent: retrievedPaymentIntent // Include the retrieved payment intent in the response
}
};
} catch (error) {
logError('ERROR @ initStripePaymentIntent -> stripe.services.js', error);
return {
status: SERVER_ERROR,
error: 'An unhandled exception occurred on the server.'
};
}
};
In the frontend Im trying to fetch that PaymentIntent like this:
getClientSecret({ amount })
.then(res => {
setClientSecret(res.data.data.clientSecret);
const retrievedPaymentIntent = res.data.data.paymentIntent;
if (retrievedPaymentIntent) {
const paymentAmount = retrievedPaymentIntent.amount;
console.log("Payment amount:", paymentAmount);
}
dispatch(unsetLoading());
})
.catch(error => {
setCheckout(false)
enqueueSnackbar('Unable to fetch data.', { variant: 'error' })
dispatch(unsetLoading())
})
}, []);
My API Request ID:
req_dyQwZzbZskjCWO
well you could do
data: {
clientSecret: paymentIntent.client_secret,
amount:paymentIntent.amount, currency:paymentIntent.currency,
}
and then you have that information on the frontend
you really should not send the whole PaymentIntent object to the frontend, it's not designed for that
you should take the information that you need, and send that specifically.
Like this?
const retrievedPaymentIntent = res.data.data.paymentIntent.amount;
if (retrievedPaymentIntent) {
const paymentAmount = retrievedPaymentIntent.amount;
console.log("Payment amount:", paymentAmount);
}
no
if you do it the way I said earlier, the amount is res.data.data.amount I think, for instance.
It's not working still
then I'd add some logging and see exactly what values you have and debug from there
Should i give the info to do so ?
not sure what you mean?
You told me that you'll see what's the problem. I said should i give you the required information which could be in your usage.
what does "in your usage" mean?
useful for you*
I don't really need anything from you
it's your code and you're the developer debugging it, so it's you who would add the logs and check them and debug the code! it's just general web dev/parsing the response from your backend rather than anything specific to Stripe. In general, sending the amount directly in the JSON response your server is sending is a good approach and then you can access it on the frontend
Ahh kay. Thank you!