#hayazee.

1 messages · Page 1 of 1 (latest)

north flareBOT
raven cave
#

hi, can you say more about what you have so far or what your code looks like?

onyx inlet
# raven cave 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

raven cave
#

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.

onyx inlet
raven cave
#

no

#

if you do it the way I said earlier, the amount is res.data.data.amount I think, for instance.

onyx inlet
#

It's not working still

raven cave
#

then I'd add some logging and see exactly what values you have and debug from there

onyx inlet
#

Should i give the info to do so ?

raven cave
#

not sure what you mean?

onyx inlet
raven cave
#

what does "in your usage" mean?

onyx inlet
raven cave
#

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

onyx inlet
#

Ahh kay. Thank you!

north flareBOT