#mhiggie
1 messages · Page 1 of 1 (latest)
Hi, can you add more details? What exactly is not working and where?
so i hit my endpoint https://lastwave-ecommerce.herokuapp.com/create-payment-intent
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 `
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
apiUrl just points the endpoints to my production url IF not on localhost
`let apiUrl
const apiUrls = {
production: 'https://lastwave-ecommerce.herokuapp.com',
development: 'http://localhost:3000'
}
if (window.location.hostname === 'localhost:3000') {
console.log(window.location)
apiUrl = apiUrls.development
} else {
apiUrl = apiUrls.production
}
export default apiUrl`
do i need to whitelist stripe in CORS of express server?
You aren't even making it to Stripe yet
This is an issue with your frontend talking to your backend
Yeah so you need to debug this 400 request that you are making to your server
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
Yeah sounds like you have the wrong key in your .env