#mhiggie

1 messages · Page 1 of 1 (latest)

opaque yachtBOT
brisk fiber
#

Hi, can you add more details? What exactly is not working and where?

novel parrot
#

export const createPaymentIntent = (user) => { let data = '' return axios.post(apiUrl + /create-payment-intent, data, { headers: { Authorization: Bearer ${user.token}} }) }

#

this is from my frontend ^

#

here's how i handle this req in backend:

#

`
const stripeAPI = require('../utils/stripe')

router.post('/create-payment-intent', requireToken, async (req, res) => {
let userId = req.user.id

let cart = await Cart.findOne({user: userId})
let total = cart.total * 100

let user = await User.findById(userId)
let receipt_email = user.email
let shipping = user.shipping

try {
paymentIntent = await stripeAPI.paymentIntents.create({
amount: total,
currency: 'usd',
payment_method_types: ['card'],
receipt_email,
shipping
});

res.status(200).json({ clientSecret: paymentIntent.client_secret })

} catch(error) {
console.log(error)
res.status(400).json({ message: "an error occured, unable to create payment intent."})
}
})`

#

then in that utils file i am doing:

#

`const stripeAPI = require('stripe')(process.env.REACT_APP_STRIPE_LIVE_KEY)

module.exports = stripeAPI `

soft mantle
#

👋 stepping in

#

When you say "not working" what is happening?

novel parrot
#

Hey thank you for the help, so i had this setup locally with test keys from stripe and was working great

#

I've since deployed backend to heroku

#

frontend to netlify

soft mantle
#

What is the apiUrl above?

#

What endpoint are you actually hitting there?

novel parrot
#

apiUrl just points the endpoints to my production url IF not on localhost

#

do i need to whitelist stripe in CORS of express server?

soft mantle
#

You aren't even making it to Stripe yet

#

This is an issue with your frontend talking to your backend

novel parrot
#

dang okay

#

good to know

#

hmm

#

my stripe routes are mounted on server

soft mantle
#

Yeah so you need to debug this 400 request that you are making to your server

novel parrot
#

arg okay cool thank you

#

what is ur thoughts on the following within the index.js most top level of my frontend app

#

`import { Elements } from "@stripe/react-stripe-js"
import { loadStripe } from '@stripe/stripe-js'

const stripePromise = loadStripe(process.env.REACT_APP_STRIPE_LIVE_PUBLISHABLE_KEY);

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<Elements stripe={stripePromise}>
<App />
</Elements>
);`

#

i see this

soft mantle
#

Yeah sounds like you have the wrong key in your .env